8 Star 1 Fork 7

src-anolis-os/rasdaemon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1052-rasdaemon-coding-style-cleanup.patch 79.43 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844
From 35b75c577ed53231479296dc8fcc04b60c229005 Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <[email protected]>
Date: Wed, 17 Jul 2024 01:06:52 +0200
Subject: [PATCH 52/85] rasdaemon: coding style cleanup
Solve lots of coding style issues reported by:
./scripts/checkpatch.pl --terse --show-types --strict \
-f $(git ls-files|grep -E '\.[ch]$') \
--ignore MACRO_ARG_REUSE,STRCPY,IF_0,UNNECESSARY_PARENTHESES,CAMELCASE,STRNCPY; done
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
---
bitfield.c | 7 +-
bitfield.h | 4 +-
mce-amd-k8.c | 25 +-
mce-amd.c | 5 +-
mce-intel-broadwell-de.c | 2 +-
mce-intel-broadwell-epex.c | 2 +-
mce-intel-dunnington.c | 2 +-
mce-intel-haswell.c | 2 +-
mce-intel-i10nm.c | 58 ++--
mce-intel-ivb.c | 2 +-
mce-intel-knl.c | 2 +-
mce-intel-nehalem.c | 2 +-
mce-intel-p4-p6.c | 2 +-
mce-intel-sb.c | 2 +-
mce-intel-skylake-xeon.c | 2 +-
mce-intel-tulsa.c | 2 +-
mce-intel.c | 19 +-
non-standard-ampere.c | 3 +-
non-standard-ampere.h | 8 +-
non-standard-hisi_hip08.c | 36 +--
non-standard-hisilicon.c | 6 +-
ras-aer-handler.c | 2 +-
ras-aer-handler.h | 2 +-
ras-arm-handler.c | 3 +-
ras-cpu-isolation.c | 12 +-
ras-devlink-handler.c | 3 +-
ras-devlink-handler.h | 2 +-
ras-diskerror-handler.c | 3 +-
ras-diskerror-handler.h | 2 +-
ras-events.c | 37 +--
ras-events.h | 2 +-
ras-extlog-handler.c | 7 +-
ras-extlog-handler.h | 2 +-
ras-logger.h | 18 +-
ras-mc-handler.c | 5 +-
ras-mc-handler.h | 2 +-
ras-mce-handler.c | 28 +-
ras-mce-handler.h | 2 +-
ras-memory-failure-handler.h | 2 +-
ras-non-standard-handler.c | 7 +-
ras-page-isolation.c | 37 +--
ras-page-isolation.h | 2 +-
ras-record.c | 2 +-
ras-record.h | 70 ++++-
ras-report.c | 503 ++++++++++++++++-------------------
rbtree.c | 189 ++++++-------
rbtree.h | 187 ++++++-------
47 files changed, 685 insertions(+), 639 deletions(-)
diff --git a/bitfield.c b/bitfield.c
index 2076683..17e154a 100644
--- a/bitfield.c
+++ b/bitfield.c
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
@@ -25,7 +25,7 @@
#include "ras-mce-handler.h"
#include "bitfield.h"
-unsigned int bitfield_msg(char *buf, size_t len, const char **bitarray,
+unsigned int bitfield_msg(char *buf, size_t len, const char * const *bitarray,
unsigned int array_len,
unsigned int bit_offset, unsigned int ignore_bits,
uint64_t status)
@@ -86,8 +86,9 @@ void decode_bitfield(struct mce_event *e, uint64_t status,
continue;
mce_snprintf(e->error_msg, "<%u:%llx>",
f->start_bit, (long long)v);
- } else
+ } else {
mce_snprintf(e->error_msg, "%s", s);
+ }
}
}
diff --git a/bitfield.h b/bitfield.h
index 2b75b41..b38db42 100644
--- a/bitfield.h
+++ b/bitfield.h
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <stdint.h>
@@ -60,7 +60,7 @@ static inline int test_prefix(int nr, uint32_t value)
/* Ancillary routines */
-unsigned int bitfield_msg(char *buf, size_t len, const char **bitarray,
+unsigned int bitfield_msg(char *buf, size_t len, const char * const *bitarray,
unsigned int array_len,
unsigned int bit_offset, unsigned int ignore_bits,
uint64_t status);
diff --git a/mce-amd-k8.c b/mce-amd-k8.c
index f27b823..7906c95 100644
--- a/mce-amd-k8.c
+++ b/mce-amd-k8.c
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <stdio.h>
#include <string.h>
@@ -33,7 +33,7 @@
#define K8_MCELOG_THRESHOLD_L3_CACHE (4 * 9 + 2)
#define K8_MCELOG_THRESHOLD_FBDIMM (4 * 9 + 3)
-static const char *k8bank[] = {
+static const char * const k8bank[] = {
"data cache",
"instruction cache",
"bus unit",
@@ -42,7 +42,7 @@ static const char *k8bank[] = {
"fixed-issue reoder"
};
-static const char *k8threshold[] = {
+static const char * const k8threshold[] = {
[0 ... K8_MCELOG_THRESHOLD_DRAM_ECC - 1] = "Unknown threshold counter",
[K8_MCELOG_THRESHOLD_DRAM_ECC] = "MC4_MISC0 DRAM threshold",
[K8_MCELOG_THRESHOLD_LINK] = "MC4_MISC1 Link threshold",
@@ -53,35 +53,35 @@ static const char *k8threshold[] = {
"Unknown threshold counter",
};
-static const char *transaction[] = {
+static const char * const transaction[] = {
"instruction", "data", "generic", "reserved"
};
-static const char *cachelevel[] = {
+static const char * const cachelevel[] = {
"0", "1", "2", "generic"
};
-static const char *memtrans[] = {
+static const char * const memtrans[] = {
"generic error", "generic read", "generic write", "data read",
"data write", "instruction fetch", "prefetch", "evict", "snoop",
"?", "?", "?", "?", "?", "?", "?"
};
-static const char *partproc[] = {
+static const char * const partproc[] = {
"local node origin", "local node response",
"local node observed", "generic participation"
};
-static const char *timeout[] = {
+static const char * const timeout[] = {
"request didn't time out",
"request timed out"
};
-static const char *memoryio[] = {
+static const char * const memoryio[] = {
"memory", "res.", "i/o", "generic"
};
-static const char *nbextendederr[] = {
+static const char * const nbextendederr[] = {
"RAM ECC error",
"CRC error",
"Sync error",
@@ -103,7 +103,7 @@ static const char *nbextendederr[] = {
"L3 Cache LRU Error"
};
-static const char *highbits[32] = {
+static const char * const highbits[32] = {
[31] = "valid",
[30] = "error overflow (multiple errors)",
[29] = "error uncorrected",
@@ -264,9 +264,8 @@ int parse_amd_k8_event(struct ras_events *ras, struct mce_event *e)
if (e->bank == 4) {
unsigned short exterrcode = (e->status >> 16) & 0x0f;
- if (exterrcode == 5 && (e->status & (1ULL << 61))) {
+ if (exterrcode == 5 && (e->status & (1ULL << 61)))
return -1;
- }
}
bank_name(e);
diff --git a/mce-amd.c b/mce-amd.c
index ac0dbac..028a329 100644
--- a/mce-amd.c
+++ b/mce-amd.c
@@ -86,10 +86,11 @@ void decode_amd_errcode(struct mce_event *e)
"Uncorrected, software restartable error.");
strcpy(e->error_msg,
"Uncorrected, software containable error.");
- } else if (e->status & MCI_STATUS_DEFERRED)
+ } else if (e->status & MCI_STATUS_DEFERRED) {
strcpy(e->error_msg, "Deferred error, no action required.");
- else
+ } else {
strcpy(e->error_msg, "Corrected error, no action required.");
+ }
if (!(e->status & MCI_STATUS_VAL))
mce_snprintf(e->mcistatus_msg, "MCE_INVALID");
diff --git a/mce-intel-broadwell-de.c b/mce-intel-broadwell-de.c
index 8210782..ad2421c 100644
--- a/mce-intel-broadwell-de.c
+++ b/mce-intel-broadwell-de.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-broadwell-epex.c b/mce-intel-broadwell-epex.c
index 9c863d9..52b3815 100644
--- a/mce-intel-broadwell-epex.c
+++ b/mce-intel-broadwell-epex.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-dunnington.c b/mce-intel-dunnington.c
index 71c3fb4..1114fd7 100644
--- a/mce-intel-dunnington.c
+++ b/mce-intel-dunnington.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-haswell.c b/mce-intel-haswell.c
index 195f6ed..12ec3c3 100644
--- a/mce-intel-haswell.c
+++ b/mce-intel-haswell.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-i10nm.c b/mce-intel-i10nm.c
index c4ace56..a486866 100644
--- a/mce-intel-i10nm.c
+++ b/mce-intel-i10nm.c
@@ -18,7 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <inttypes.h>
#include <stdio.h>
@@ -299,18 +299,32 @@ static void i10nm_imc_misc(struct mce_event *e)
uint32_t eccmode = EXTRACT(e->misc, 59, 62);
uint32_t transient = EXTRACT(e->misc, 63, 63);
- mce_snprintf(e->error_msg, "bank: 0x%x bankgroup: 0x%x row: 0x%x column: 0x%x", bank, bankgroup, row, column);
+ mce_snprintf(e->error_msg,
+ "bank: 0x%x bankgroup: 0x%x row: 0x%x column: 0x%x",
+ bank, bankgroup, row, column);
if (!transient && !EXTRACT(e->status, 61, 61))
mce_snprintf(e->error_msg, "failed device: 0x%x", fdevice);
mce_snprintf(e->error_msg, "rank: 0x%x subrank: 0x%x", rank, subrank);
mce_snprintf(e->error_msg, "ecc mode: ");
switch (eccmode) {
- case 0: mce_snprintf(e->error_msg, "SDDC memory mode"); break;
- case 1: mce_snprintf(e->error_msg, "SDDC"); break;
- case 4: mce_snprintf(e->error_msg, "ADDDC memory mode"); break;
- case 5: mce_snprintf(e->error_msg, "ADDDC"); break;
- case 8: mce_snprintf(e->error_msg, "DDRT read"); break;
- default: mce_snprintf(e->error_msg, "unknown"); break;
+ case 0:
+ mce_snprintf(e->error_msg, "SDDC memory mode");
+ break;
+ case 1:
+ mce_snprintf(e->error_msg, "SDDC");
+ break;
+ case 4:
+ mce_snprintf(e->error_msg, "ADDDC memory mode");
+ break;
+ case 5:
+ mce_snprintf(e->error_msg, "ADDDC");
+ break;
+ case 8:
+ mce_snprintf(e->error_msg, "DDRT read");
+ break;
+ default:
+ mce_snprintf(e->error_msg, "unknown");
+ break;
}
if (transient)
mce_snprintf(e->error_msg, "transient");
@@ -359,7 +373,7 @@ static enum banktype sapphire[32] = {
[13 ... 20] = BT_IMC,
};
-void i10nm_memerr_misc(struct mce_event *e, int *channel);
+static void i10nm_memerr_misc(struct mce_event *e, int *channel);
void i10nm_decode_model(enum cputype cputype, struct ras_events *ras,
struct mce_event *e)
@@ -426,12 +440,24 @@ void i10nm_decode_model(enum cputype cputype, struct ras_events *ras,
mce_snprintf(e->error_msg, "MemCtrl: ");
f = EXTRACT(status, 16, 23);
switch (EXTRACT(status, 24, 31)) {
- case 0: decode_bitfield(e, f, imc0); break;
- case 1: decode_bitfield(e, f, imc1); break;
- case 2: decode_bitfield(e, f, imc2); break;
- case 4: decode_bitfield(e, f, imc4); break;
- case 8: decode_bitfield(e, f, imc8); break;
- case 0x10: decode_bitfield(e, f, imc10); break;
+ case 0:
+ decode_bitfield(e, f, imc0);
+ break;
+ case 1:
+ decode_bitfield(e, f, imc1);
+ break;
+ case 2:
+ decode_bitfield(e, f, imc2);
+ break;
+ case 4:
+ decode_bitfield(e, f, imc4);
+ break;
+ case 8:
+ decode_bitfield(e, f, imc8);
+ break;
+ case 0x10:
+ decode_bitfield(e, f, imc10);
+ break;
}
i10nm_imc_misc(e);
break;
@@ -464,7 +490,7 @@ void i10nm_decode_model(enum cputype cputype, struct ras_events *ras,
* we can derive the channel from the bank number.
* There can be four memory controllers with two channels each.
*/
-void i10nm_memerr_misc(struct mce_event *e, int *channel)
+static void i10nm_memerr_misc(struct mce_event *e, int *channel)
{
uint64_t status = e->status;
unsigned int chan, imc;
diff --git a/mce-intel-ivb.c b/mce-intel-ivb.c
index e5e6a7a..3204b58 100644
--- a/mce-intel-ivb.c
+++ b/mce-intel-ivb.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-knl.c b/mce-intel-knl.c
index 0e2ea80..ff00ca9 100644
--- a/mce-intel-knl.c
+++ b/mce-intel-knl.c
@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-nehalem.c b/mce-intel-nehalem.c
index 18992d1..1ab0ef3 100644
--- a/mce-intel-nehalem.c
+++ b/mce-intel-nehalem.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-p4-p6.c b/mce-intel-p4-p6.c
index 2751d34..ecd266f 100644
--- a/mce-intel-p4-p6.c
+++ b/mce-intel-p4-p6.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-sb.c b/mce-intel-sb.c
index 385b125..6c69f28 100644
--- a/mce-intel-sb.c
+++ b/mce-intel-sb.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-skylake-xeon.c b/mce-intel-skylake-xeon.c
index 37e5e11..fdf02b9 100644
--- a/mce-intel-skylake-xeon.c
+++ b/mce-intel-skylake-xeon.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel-tulsa.c b/mce-intel-tulsa.c
index f38d638..7607e02 100644
--- a/mce-intel-tulsa.c
+++ b/mce-intel-tulsa.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <string.h>
#include <stdio.h>
diff --git a/mce-intel.c b/mce-intel.c
index 7f48cc4..58bcba3 100644
--- a/mce-intel.c
+++ b/mce-intel.c
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <errno.h>
#include <fcntl.h>
@@ -164,10 +164,15 @@ static void decode_memory_controller(struct mce_event *e, uint32_t status)
static void decode_termal_bank(struct mce_event *e)
{
if (e->status & 1) {
- mce_snprintf(e->mcgstatus_msg, "Processor %d heated above trip temperature. Throttling enabled.", e->cpu);
- mce_snprintf(e->user_action, "Please check your system cooling. Performance will be impacted");
+ mce_snprintf(e->mcgstatus_msg,
+ "Processor %d heated above trip temperature. Throttling enabled.",
+ e->cpu);
+ mce_snprintf(e->user_action,
+ "Please check your system cooling. Performance will be impacted");
} else {
- mce_snprintf(e->error_msg, "Processor %d below trip temperature. Throttling disabled", e->cpu);
+ mce_snprintf(e->error_msg,
+ "Processor %d below trip temperature. Throttling disabled",
+ e->cpu);
}
}
@@ -209,9 +214,8 @@ static char *get_RRRR_str(uint8_t rrrr)
unsigned int i;
for (i = 0; i < ARRAY_SIZE(RRRR); i++) {
- if (RRRR[i].value == rrrr) {
+ if (RRRR[i].value == rrrr)
return RRRR[i].str;
- }
}
return "UNKNOWN";
@@ -281,8 +285,9 @@ static void decode_mca(struct mce_event *e, uint64_t track, int *ismemerr)
} else if (test_prefix(7, mca)) {
decode_memory_controller(e, mca);
*ismemerr = 1;
- } else
+ } else {
mce_snprintf(e->mcastatus_msg, "Unknown Error %x", mca);
+ }
}
static void decode_tracking(struct mce_event *e, uint64_t track)
diff --git a/non-standard-ampere.c b/non-standard-ampere.c
index 79e09a0..0005b48 100644
--- a/non-standard-ampere.c
+++ b/non-standard-ampere.c
@@ -1063,8 +1063,9 @@ static int decode_amp_oem_type_error(struct ras_events *ras,
} else if (payload_type == PAYLOAD_TYPE_3) {
db_tab = amp_payload3_event_tab;
id = AMP_PAYLOAD3_FIELD_TIMESTAMP;
- } else
+ } else {
return -1;
+ }
if (!ev_decoder->stmt_dec_record) {
if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
diff --git a/non-standard-ampere.h b/non-standard-ampere.h
index 8937e4d..e7596ea 100644
--- a/non-standard-ampere.h
+++ b/non-standard-ampere.h
@@ -14,10 +14,10 @@
#include "ras-events.h"
#include "libtrace/event-parse.h"
-#define SOCKET_NUM(x) ((x >> 14) & 0x3)
-#define PAYLOAD_TYPE(x) ((x >> 6) & 0x3)
-#define TYPE(x) (x & 0x3f)
-#define INSTANCE(x) (x & 0x3fff)
+#define SOCKET_NUM(x) (((x) >> 14) & 0x3)
+#define PAYLOAD_TYPE(x) (((x) >> 6) & 0x3)
+#define TYPE(x) ((x) & 0x3f)
+#define INSTANCE(x) ((x) & 0x3fff)
#define AMP_PAYLOAD0_BUF_LEN 1024
#define PAYLOAD_TYPE_0 0x00
#define PAYLOAD_TYPE_1 0x01
diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c
index e482a7a..d90c6bf 100644
--- a/non-standard-hisi_hip08.c
+++ b/non-standard-hisi_hip08.c
@@ -185,11 +185,11 @@ enum {
struct hisi_module_info {
int id;
const char *name;
- const char **sub;
+ const char * const *sub;
int sub_num;
};
-static const char *pll_submodule_name[] = {
+static const char * const pll_submodule_name[] = {
"TB_PLL0",
"TB_PLL1",
"TB_PLL2",
@@ -205,7 +205,7 @@ static const char *pll_submodule_name[] = {
"NIMBUS_PLL4",
};
-static const char *sllc_submodule_name[] = {
+static const char * const sllc_submodule_name[] = {
"TB_SLLC0",
"TB_SLLC1",
"TB_SLLC2",
@@ -216,7 +216,7 @@ static const char *sllc_submodule_name[] = {
"NIMBUS_SLLC1",
};
-static const char *sioe_submodule_name[] = {
+static const char * const sioe_submodule_name[] = {
"TB_SIOE0",
"TB_SIOE1",
"TB_SIOE2",
@@ -229,12 +229,12 @@ static const char *sioe_submodule_name[] = {
"NIMBUS_SIOE1",
};
-static const char *poe_submodule_name[] = {
+static const char * const poe_submodule_name[] = {
"TB_POE",
"TA_POE",
};
-static const char *disp_submodule_name[] = {
+static const char * const disp_submodule_name[] = {
"TB_PERI_DISP",
"TB_POE_DISP",
"TB_GIC_DISP",
@@ -247,7 +247,7 @@ static const char *disp_submodule_name[] = {
"NETWORK_DISP",
};
-static const char *sas_submodule_name[] = {
+static const char * const sas_submodule_name[] = {
"SAS0",
"SAS1",
};
@@ -321,27 +321,27 @@ static const struct hisi_module_info hisi_oem_type1_module[] = {
}
};
-static const char *smmu_submodule_name[] = {
+static const char * const smmu_submodule_name[] = {
"HAC_SMMU",
"PCIE_SMMU",
"MGMT_SMMU",
"NIC_SMMU",
};
-static const char *hllc_submodule_name[] = {
+static const char * const hllc_submodule_name[] = {
"HLLC0",
"HLLC1",
"HLLC2",
};
-static const char *hha_submodule_name[] = {
+static const char * const hha_submodule_name[] = {
"TB_HHA0",
"TB_HHA1",
"TA_HHA0",
"TA_HHA1"
};
-static const char *ddrc_submodule_name[] = {
+static const char * const ddrc_submodule_name[] = {
"TB_DDRC0",
"TB_DDRC1",
"TB_DDRC2",
@@ -352,7 +352,7 @@ static const char *ddrc_submodule_name[] = {
"TA_DDRC3",
};
-static const char *l3tag_submodule_name[] = {
+static const char * const l3tag_submodule_name[] = {
"TB_PARTITION0",
"TB_PARTITION1",
"TB_PARTITION2",
@@ -371,7 +371,7 @@ static const char *l3tag_submodule_name[] = {
"TA_PARTITION7",
};
-static const char *l3data_submodule_name[] = {
+static const char * const l3data_submodule_name[] = {
"TB_BANK0",
"TB_BANK1",
"TB_BANK2",
@@ -427,8 +427,8 @@ static const struct hisi_module_info hisi_oem_type2_module[] = {
}
};
-static const char *oem_module_name(const struct hisi_module_info *info,
- uint8_t module_id)
+static const char * const oem_module_name(const struct hisi_module_info *info,
+ uint8_t module_id)
{
const struct hisi_module_info *module = &info[0];
@@ -442,13 +442,13 @@ static const char *oem_module_name(const struct hisi_module_info *info,
return "unknown";
}
-static const char *oem_submodule_name(const struct hisi_module_info *info,
- uint8_t module_id, uint8_t sub_module_id)
+static const char * const oem_submodule_name(const struct hisi_module_info *info,
+ uint8_t module_id, uint8_t sub_module_id)
{
const struct hisi_module_info *module = &info[0];
for (; module->name; module++) {
- const char **submodule = module->sub;
+ const char * const *submodule = module->sub;
if (module->id != module_id)
continue;
diff --git a/non-standard-hisilicon.c b/non-standard-hisilicon.c
index e9ea5df..00388ec 100644
--- a/non-standard-hisilicon.c
+++ b/non-standard-hisilicon.c
@@ -171,13 +171,13 @@ static const struct db_table_descriptor hisi_common_section_tab = {
};
#endif
-static const char *soc_desc[] = {
+static const char * const soc_desc[] = {
"Kunpeng916",
"Kunpeng920",
"Kunpeng930",
};
-static const char *module_name[] = {
+static const char * const module_name[] = {
"MN",
"PLL",
"SLLC",
@@ -221,7 +221,7 @@ static const char *module_name[] = {
"HBMC",
};
-static const char *get_soc_desc(uint8_t soc_id)
+static const char * const get_soc_desc(uint8_t soc_id)
{
if (soc_id >= sizeof(soc_desc) / sizeof(char *))
return "unknown";
diff --git a/ras-aer-handler.c b/ras-aer-handler.c
index a867ae4..b6a6f1e 100644
--- a/ras-aer-handler.c
+++ b/ras-aer-handler.c
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/ras-aer-handler.h b/ras-aer-handler.h
index 876a60b..7a7f3d1 100644
--- a/ras-aer-handler.h
+++ b/ras-aer-handler.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_AER_HANDLER_H
#define __RAS_AER_HANDLER_H
diff --git a/ras-arm-handler.c b/ras-arm-handler.c
index a295820..55162a6 100644
--- a/ras-arm-handler.c
+++ b/ras-arm-handler.c
@@ -42,8 +42,9 @@ void display_raw_data(struct trace_seq *s,
if (++line_count == 4) {
trace_seq_printf(s, "\n %08x: ", i);
line_count = 0;
- } else
+ } else {
trace_seq_printf(s, " ");
+ }
}
}
diff --git a/ras-cpu-isolation.c b/ras-cpu-isolation.c
index 8af31e9..2b37ebe 100644
--- a/ras-cpu-isolation.c
+++ b/ras-cpu-isolation.c
@@ -84,7 +84,7 @@ static int open_sys_file(unsigned int cpu, int __oflag, const char *format)
char real_path[PATH_MAX] = "";
snprintf(path, sizeof(path), format, cpu);
- if (strlen(path) > PATH_MAX || realpath(path, real_path) == NULL) {
+ if (strlen(path) > PATH_MAX || !realpath(path, real_path)) {
log(TERM, LOG_ERR, "[%s]:open file: %s failed\n", __func__, path);
return -1;
}
@@ -178,8 +178,9 @@ static int parse_ul_config(struct isolation_param *config, char *env, unsigned l
return -1;
}
*value = DEC_CHECK * (*value) + (env[i] - '0');
- } else
+ } else {
return -1;
+ }
}
if (!has_unit)
@@ -391,15 +392,16 @@ void ras_record_cpu_error(struct error_info *err_info, int cpu)
}
ret = error_handler(cpu, err_info);
- if (ret == HANDLE_NOTHING)
+ if (ret == HANDLE_NOTHING) {
log(TERM, LOG_WARNING, "Doing nothing in the cpu%d\n", cpu);
- else if (ret == HANDLE_SUCCEED) {
+ } else if (ret == HANDLE_SUCCEED) {
log(TERM, LOG_INFO, "Offline cpu%d succeed, the state is %s\n",
cpu, cpu_state[cpu_infos[cpu].state]);
clear_queue(cpu_infos[cpu].ce_queue);
cpu_infos[cpu].ce_nums = 0;
cpu_infos[cpu].uce_nums = 0;
- } else
+ } else {
log(TERM, LOG_WARNING, "Offline cpu%d fail, the state is %s\n",
cpu, cpu_state[cpu_infos[cpu].state]);
+ }
}
diff --git a/ras-devlink-handler.c b/ras-devlink-handler.c
index b19ccaa..4b22a8b 100644
--- a/ras-devlink-handler.c
+++ b/ras-devlink-handler.c
@@ -14,7 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
+
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
diff --git a/ras-devlink-handler.h b/ras-devlink-handler.h
index ca9a1b7..74f8441 100644
--- a/ras-devlink-handler.h
+++ b/ras-devlink-handler.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_DEVLINK_HANDLER_H
#define __RAS_DEVLINK_HANDLER_H
diff --git a/ras-diskerror-handler.c b/ras-diskerror-handler.c
index 618afdb..9225a81 100644
--- a/ras-diskerror-handler.c
+++ b/ras-diskerror-handler.c
@@ -14,7 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
+
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
diff --git a/ras-diskerror-handler.h b/ras-diskerror-handler.h
index 002f1c4..facdc79 100644
--- a/ras-diskerror-handler.h
+++ b/ras-diskerror-handler.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_DISKERROR_HANDLER_H
#define __RAS_DISKERROR_HANDLER_H
diff --git a/ras-events.c b/ras-events.c
index c83b8de..57d2026 100644
--- a/ras-events.c
+++ b/ras-events.c
@@ -14,34 +14,37 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
+
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <sys/poll.h>
-#include <signal.h>
#include <sys/signalfd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "libtrace/kbuffer.h"
#include "libtrace/event-parse.h"
-#include "ras-mc-handler.h"
+#include <unistd.h>
+
#include "ras-aer-handler.h"
-#include "ras-non-standard-handler.h"
#include "ras-arm-handler.h"
-#include "ras-mce-handler.h"
-#include "ras-extlog-handler.h"
+#include "ras-cpu-isolation.h"
#include "ras-devlink-handler.h"
#include "ras-diskerror-handler.h"
-#include "ras-memory-failure-handler.h"
-#include "ras-record.h"
+#include "ras-extlog-handler.h"
#include "ras-logger.h"
+#include "ras-mce-handler.h"
+#include "ras-mc-handler.h"
+#include "ras-memory-failure-handler.h"
+#include "ras-non-standard-handler.h"
#include "ras-page-isolation.h"
-#include "ras-cpu-isolation.h"
+#include "ras-record.h"
#include "trigger.h"
/*
@@ -103,7 +106,7 @@ static int get_debugfs_dir(char *tracing_dir, size_t len)
fclose(fp);
log(ALL, LOG_INFO, "Can't find debugfs\n");
- return ENOENT;
+ return -ENOENT;
}
static int open_trace(struct ras_events *ras, char *name, int flags)
@@ -162,7 +165,8 @@ static int is_disabled_event(char *group, char *event)
snprintf(ras_event_name, sizeof(ras_event_name), "%s:%s",
group, event);
- if (choices_disable && strlen(choices_disable) != 0 && strstr(choices_disable, ras_event_name)) {
+ if (choices_disable && strlen(choices_disable) != 0 &&
+ strstr(choices_disable, ras_event_name)) {
return 1;
}
return 0;
@@ -498,9 +502,8 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
do {
ready = poll(fds, (n_cpus + 1), -1);
- if (ready < 0) {
+ if (ready < 0)
log(TERM, LOG_WARNING, "poll\n");
- }
/* check for the signal */
if (fds[n_cpus].revents & POLLIN) {
@@ -1040,7 +1043,7 @@ int handle_ras_events(int record_events)
goto err;
}
- data = calloc(sizeof(*data), cpus);
+ data = calloc(cpus, sizeof(*data));
if (!data)
goto err;
diff --git a/ras-events.h b/ras-events.h
index e4b308a..5d32a00 100644
--- a/ras-events.h
+++ b/ras-events.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_EVENTS_H
#define __RAS_EVENTS_H
diff --git a/ras-extlog-handler.c b/ras-extlog-handler.c
index b40160a..9e5c3e7 100644
--- a/ras-extlog-handler.c
+++ b/ras-extlog-handler.c
@@ -14,18 +14,19 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
+
#include <ctype.h>
#include <errno.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stdint.h>
#include "libtrace/kbuffer.h"
#include "ras-extlog-handler.h"
-#include "ras-record.h"
#include "ras-logger.h"
+#include "ras-record.h"
#include "ras-report.h"
static char *err_type(int etype)
diff --git a/ras-extlog-handler.h b/ras-extlog-handler.h
index e03f5da..daba407 100644
--- a/ras-extlog-handler.h
+++ b/ras-extlog-handler.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_EXTLOG_HANDLER_H
#define __RAS_EXTLOG_HANDLER_H
diff --git a/ras-logger.h b/ras-logger.h
index 8cab83e..dbf1cb0 100644
--- a/ras-logger.h
+++ b/ras-logger.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_LOGGER_H
@@ -35,14 +35,14 @@
#define ALL (SYSLOG | TERM)
/* TODO: global logging limit mask */
-#define log(where, level, fmt, args...) do {\
- if (where & SYSLOG)\
- syslog(level, fmt, ##args);\
- if (where & TERM) {\
- fprintf(stderr, "%s: ", TOOL_NAME);\
- fprintf(stderr, fmt, ##args);\
- fflush(stderr);\
- }\
+#define log(where, level, fmt, args...) do { \
+ if ((where) & SYSLOG) \
+ syslog(level, fmt, ##args); \
+ if ((where) & TERM) { \
+ fprintf(stderr, "%s: ", TOOL_NAME); \
+ fprintf(stderr, fmt, ##args); \
+ fflush(stderr); \
+ } \
} while (0)
#define __RAS_LOGGER_H
diff --git a/ras-mc-handler.c b/ras-mc-handler.c
index 7a4fa3c..c31468b 100644
--- a/ras-mc-handler.c
+++ b/ras-mc-handler.c
@@ -14,7 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
+
#define _GNU_SOURCE
#include <assert.h>
#include <stdio.h>
@@ -165,8 +166,8 @@ int ras_mc_event_handler(struct trace_seq *s,
case HW_EVENT_ERR_FATAL:
ev.error_type = "Fatal";
break;
- default:
case HW_EVENT_ERR_INFO:
+ default:
ev.error_type = "Info";
}
diff --git a/ras-mc-handler.h b/ras-mc-handler.h
index dc5c545..815056c 100644
--- a/ras-mc-handler.h
+++ b/ras-mc-handler.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_MC_HANDLER_H
#define __RAS_MC_HANDLER_H
diff --git a/ras-mce-handler.c b/ras-mce-handler.c
index f55c732..524f40a 100644
--- a/ras-mce-handler.c
+++ b/ras-mce-handler.c
@@ -14,7 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
+
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
@@ -164,20 +165,19 @@ static int detect_cpu(struct mce_priv *mce)
f = fopen("/proc/cpuinfo", "r");
if (!f) {
log(ALL, LOG_INFO, "Can't open /proc/cpuinfo\n");
- return errno;
+ return -errno;
}
while (seen != CPU_ALL && getdelim(&line, &linelen, '\n', f) > 0) {
- if (sscanf(line, "vendor_id : %63[^\n]",
- (char *)&mce->vendor) == 1)
+ if (sscanf(line, "vendor_id : %63[^\n]", (char *)&mce->vendor) == 1) {
seen |= CPU_VENDOR;
- else if (sscanf(line, "cpu family : %d", &mce->family) == 1)
+ } else if (sscanf(line, "cpu family : %d", &mce->family) == 1) {
seen |= CPU_FAMILY;
- else if (sscanf(line, "model : %d", &mce->model) == 1)
+ } else if (sscanf(line, "model : %d", &mce->model) == 1) {
seen |= CPU_MODEL;
- else if (sscanf(line, "cpu MHz : %lf", &mce->mhz) == 1)
+ } else if (sscanf(line, "cpu MHz : %lf", &mce->mhz) == 1) {
seen |= CPU_MHZ;
- else if (!strncmp(line, "flags", 5) && isspace(line[6])) {
+ } else if (!strncmp(line, "flags", 5) && isspace(line[6])) {
if (mce->processor_flags)
free(mce->processor_flags);
mce->processor_flags = line;
@@ -194,7 +194,7 @@ static int detect_cpu(struct mce_priv *mce)
(seen & CPU_MODEL) ? "" : " [model]",
(seen & CPU_MHZ) ? "" : " [cpu MHz]",
(seen & CPU_FLAGS) ? "" : " [flags]");
- ret = EINVAL;
+ ret = -EINVAL;
goto ret;
}
@@ -212,18 +212,18 @@ static int detect_cpu(struct mce_priv *mce)
log(ALL, LOG_INFO,
"Can't parse MCE for this AMD CPU yet %d\n",
mce->family);
- ret = EINVAL;
+ ret = -EINVAL;
}
goto ret;
} else if (!strcmp(mce->vendor, "HygonGenuine")) {
- if (mce->family == 24) {
+ if (mce->family == 24)
mce->cputype = CPU_DHYANA;
- }
+
goto ret;
} else if (!strcmp(mce->vendor, "GenuineIntel")) {
mce->cputype = select_intel_cputype(mce);
} else {
- ret = EINVAL;
+ ret = -EINVAL;
}
ret:
@@ -252,7 +252,7 @@ int register_mce_handler(struct ras_events *ras, unsigned int ncpus)
free(mce->processor_flags);
free(ras->mce_priv);
ras->mce_priv = NULL;
- return (rc);
+ return rc;
}
switch (mce->cputype) {
case CPU_SANDY_BRIDGE_EP:
diff --git a/ras-mce-handler.h b/ras-mce-handler.h
index 7c4d0be..e1064f6 100644
--- a/ras-mce-handler.h
+++ b/ras-mce-handler.h
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_MCE_HANDLER_H
#define __RAS_MCE_HANDLER_H
diff --git a/ras-memory-failure-handler.h b/ras-memory-failure-handler.h
index 30d8e9d..4241f05 100644
--- a/ras-memory-failure-handler.h
+++ b/ras-memory-failure-handler.h
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*/
+ */
#ifndef __RAS_MEMORY_FAILURE_HANDLER_H
#define __RAS_MEMORY_FAILURE_HANDLER_H
diff --git a/ras-non-standard-handler.c b/ras-non-standard-handler.c
index 968bd56..c62a91b 100644
--- a/ras-non-standard-handler.c
+++ b/ras-non-standard-handler.c
@@ -26,7 +26,9 @@ static struct ras_ns_ev_decoder *ras_ns_ev_dec_list;
void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index)
{
- trace_seq_printf(s, "%02x%02x%02x%02x", buf[index + 3], buf[index + 2], buf[index + 1], buf[index]);
+ trace_seq_printf(s, "%02x%02x%02x%02x",
+ buf[index + 3], buf[index + 2],
+ buf[index + 1], buf[index]);
}
static char *uuid_le(const char *uu)
@@ -254,8 +256,9 @@ int ras_non_standard_event_handler(struct trace_seq *s,
if (++line_count == 4) {
trace_seq_printf(s, "\n %08x: ", i);
line_count = 0;
- } else
+ } else {
trace_seq_printf(s, " ");
+ }
}
}
diff --git a/ras-page-isolation.c b/ras-page-isolation.c
index 89f8c15..4ef3cae 100644
--- a/ras-page-isolation.c
+++ b/ras-page-isolation.c
@@ -10,16 +10,17 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*/
+ */
#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
+#include <stdlib.h>
#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
+#include <unistd.h>
+
#include "ras-logger.h"
#include "ras-page-isolation.h"
@@ -53,7 +54,7 @@ static struct isolation cycle = {
.unit = "h",
};
-static const char *kernel_offline[] = {
+static const char * const kernel_offline[] = {
[OFFLINE_SOFT] = "/sys/devices/system/memory/soft_offline_page",
[OFFLINE_HARD] = "/sys/devices/system/memory/hard_offline_page",
[OFFLINE_SOFT_THEN_HARD] = "/sys/devices/system/memory/soft_offline_page",
@@ -68,7 +69,7 @@ static const struct config offline_choice[] = {
{}
};
-static const char *page_state[] = {
+static const char * const page_state[] = {
[PAGE_ONLINE] = "online",
[PAGE_OFFLINE] = "offlined",
[PAGE_OFFLINE_FAILED] = "offline-failed",
@@ -150,8 +151,8 @@ parse:
if (!no_unit)
config->unit = unit;
} else {
- log(TERM, LOG_INFO, "Improper %s, set to default %s.\n",
- config->name, config->env);
+ log(TERM, LOG_INFO, "Improper %s, set to default %s.\n",
+ config->name, config->env);
}
/* if env value string is greater than ulong_max, truncate the last digit */
@@ -219,15 +220,18 @@ static int do_page_offline(unsigned long long addr, enum otype type)
fd = open(kernel_offline[type], O_WRONLY);
if (fd == -1) {
- log(TERM, LOG_ERR, "[%s]:open file: %s failed\n", __func__, kernel_offline[type]);
+ log(TERM, LOG_ERR, "[%s]:open file: %s failed\n", __func__,
+ kernel_offline[type]);
return -1;
}
sprintf(buf, "%#llx", addr);
rc = write(fd, buf, strlen(buf));
- if (rc < 0) {
- log(TERM, LOG_ERR, "page offline addr(%s) by %s failed, errno:%d\n", buf, kernel_offline[type], errno);
- }
+ if (rc < 0)
+ log(TERM, LOG_ERR,
+ "page offline addr(%s) by %s failed, errno:%d\n",
+ buf, kernel_offline[type], errno);
+
close(fd);
return rc;
}
@@ -307,13 +311,12 @@ static struct page_record *page_lookup_insert(unsigned long long addr)
while (*entry) {
parent = *entry;
pr = rb_entry(parent, struct page_record, entry);
- if (addr == pr->addr) {
+ if (addr == pr->addr)
return pr;
- } else if (addr < pr->addr) {
+ else if (addr < pr->addr)
entry = &(*entry)->rb_left;
- } else {
+ else
entry = &(*entry)->rb_right;
- }
}
find = calloc(1, sizeof(struct page_record));
diff --git a/ras-page-isolation.h b/ras-page-isolation.h
index 0482e1e..7ccfca1 100644
--- a/ras-page-isolation.h
+++ b/ras-page-isolation.h
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*/
+ */
#ifndef __RAS_PAGE_ISOLATION_H
#define __RAS_PAGE_ISOLATION_H
diff --git a/ras-record.c b/ras-record.c
index 0409099..b0c9754 100644
--- a/ras-record.c
+++ b/ras-record.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
/*
* BuildRequires: sqlite-devel
diff --git a/ras-record.h b/ras-record.h
index 746a851..a012ac6 100644
--- a/ras-record.h
+++ b/ras-record.h
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ */
#ifndef __RAS_RECORD_H
#define __RAS_RECORD_H
@@ -186,12 +186,16 @@ int ras_mc_finalize_vendor_table(sqlite3_stmt *stmt);
int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev);
int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev);
int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev);
-int ras_store_extlog_mem_record(struct ras_events *ras, struct ras_extlog_event *ev);
-int ras_store_non_standard_record(struct ras_events *ras, struct ras_non_standard_event *ev);
+int ras_store_extlog_mem_record(struct ras_events *ras,
+ struct ras_extlog_event *ev);
+int ras_store_non_standard_record(struct ras_events *ras,
+ struct ras_non_standard_event *ev);
int ras_store_arm_record(struct ras_events *ras, struct ras_arm_event *ev);
int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev);
-int ras_store_diskerror_event(struct ras_events *ras, struct diskerror_event *ev);
+int ras_store_diskerror_event(struct ras_events *ras,
+ struct diskerror_event *ev);
int ras_store_mf_event(struct ras_events *ras, struct ras_mf_event *ev);
+<<<<<<< HEAD
#else
static inline int ras_mc_event_opendb(unsigned int cpu, struct ras_events *ras) { return 0; };
@@ -205,6 +209,64 @@ static inline int ras_store_arm_record(struct ras_events *ras, struct ras_arm_ev
static inline int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev) { return 0; };
static inline int ras_store_diskerror_event(struct ras_events *ras, struct diskerror_event *ev) { return 0; };
static inline int ras_store_mf_event(struct ras_events *ras, struct ras_mf_event *ev) { return 0; };
+=======
+int ras_store_cxl_poison_event(struct ras_events *ras,
+ struct ras_cxl_poison_event *ev);
+int ras_store_cxl_aer_ue_event(struct ras_events *ras,
+ struct ras_cxl_aer_ue_event *ev);
+int ras_store_cxl_aer_ce_event(struct ras_events *ras,
+ struct ras_cxl_aer_ce_event *ev);
+int ras_store_cxl_overflow_event(struct ras_events *ras,
+ struct ras_cxl_overflow_event *ev);
+int ras_store_cxl_generic_event(struct ras_events *ras,
+ struct ras_cxl_generic_event *ev);
+int ras_store_cxl_general_media_event(struct ras_events *ras,
+ struct ras_cxl_general_media_event *ev);
+int ras_store_cxl_dram_event(struct ras_events *ras,
+ struct ras_cxl_dram_event *ev);
+int ras_store_cxl_memory_module_event(struct ras_events *ras,
+ struct ras_cxl_memory_module_event *ev);
+
+#else
+static inline int ras_mc_event_opendb(unsigned int cpu,
+ struct ras_events *ras) { return 0; };
+static inline int ras_mc_event_closedb(unsigned int cpu,
+ struct ras_events *ras) { return 0; };
+static inline int ras_store_mc_event(struct ras_events *ras,
+ struct ras_mc_event *ev) { return 0; };
+static inline int ras_store_aer_event(struct ras_events *ras,
+ struct ras_aer_event *ev) { return 0; };
+static inline int ras_store_mce_record(struct ras_events *ras,
+ struct mce_event *ev) { return 0; };
+static inline int ras_store_extlog_mem_record(struct ras_events *ras,
+ struct ras_extlog_event *ev) { return 0; };
+static inline int ras_store_non_standard_record(struct ras_events *ras,
+ struct ras_non_standard_event *ev) { return 0; };
+static inline int ras_store_arm_record(struct ras_events *ras,
+ struct ras_arm_event *ev) { return 0; };
+static inline int ras_store_devlink_event(struct ras_events *ras,
+ struct devlink_event *ev) { return 0; };
+static inline int ras_store_diskerror_event(struct ras_events *ras,
+ struct diskerror_event *ev) { return 0; };
+static inline int ras_store_mf_event(struct ras_events *ras,
+ struct ras_mf_event *ev) { return 0; };
+static inline int ras_store_cxl_poison_event(struct ras_events *ras,
+ struct ras_cxl_poison_event *ev) { return 0; };
+static inline int ras_store_cxl_aer_ue_event(struct ras_events *ras,
+ struct ras_cxl_aer_ue_event *ev) { return 0; };
+static inline int ras_store_cxl_aer_ce_event(struct ras_events *ras,
+ struct ras_cxl_aer_ce_event *ev) { return 0; };
+static inline int ras_store_cxl_overflow_event(struct ras_events *ras,
+ struct ras_cxl_overflow_event *ev) { return 0; };
+static inline int ras_store_cxl_generic_event(struct ras_events *ras,
+ struct ras_cxl_generic_event *ev) { return 0; };
+static inline int ras_store_cxl_general_media_event(struct ras_events *ras,
+ struct ras_cxl_general_media_event *ev) { return 0; };
+static inline int ras_store_cxl_dram_event(struct ras_events *ras,
+ struct ras_cxl_dram_event *ev) { return 0; };
+static inline int ras_store_cxl_memory_module_event(struct ras_events *ras,
+ struct ras_cxl_memory_module_event *ev) { return 0; };
+>>>>>>> 7a69b22 (rasdaemon: coding style cleanup)
#endif
diff --git a/ras-report.c b/ras-report.c
index 6e3b351..0ddf86f 100644
--- a/ras-report.c
+++ b/ras-report.c
@@ -28,9 +28,8 @@ static int setup_report_socket(void)
struct sockaddr_un addr;
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sockfd < 0) {
+ if (sockfd < 0)
return -1;
- }
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_UNIX;
@@ -52,44 +51,38 @@ static int commit_report_basic(int sockfd)
struct utsname un;
int rc = -1;
- if (sockfd < 0) {
+ if (sockfd < 0)
return rc;
- }
memset(buf, 0, INPUT_BUFFER_SIZE);
memset(&un, 0, sizeof(struct utsname));
rc = uname(&un);
- if (rc < 0) {
+ if (rc < 0)
return rc;
- }
/*
* ABRT server protocol
*/
sprintf(buf, "PUT / HTTP/1.1\r\n\r\n");
rc = write(sockfd, buf, strlen(buf));
- if (rc < strlen(buf)) {
+ if (rc < strlen(buf))
return -1;
- }
sprintf(buf, "PID=%d", (int)getpid());
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
return -1;
- }
sprintf(buf, "EXECUTABLE=/boot/vmlinuz-%s", un.release);
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
return -1;
- }
sprintf(buf, "TYPE=%s", "ras");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
return -1;
- }
return 0;
}
@@ -101,33 +94,33 @@ static int set_mc_event_backtrace(char *buf, struct ras_mc_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "error_count=%d\n" \
- "error_type=%s\n" \
- "msg=%s\n" \
- "label=%s\n" \
- "mc_index=%c\n" \
- "top_layer=%c\n" \
- "middle_layer=%c\n" \
- "lower_layer=%c\n" \
- "address=%llu\n" \
- "grain=%llu\n" \
- "syndrome=%llu\n" \
- "driver_detail=%s\n", \
- ev->timestamp, \
- ev->error_count, \
- ev->error_type, \
- ev->msg, \
- ev->label, \
- ev->mc_index, \
- ev->top_layer, \
- ev->middle_layer, \
- ev->lower_layer, \
- ev->address, \
- ev->grain, \
- ev->syndrome, \
- ev->driver_detail);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "error_count=%d\n"
+ "error_type=%s\n"
+ "msg=%s\n"
+ "label=%s\n"
+ "mc_index=%c\n"
+ "top_layer=%c\n"
+ "middle_layer=%c\n"
+ "lower_layer=%c\n"
+ "address=%llu\n"
+ "grain=%llu\n"
+ "syndrome=%llu\n"
+ "driver_detail=%s\n",
+ ev->timestamp,
+ ev->error_count,
+ ev->error_type,
+ ev->msg,
+ ev->label,
+ ev->mc_index,
+ ev->top_layer,
+ ev->middle_layer,
+ ev->lower_layer,
+ ev->address,
+ ev->grain,
+ ev->syndrome,
+ ev->driver_detail);
strcat(buf, bt_buf);
@@ -141,53 +134,53 @@ static int set_mce_event_backtrace(char *buf, struct mce_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "bank_name=%s\n" \
- "error_msg=%s\n" \
- "mcgstatus_msg=%s\n" \
- "mcistatus_msg=%s\n" \
- "mcastatus_msg=%s\n" \
- "user_action=%s\n" \
- "mc_location=%s\n" \
- "mcgcap=%lu\n" \
- "mcgstatus=%lu\n" \
- "status=%lu\n" \
- "addr=%lu\n" \
- "misc=%lu\n" \
- "ip=%lu\n" \
- "tsc=%lu\n" \
- "walltime=%lu\n" \
- "cpu=%u\n" \
- "cpuid=%u\n" \
- "apicid=%u\n" \
- "socketid=%u\n" \
- "cs=%d\n" \
- "bank=%d\n" \
- "cpuvendor=%d\n", \
- ev->timestamp, \
- ev->bank_name, \
- ev->error_msg, \
- ev->mcgstatus_msg, \
- ev->mcistatus_msg, \
- ev->mcastatus_msg, \
- ev->user_action, \
- ev->mc_location, \
- ev->mcgcap, \
- ev->mcgstatus, \
- ev->status, \
- ev->addr, \
- ev->misc, \
- ev->ip, \
- ev->tsc, \
- ev->walltime, \
- ev->cpu, \
- ev->cpuid, \
- ev->apicid, \
- ev->socketid, \
- ev->cs, \
- ev->bank, \
- ev->cpuvendor);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "bank_name=%s\n"
+ "error_msg=%s\n"
+ "mcgstatus_msg=%s\n"
+ "mcistatus_msg=%s\n"
+ "mcastatus_msg=%s\n"
+ "user_action=%s\n"
+ "mc_location=%s\n"
+ "mcgcap=%lu\n"
+ "mcgstatus=%lu\n"
+ "status=%lu\n"
+ "addr=%lu\n"
+ "misc=%lu\n"
+ "ip=%lu\n"
+ "tsc=%lu\n"
+ "walltime=%lu\n"
+ "cpu=%u\n"
+ "cpuid=%u\n"
+ "apicid=%u\n"
+ "socketid=%u\n"
+ "cs=%d\n"
+ "bank=%d\n"
+ "cpuvendor=%d\n",
+ ev->timestamp,
+ ev->bank_name,
+ ev->error_msg,
+ ev->mcgstatus_msg,
+ ev->mcistatus_msg,
+ ev->mcastatus_msg,
+ ev->user_action,
+ ev->mc_location,
+ ev->mcgcap,
+ ev->mcgstatus,
+ ev->status,
+ ev->addr,
+ ev->misc,
+ ev->ip,
+ ev->tsc,
+ ev->walltime,
+ ev->cpu,
+ ev->cpuid,
+ ev->apicid,
+ ev->socketid,
+ ev->cs,
+ ev->bank,
+ ev->cpuvendor);
strcat(buf, bt_buf);
@@ -201,15 +194,15 @@ static int set_aer_event_backtrace(char *buf, struct ras_aer_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "error_type=%s\n" \
- "dev_name=%s\n" \
- "msg=%s\n", \
- ev->timestamp, \
- ev->error_type, \
- ev->dev_name, \
- ev->msg);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "error_type=%s\n"
+ "dev_name=%s\n"
+ "msg=%s\n",
+ ev->timestamp,
+ ev->error_type,
+ ev->dev_name,
+ ev->msg);
strcat(buf, bt_buf);
@@ -223,13 +216,13 @@ static int set_non_standard_event_backtrace(char *buf, struct ras_non_standard_e
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "severity=%s\n" \
- "length=%d\n", \
- ev->timestamp, \
- ev->severity, \
- ev->length);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "severity=%s\n"
+ "length=%d\n",
+ ev->timestamp,
+ ev->severity,
+ ev->length);
strcat(buf, bt_buf);
@@ -243,21 +236,21 @@ static int set_arm_event_backtrace(char *buf, struct ras_arm_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "error_count=%d\n" \
- "affinity=%d\n" \
- "mpidr=0x%lx\n" \
- "midr=0x%lx\n" \
- "running_state=%d\n" \
- "psci_state=%d\n", \
- ev->timestamp, \
- ev->error_count, \
- ev->affinity, \
- ev->mpidr, \
- ev->midr, \
- ev->running_state, \
- ev->psci_state);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "error_count=%d\n"
+ "affinity=%d\n"
+ "mpidr=0x%lx\n"
+ "midr=0x%lx\n"
+ "running_state=%d\n"
+ "psci_state=%d\n",
+ ev->timestamp,
+ ev->error_count,
+ ev->affinity,
+ ev->mpidr,
+ ev->midr,
+ ev->running_state,
+ ev->psci_state);
strcat(buf, bt_buf);
@@ -271,19 +264,19 @@ static int set_devlink_event_backtrace(char *buf, struct devlink_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "bus_name=%s\n" \
- "dev_name=%s\n" \
- "driver_name=%s\n" \
- "reporter_name=%s\n" \
- "msg=%s\n", \
- ev->timestamp, \
- ev->bus_name, \
- ev->dev_name, \
- ev->driver_name, \
- ev->reporter_name, \
- ev->msg);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "bus_name=%s\n"
+ "dev_name=%s\n"
+ "driver_name=%s\n"
+ "reporter_name=%s\n"
+ "msg=%s\n",
+ ev->timestamp,
+ ev->bus_name,
+ ev->dev_name,
+ ev->driver_name,
+ ev->reporter_name,
+ ev->msg);
strcat(buf, bt_buf);
@@ -297,21 +290,21 @@ static int set_diskerror_event_backtrace(char *buf, struct diskerror_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "dev=%s\n" \
- "sector=%llu\n" \
- "nr_sector=%u\n" \
- "error=%s\n" \
- "rwbs=%s\n" \
- "cmd=%s\n", \
- ev->timestamp, \
- ev->dev, \
- ev->sector, \
- ev->nr_sector, \
- ev->error, \
- ev->rwbs, \
- ev->cmd);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "dev=%s\n"
+ "sector=%llu\n"
+ "nr_sector=%u\n"
+ "error=%s\n"
+ "rwbs=%s\n"
+ "cmd=%s\n",
+ ev->timestamp,
+ ev->dev,
+ ev->sector,
+ ev->nr_sector,
+ ev->error,
+ ev->rwbs,
+ ev->cmd);
strcat(buf, bt_buf);
@@ -325,15 +318,15 @@ static int set_mf_event_backtrace(char *buf, struct ras_mf_event *ev)
if (!buf || !ev)
return -1;
- sprintf(bt_buf, "BACKTRACE=" \
- "timestamp=%s\n" \
- "pfn=%s\n" \
- "page_type=%s\n" \
- "action_result=%s\n", \
- ev->timestamp, \
- ev->pfn, \
- ev->page_type, \
- ev->action_result);
+ sprintf(bt_buf, "BACKTRACE="
+ "timestamp=%s\n"
+ "pfn=%s\n"
+ "page_type=%s\n"
+ "action_result=%s\n",
+ ev->timestamp,
+ ev->pfn,
+ ev->page_type,
+ ev->action_result);
strcat(buf, bt_buf);
@@ -346,60 +339,64 @@ static int commit_report_backtrace(int sockfd, int type, void *ev){
int rc = -1;
int buf_len = 0;
- if (sockfd < 0 || !ev) {
+ if (sockfd < 0 || !ev)
return -1;
- }
memset(buf, 0, MAX_BACKTRACE_SIZE);
switch (type) {
case MC_EVENT:
- rc = set_mc_event_backtrace(buf, (struct ras_mc_event *)ev);
+ rc = set_mc_event_backtrace(buf,
+ (struct ras_mc_event *)ev);
break;
case AER_EVENT:
- rc = set_aer_event_backtrace(buf, (struct ras_aer_event *)ev);
+ rc = set_aer_event_backtrace(buf,
+ (struct ras_aer_event *)ev);
break;
case MCE_EVENT:
- rc = set_mce_event_backtrace(buf, (struct mce_event *)ev);
+ rc = set_mce_event_backtrace(buf,
+ (struct mce_event *)ev);
break;
case NON_STANDARD_EVENT:
- rc = set_non_standard_event_backtrace(buf, (struct ras_non_standard_event *)ev);
+ rc = set_non_standard_event_backtrace(buf,
+ (struct ras_non_standard_event *)ev);
break;
case ARM_EVENT:
- rc = set_arm_event_backtrace(buf, (struct ras_arm_event *)ev);
+ rc = set_arm_event_backtrace(buf,
+ (struct ras_arm_event *)ev);
break;
case DEVLINK_EVENT:
- rc = set_devlink_event_backtrace(buf, (struct devlink_event *)ev);
+ rc = set_devlink_event_backtrace(buf,
+ (struct devlink_event *)ev);
break;
case DISKERROR_EVENT:
- rc = set_diskerror_event_backtrace(buf, (struct diskerror_event *)ev);
+ rc = set_diskerror_event_backtrace(buf,
+ (struct diskerror_event *)ev);
break;
case MF_EVENT:
- rc = set_mf_event_backtrace(buf, (struct ras_mf_event *)ev);
+ rc = set_mf_event_backtrace(buf,
+ (struct ras_mf_event *)ev);
break;
default:
return -1;
}
- if (rc < 0) {
+ if (rc < 0)
return -1;
- }
buf_len = strlen(buf);
for (; buf_len > INPUT_BUFFER_SIZE - 1; buf_len -= (INPUT_BUFFER_SIZE - 1)) {
rc = write(sockfd, pbuf, INPUT_BUFFER_SIZE - 1);
- if (rc < INPUT_BUFFER_SIZE - 1) {
+ if (rc < INPUT_BUFFER_SIZE - 1)
return -1;
- }
pbuf = pbuf + INPUT_BUFFER_SIZE - 1;
}
rc = write(sockfd, pbuf, buf_len + 1);
- if (rc < buf_len) {
+ if (rc < buf_len)
return -1;
- }
return 0;
}
@@ -414,45 +411,37 @@ int ras_report_mc_event(struct ras_events *ras, struct ras_mc_event *ev)
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return -1;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto mc_fail;
- }
rc = commit_report_backtrace(sockfd, MC_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto mc_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-mc");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto mc_fail;
- }
sprintf(buf, "REASON=%s", "EDAC driver report problem");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto mc_fail;
- }
done = 1;
mc_fail:
-
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
- if (done) {
+ if (done)
return 0;
- } else {
- return -1;
- }
+
+ return -1;
}
int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev)
@@ -465,45 +454,38 @@ int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev)
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return -1;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto aer_fail;
- }
rc = commit_report_backtrace(sockfd, AER_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto aer_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-aer");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto aer_fail;
- }
sprintf(buf, "REASON=%s", "PCIe AER driver report problem");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto aer_fail;
- }
done = 1;
aer_fail:
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
- if (done) {
+ if (done)
return 0;
- } else {
- return -1;
- }
+
+ return -1;
}
int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standard_event *ev)
@@ -515,39 +497,33 @@ int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standar
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return rc;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto non_standard_fail;
- }
rc = commit_report_backtrace(sockfd, NON_STANDARD_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto non_standard_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-non-standard");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto non_standard_fail;
- }
sprintf(buf, "REASON=%s", "Unknown CPER section problem");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto non_standard_fail;
- }
rc = 0;
non_standard_fail:
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
return rc;
}
@@ -561,39 +537,33 @@ int ras_report_arm_event(struct ras_events *ras, struct ras_arm_event *ev)
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return rc;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto arm_fail;
- }
rc = commit_report_backtrace(sockfd, ARM_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto arm_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-arm");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto arm_fail;
- }
sprintf(buf, "REASON=%s", "ARM CPU report problem");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto arm_fail;
- }
rc = 0;
arm_fail:
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
return rc;
}
@@ -608,45 +578,38 @@ int ras_report_mce_event(struct ras_events *ras, struct mce_event *ev)
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return -1;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto mce_fail;
- }
rc = commit_report_backtrace(sockfd, MCE_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto mce_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-mce");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto mce_fail;
- }
sprintf(buf, "REASON=%s", "Machine Check driver report problem");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto mce_fail;
- }
done = 1;
mce_fail:
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
- if (done) {
+ if (done)
return 0;
- } else {
- return -1;
- }
+
+ return -1;
}
int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev)
@@ -659,45 +622,38 @@ int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev)
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return -1;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto devlink_fail;
- }
rc = commit_report_backtrace(sockfd, DEVLINK_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto devlink_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-devlink");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto devlink_fail;
- }
sprintf(buf, "REASON=%s", "devlink health report problem");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto devlink_fail;
- }
done = 1;
devlink_fail:
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
- if (done) {
+ if (done)
return 0;
- } else {
- return -1;
- }
+
+ return -1;
}
int ras_report_diskerror_event(struct ras_events *ras, struct diskerror_event *ev)
@@ -710,44 +666,37 @@ int ras_report_diskerror_event(struct ras_events *ras, struct diskerror_event *e
memset(buf, 0, sizeof(buf));
sockfd = setup_report_socket();
- if (sockfd < 0) {
+ if (sockfd < 0)
return -1;
- }
rc = commit_report_basic(sockfd);
- if (rc < 0) {
+ if (rc < 0)
goto diskerror_fail;
- }
rc = commit_report_backtrace(sockfd, DISKERROR_EVENT, ev);
- if (rc < 0) {
+ if (rc < 0)
goto diskerror_fail;
- }
sprintf(buf, "ANALYZER=%s", "rasdaemon-diskerror");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto diskerror_fail;
- }
sprintf(buf, "REASON=%s", "disk I/O error");
rc = write(sockfd, buf, strlen(buf) + 1);
- if (rc < strlen(buf) + 1) {
+ if (rc < strlen(buf) + 1)
goto diskerror_fail;
- }
done = 1;
diskerror_fail:
- if (sockfd >= 0) {
+ if (sockfd >= 0)
close(sockfd);
- }
- if (done) {
+ if (done)
return 0;
- } else {
- return -1;
- }
+
+ return -1;
}
int ras_report_mf_event(struct ras_events *ras, struct ras_mf_event *ev)
diff --git a/rbtree.c b/rbtree.c
index 43da434..86d061c 100644
--- a/rbtree.c
+++ b/rbtree.c
@@ -1,25 +1,23 @@
/*
- Red Black Trees
- (C) 1999 Andrea Arcangeli <[email protected]>
- (C) 2002 David Woodhouse <[email protected]>
- Taken from the Linux 2.6.30 source with some minor modificatons.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- linux/lib/rbtree.c
-*/
+ * Red Black Trees
+ * (C) 1999 Andrea Arcangeli <[email protected]>
+ * (C) 2002 David Woodhouse <[email protected]>
+ * Taken from the Linux 2.6.30 source with some minor modificatons.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
#include "rbtree.h"
@@ -35,14 +33,14 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
rb_set_parent(right, parent);
- if (parent)
- {
+ if (parent) {
if (node == parent->rb_left)
parent->rb_left = right;
else
parent->rb_right = right;
- } else
+ } else {
root->rb_node = right;
+ }
rb_set_parent(node, right);
}
@@ -58,14 +56,14 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
rb_set_parent(left, parent);
- if (parent)
- {
+ if (parent) {
if (node == parent->rb_right)
parent->rb_right = left;
else
parent->rb_left = left;
- } else
+ } else {
root->rb_node = left;
+ }
rb_set_parent(node, left);
}
@@ -73,27 +71,21 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root)
{
struct rb_node *parent, *gparent;
- while ((parent = rb_parent(node)) && rb_is_red(parent))
- {
+ while ((parent = rb_parent(node)) && rb_is_red(parent)) {
gparent = rb_parent(parent);
- if (parent == gparent->rb_left)
- {
- {
- register struct rb_node *uncle = gparent->rb_right;
-
- if (uncle && rb_is_red(uncle))
- {
- rb_set_black(uncle);
- rb_set_black(parent);
- rb_set_red(gparent);
- node = gparent;
- continue;
- }
+ if (parent == gparent->rb_left) {
+ register struct rb_node *uncle = gparent->rb_right;
+
+ if (uncle && rb_is_red(uncle)) {
+ rb_set_black(uncle);
+ rb_set_black(parent);
+ rb_set_red(gparent);
+ node = gparent;
+ continue;
}
- if (parent->rb_right == node)
- {
+ if (parent->rb_right == node) {
struct rb_node *tmp;
__rb_rotate_left(parent, root);
@@ -106,21 +98,17 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root)
rb_set_red(gparent);
__rb_rotate_right(gparent, root);
} else {
- {
- struct rb_node *uncle = gparent->rb_left;
-
- if (uncle && rb_is_red(uncle))
- {
- rb_set_black(uncle);
- rb_set_black(parent);
- rb_set_red(gparent);
- node = gparent;
- continue;
- }
+ struct rb_node *uncle = gparent->rb_left;
+
+ if (uncle && rb_is_red(uncle)) {
+ rb_set_black(uncle);
+ rb_set_black(parent);
+ rb_set_red(gparent);
+ node = gparent;
+ continue;
}
- if (parent->rb_left == node)
- {
+ if (parent->rb_left == node) {
struct rb_node *tmp;
__rb_rotate_right(parent, root);
@@ -143,28 +131,22 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
{
struct rb_node *other;
- while ((!node || rb_is_black(node)) && node != root->rb_node)
- {
- if (parent->rb_left == node)
- {
+ while ((!node || rb_is_black(node)) && node != root->rb_node) {
+ if (parent->rb_left == node) {
other = parent->rb_right;
- if (rb_is_red(other))
- {
+ if (rb_is_red(other)) {
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_left(parent, root);
other = parent->rb_right;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
- (!other->rb_right || rb_is_black(other->rb_right)))
- {
+ (!other->rb_right || rb_is_black(other->rb_right))) {
rb_set_red(other);
node = parent;
parent = rb_parent(node);
- } else
- {
- if (!other->rb_right || rb_is_black(other->rb_right))
- {
+ } else {
+ if (!other->rb_right || rb_is_black(other->rb_right)) {
rb_set_black(other->rb_left);
rb_set_red(other);
__rb_rotate_right(other, root);
@@ -177,26 +159,21 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
node = root->rb_node;
break;
}
- } else
- {
+ } else {
other = parent->rb_left;
- if (rb_is_red(other))
- {
+ if (rb_is_red(other)) {
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_right(parent, root);
other = parent->rb_left;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
- (!other->rb_right || rb_is_black(other->rb_right)))
- {
+ (!other->rb_right || rb_is_black(other->rb_right))) {
rb_set_red(other);
node = parent;
parent = rb_parent(node);
- } else
- {
- if (!other->rb_left || rb_is_black(other->rb_left))
- {
+ } else {
+ if (!other->rb_left || rb_is_black(other->rb_left)) {
rb_set_black(other->rb_right);
rb_set_red(other);
__rb_rotate_left(other, root);
@@ -220,12 +197,11 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
struct rb_node *child, *parent;
int color;
- if (!node->rb_left)
+ if (!node->rb_left) {
child = node->rb_right;
- else if (!node->rb_right)
+ } else if (!node->rb_right) {
child = node->rb_left;
- else
- {
+ } else {
struct rb_node *old = node, *left;
node = node->rb_right;
@@ -240,21 +216,22 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
if (parent == old) {
parent->rb_right = child;
parent = node;
- } else
+ } else {
parent->rb_left = child;
+ }
node->rb_parent_color = old->rb_parent_color;
node->rb_right = old->rb_right;
node->rb_left = old->rb_left;
- if (rb_parent(old))
- {
+ if (rb_parent(old)) {
if (rb_parent(old)->rb_left == old)
rb_parent(old)->rb_left = node;
else
rb_parent(old)->rb_right = node;
- } else
+ } else {
root->rb_node = node;
+ }
rb_set_parent(old->rb_left, node);
if (old->rb_right)
@@ -267,14 +244,14 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
if (child)
rb_set_parent(child, parent);
- if (parent)
- {
+ if (parent) {
if (parent->rb_left == node)
parent->rb_left = child;
else
parent->rb_right = child;
- } else
+ } else {
root->rb_node = child;
+ }
color:
if (color == RB_BLACK)
@@ -315,8 +292,10 @@ struct rb_node *rb_next(const struct rb_node *node)
if (rb_parent(node) == node)
return NULL;
- /* If we have a right-hand child, go down and then left as far
- as we can. */
+ /*
+ * If we have a right-hand child, go down and then left as far
+ * as we can.
+ */
if (node->rb_right) {
node = node->rb_right;
while (node->rb_left)
@@ -324,12 +303,14 @@ struct rb_node *rb_next(const struct rb_node *node)
return (struct rb_node *)node;
}
- /* No right-hand children. Everything down and left is
- smaller than us, so any 'next' node must be in the general
- direction of our parent. Go up the tree; any time the
- ancestor is a right-hand child of its parent, keep going
- up. First time it's a left-hand child of its parent, said
- parent is our 'next' node. */
+ /*
+ * No right-hand children. Everything down and left is
+ * smaller than us, so any 'next' node must be in the general
+ * direction of our parent. Go up the tree; any time the
+ * ancestor is a right-hand child of its parent, keep going
+ * up. First time it's a left-hand child of its parent, said
+ * parent is our 'next' node.
+ */
while ((parent = rb_parent(node)) && node == parent->rb_right)
node = parent;
@@ -343,8 +324,10 @@ struct rb_node *rb_prev(const struct rb_node *node)
if (rb_parent(node) == node)
return NULL;
- /* If we have a left-hand child, go down and then right as far
- as we can. */
+ /*
+ * If we have a left-hand child, go down and then right as far
+ * as we can.
+ */
if (node->rb_left) {
node = node->rb_left;
while (node->rb_right)
@@ -352,8 +335,10 @@ struct rb_node *rb_prev(const struct rb_node *node)
return (struct rb_node *)node;
}
- /* No left-hand children. Go up till we find an ancestor which
- is a right-hand child of its parent */
+ /*
+ * No left-hand children. Go up till we find an ancestor which
+ * is a right-hand child of its parent
+ */
while ((parent = rb_parent(node)) && node == parent->rb_left)
node = parent;
diff --git a/rbtree.h b/rbtree.h
index e8c38de..7fb15fa 100644
--- a/rbtree.h
+++ b/rbtree.h
@@ -1,96 +1,96 @@
/*
- Red Black Trees
- (C) 1999 Andrea Arcangeli <[email protected]>
- Taken from the Linux 2.6.30 source.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- linux/include/linux/rbtree.h
-
- To use rbtrees you'll have to implement your own insert and search cores.
- This will avoid us to use callbacks and to drop drammatically performances.
- I know it's not the cleaner way, but in C (not in C++) to get
- performances and genericity...
-
- Some example of insert and search follows here. The search is a plain
- normal search over an ordered tree. The insert instead must be implemented
- int two steps: as first thing the code must insert the element in
- order as a red leaf in the tree, then the support library function
- rb_insert_color() must be called. Such function will do the
- not trivial work to rebalance the rbtree if necessary.
-
------------------------------------------------------------------------
-static inline struct page * rb_search_page_cache(struct inode * inode,
- unsigned long offset)
-{
- struct rb_node * n = inode->i_rb_page_cache.rb_node;
- struct page * page;
-
- while (n)
- {
- page = rb_entry(n, struct page, rb_page_cache);
-
- if (offset < page->offset)
- n = n->rb_left;
- else if (offset > page->offset)
- n = n->rb_right;
- else
- return page;
- }
- return NULL;
-}
-
-static inline struct page * __rb_insert_page_cache(struct inode * inode,
- unsigned long offset,
- struct rb_node * node)
-{
- struct rb_node ** p = &inode->i_rb_page_cache.rb_node;
- struct rb_node * parent = NULL;
- struct page * page;
-
- while (*p)
- {
- parent = *p;
- page = rb_entry(parent, struct page, rb_page_cache);
-
- if (offset < page->offset)
- p = &(*p)->rb_left;
- else if (offset > page->offset)
- p = &(*p)->rb_right;
- else
- return page;
- }
-
- rb_link_node(node, parent, p);
-
- return NULL;
-}
+ * Red Black Trees
+ * (C) 1999 Andrea Arcangeli <[email protected]>
+ * Taken from the Linux 2.6.30 source.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
-static inline struct page * rb_insert_page_cache(struct inode * inode,
- unsigned long offset,
- struct rb_node * node)
-{
- struct page * ret;
- if ((ret = __rb_insert_page_cache(inode, offset, node)))
- goto out;
- rb_insert_color(node, &inode->i_rb_page_cache);
- out:
- return ret;
-}
------------------------------------------------------------------------
-*/
+/*
+ * To use rbtrees you'll have to implement your own insert and search cores.
+ * This will avoid us to use callbacks and to drop drammatically performances.
+ * I know it's not the cleaner way, but in C (not in C++) to get
+ * performances and genericity...
+ *
+ * Some example of insert and search follows here. The search is a plain
+ * normal search over an ordered tree. The insert instead must be implemented
+ * int two steps: as first thing the code must insert the element in
+ * order as a red leaf in the tree, then the support library function
+ * rb_insert_color() must be called. Such function will do the
+ * not trivial work to rebalance the rbtree if necessary.
+ *
+ * -----------------------------------------------------------------------
+ *
+ * static inline struct page * rb_search_page_cache(struct inode * inode,
+ * unsigned long offset)
+ * {
+ * struct rb_node * n = inode->i_rb_page_cache.rb_node;
+ * struct page * page;
+ *
+ * while (n)
+ * {
+ * page = rb_entry(n, struct page, rb_page_cache);
+ *
+ * if (offset < page->offset)
+ * n = n->rb_left;
+ * else if (offset > page->offset)
+ * n = n->rb_right;
+ * else
+ * return page;
+ * }
+ * return NULL;
+ * }
+ *
+ * static inline struct page * __rb_insert_page_cache(struct inode * inode,
+ * unsigned long offset,
+ * struct rb_node * node)
+ * {
+ * struct rb_node ** p = &inode->i_rb_page_cache.rb_node;
+ * struct rb_node * parent = NULL;
+ * struct page * page;
+ *
+ * while (*p)
+ * {
+ * parent = *p;
+ * page = rb_entry(parent, struct page, rb_page_cache);
+ *
+ * if (offset < page->offset)
+ * p = &(*p)->rb_left;
+ * else if (offset > page->offset)
+ * p = &(*p)->rb_right;
+ * else
+ * return page;
+ * }
+ *
+ * rb_link_node(node, parent, p);
+ *
+ * return NULL;
+ * }
+ *
+ * static inline struct page * rb_insert_page_cache(struct inode * inode,
+ * unsigned long offset,
+ * struct rb_node * node)
+ * {
+ * struct page * ret;
+ * if ((ret = __rb_insert_page_cache(inode, offset, node)))
+ * goto out;
+ * rb_insert_color(node, &inode->i_rb_page_cache);
+ * out:
+ * return ret;
+ * }
+ */
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
@@ -98,8 +98,9 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
#include <stddef.h>
#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
+ const typeof(((type *)0)->member) *__mptr = (ptr); \
+ (type *)((char *)__mptr - offsetof(type, member)); \
+})
struct rb_node {
unsigned long rb_parent_color;
--
2.33.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-anolis-os/rasdaemon.git
[email protected]:src-anolis-os/rasdaemon.git
src-anolis-os
rasdaemon
rasdaemon
a8

搜索帮助