From: Mauro Carvalho Chehab Date: Mon, 22 Jan 2024 07:36:47 +0000 (+0100) Subject: C files: cleanup coding style X-Git-Tag: v0.8.1~48 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7b3de7f9707a9b7b087b0f0013c21ac6561e287d;p=users%2Fmchehab%2Frasdaemon.git C files: cleanup coding style The rasdaemon conding style follows Linux Kernel where it makes sense. Yet, changes made overtime ended with some coding style non-compliances. Adjust rasdaemon coding style by using: scripts/checkpatch.pl --fix-inplace --strict *.c --ignore PREFER_KERNEL_TYPES And doing some manual fixups where the script didn't work. As a bonus, some typos were also fixed on some rasdaemon messages. Signed-off-by: Mauro Carvalho Chehab --- diff --git a/bitfield.c b/bitfield.c index f004755..2076683 100644 --- a/bitfield.c +++ b/bitfield.c @@ -25,10 +25,10 @@ #include "ras-mce-handler.h" #include "bitfield.h" -unsigned bitfield_msg(char *buf, size_t len, const char **bitarray, - unsigned array_len, - unsigned bit_offset, unsigned ignore_bits, - uint64_t status) +unsigned int bitfield_msg(char *buf, size_t len, const char **bitarray, + unsigned int array_len, + unsigned int bit_offset, unsigned int ignore_bits, + uint64_t status) { int i, n; char *p = buf; @@ -64,6 +64,7 @@ unsigned bitfield_msg(char *buf, size_t len, const char **bitarray, static uint64_t bitmask(uint64_t i) { uint64_t mask = 1; + while (mask < i) mask = (mask << 1) | 1; return mask; @@ -77,6 +78,7 @@ void decode_bitfield(struct mce_event *e, uint64_t status, for (f = fields; f->str; f++) { uint64_t v = (status >> f->start_bit) & bitmask(f->stringlen - 1); char *s = NULL; + if (v < f->stringlen) s = f->str[v]; if (!s) { @@ -93,11 +95,14 @@ void decode_numfield(struct mce_event *e, uint64_t status, struct numfield *fields) { struct numfield *f; + for (f = fields; f->name; f++) { uint64_t mask = (1ULL << (f->end - f->start + 1)) - 1; uint64_t v = (status >> f->start) & mask; + if (v > 0 || f->force) { char fmt[32] = {0}; + snprintf(fmt, 32, "%%s: %s\n", f->fmt ? f->fmt : "%Lu"); mce_snprintf(e->error_msg, fmt, f->name, v); } diff --git a/mce-amd-k8.c b/mce-amd-k8.c index dc772c2..f27b823 100644 --- a/mce-amd-k8.c +++ b/mce-amd-k8.c @@ -43,7 +43,7 @@ static const char *k8bank[] = { }; static const char *k8threshold[] = { - [0 ... K8_MCELOG_THRESHOLD_DRAM_ECC - 1] = "Unknow threshold counter", + [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", [K8_MCELOG_THRESHOLD_L3_CACHE] = "MC4_MISC2 L3 Cache threshold", @@ -56,25 +56,31 @@ static const char *k8threshold[] = { static const char *transaction[] = { "instruction", "data", "generic", "reserved" }; + static const char *cachelevel[] = { "0", "1", "2", "generic" }; + static const char *memtrans[] = { "generic error", "generic read", "generic write", "data read", "data write", "instruction fetch", "prefetch", "evict", "snoop", "?", "?", "?", "?", "?", "?", "?" }; + static const char *partproc[] = { "local node origin", "local node response", "local node observed", "generic participation" }; + static const char *timeout[] = { "request didn't time out", "request timed out" }; + static const char *memoryio[] = { "memory", "res.", "i/o", "generic" }; + static const char *nbextendederr[] = { "RAM ECC error", "CRC error", @@ -96,6 +102,7 @@ static const char *nbextendederr[] = { "L3 Cache Tag Error", "L3 Cache LRU Error" }; + static const char *highbits[32] = { [31] = "valid", [30] = "error overflow (multiple errors)", @@ -164,7 +171,7 @@ static void decode_k8_dc_mc(struct mce_event *e) if (e->status & (3ULL << 45)) { mce_snprintf(e->error_msg, "Data cache ECC error (syndrome %x)", - (uint32_t) (e->status >> 47) & 0xff); + (uint32_t)(e->status >> 47) & 0xff); if (e->status & (1ULL << 40)) mce_snprintf(e->error_msg, "found by scrubber"); } @@ -185,7 +192,7 @@ static void decode_k8_ic_mc(struct mce_event *e) if ((errcode & 0xfff0) == 0x0010) mce_snprintf(e->error_msg, "TLB parity error in %s array", - (exterrcode == 0) ? "physical" : "virtual"); + (exterrcode == 0) ? "physical" : "virtual"); } static void decode_k8_bu_mc(struct mce_event *e) @@ -196,10 +203,10 @@ static void decode_k8_bu_mc(struct mce_event *e) mce_snprintf(e->error_msg, "L2 cache ECC error"); mce_snprintf(e->error_msg, "%s array error", - !exterrcode ? "Bus or cache" : "Cache tag"); + !exterrcode ? "Bus or cache" : "Cache tag"); } -static void decode_k8_nb_mc(struct mce_event *e, unsigned *memerr) +static void decode_k8_nb_mc(struct mce_event *e, unsigned int *memerr) { unsigned short exterrcode = (e->status >> 16) & 0x0f; @@ -209,13 +216,13 @@ static void decode_k8_nb_mc(struct mce_event *e, unsigned *memerr) case 0: *memerr = 1; mce_snprintf(e->error_msg, "ECC syndrome = %x", - (uint32_t) (e->status >> 47) & 0xff); + (uint32_t)(e->status >> 47) & 0xff); break; case 8: *memerr = 1; mce_snprintf(e->error_msg, "Chipkill ECC syndrome = %x", - (uint32_t) ((((e->status >> 24) & 0xff) << 8) - | ((e->status >> 47) & 0xff))); + (uint32_t)((((e->status >> 24) & 0xff) << 8) + | ((e->status >> 47) & 0xff))); break; case 1: case 2: @@ -223,7 +230,7 @@ static void decode_k8_nb_mc(struct mce_event *e, unsigned *memerr) case 4: case 6: mce_snprintf(e->error_msg, "link number = %x", - (uint32_t) (e->status >> 36) & 0xf); + (uint32_t)(e->status >> 36) & 0xf); break; } } @@ -251,11 +258,12 @@ static void bank_name(struct mce_event *e) int parse_amd_k8_event(struct ras_events *ras, struct mce_event *e) { - unsigned ismemerr = 0; + unsigned int ismemerr = 0; /* Don't handle GART errors */ if (e->bank == 4) { unsigned short exterrcode = (e->status >> 16) & 0x0f; + if (exterrcode == 5 && (e->status & (1ULL << 61))) { return -1; } diff --git a/mce-amd-smca.c b/mce-amd-smca.c index 6b2b92b..45cf67d 100644 --- a/mce-amd-smca.c +++ b/mce-amd-smca.c @@ -74,10 +74,10 @@ enum smca_bank_types { SMCA_PCIE, /* PCI Express Unit */ SMCA_PCIE_V2, SMCA_XGMI_PCS, /* xGMI PCS Unit */ - SMCA_NBIF, /*NBIF Unit */ - SMCA_SHUB, /* System Hub Unit */ - SMCA_SATA, /* SATA Unit */ - SMCA_USB, /* USB Unit */ + SMCA_NBIF, /* NBIF Unit */ + SMCA_SHUB, /* System Hub Unit */ + SMCA_SATA, /* SATA Unit */ + SMCA_USB, /* USB Unit */ SMCA_USR_DP, /* Ultra Short Reach Data Plane Controller */ SMCA_USR_CP, /* Ultra Short Reach Control Plane Controller */ SMCA_GMI_PCS, /* GMI PCS Unit */ @@ -799,7 +799,7 @@ static struct smca_bank_name smca_names[] = { [SMCA_PSP ... SMCA_PSP_V2] = { "Platform Security Processor" }, [SMCA_SMU ... SMCA_SMU_V2] = { "System Management Unit" }, [SMCA_MP5] = { "Microprocessor 5 Unit" }, - [SMCA_MPDMA] = { "MPDMA Unit" }, + [SMCA_MPDMA] = { "MPDMA Unit" }, [SMCA_NBIO] = { "Northbridge IO Unit" }, [SMCA_PCIE ... SMCA_PCIE_V2] = { "PCI Express Unit" }, [SMCA_XGMI_PCS] = { "Ext Global Memory Interconnect PCS Unit" }, @@ -817,7 +817,6 @@ static struct smca_bank_name smca_names[] = { void amd_decode_errcode(struct mce_event *e) { - decode_amd_errcode(e); if (e->status & MCI_STATUS_POISON) @@ -825,8 +824,8 @@ void amd_decode_errcode(struct mce_event *e) if (e->status & MCI_STATUS_TCC) mce_snprintf(e->mcistatus_msg, "Task_context_corrupt"); - } + /* * To find the UMC channel represented by this bank we need to match on its * instance_id. The instance_id of a bank is held in the lower 32 bits of its @@ -856,7 +855,7 @@ static int find_hbm_channel(struct mce_event *e) return (umc % 2) ? tmp + 4 : tmp; } -static inline void fixup_hwid(struct mce_priv* m, uint32_t *hwid_mcatype) +static inline void fixup_hwid(struct mce_priv *m, uint32_t *hwid_mcatype) { if (m->family == 0x19) { switch (m->model) { @@ -965,7 +964,6 @@ void decode_smca_error(struct mce_event *e, struct mce_priv *m) channel, csrow); } - if (e->vdata_len) { uint64_t smca_config = e->vdata[2]; @@ -976,7 +974,6 @@ void decode_smca_error(struct mce_event *e, struct mce_priv *m) if (smca_config & BIT(9)) memcpy(e->frutext, e->vdata, 16); } - } int parse_amd_smca_event(struct ras_events *ras, struct mce_event *e) @@ -984,7 +981,7 @@ int parse_amd_smca_event(struct ras_events *ras, struct mce_event *e) uint64_t mcgstatus = e->mcgstatus; mce_snprintf(e->mcgstatus_msg, "mcgstatus=%lld", - (long long)e->mcgstatus); + (long long)e->mcgstatus); if (mcgstatus & MCG_STATUS_RIPV) mce_snprintf(e->mcgstatus_msg, "RIPV"); diff --git a/mce-amd.c b/mce-amd.c index 116df11..ac0dbac 100644 --- a/mce-amd.c +++ b/mce-amd.c @@ -26,26 +26,31 @@ static char *transaction[] = { "instruction", "data", "generic", "reserved" }; + /* Error codes: cache level (LL) */ static char *cachelevel[] = { "reserved", "L1", "L2", "L3/generic" }; + /* Error codes: memory transaction type (RRRR) */ static char *memtrans[] = { "generic", "generic read", "generic write", "data read", "data write", "instruction fetch", "prefetch", "evict", "snoop", "?", "?", "?", "?", "?", "?", "?" }; + /* Participation Processor */ static char *partproc[] = { "local node origin", "local node response", "local node observed", "generic participation" }; + /* Timeout */ static char *timeout[] = { "request didn't time out", "request timed out" }; + /* internal unclassified error code */ static char *internal[] = { "reserved", "reserved", @@ -118,5 +123,4 @@ void decode_amd_errcode(struct mce_event *e) PP_MSG(ec), TO_MSG(ec), R4_MSG(ec), LL_MSG(ec)); return; - } diff --git a/mce-intel-broadwell-de.c b/mce-intel-broadwell-de.c index d52c82e..8210782 100644 --- a/mce-intel-broadwell-de.c +++ b/mce-intel-broadwell-de.c @@ -78,7 +78,7 @@ void broadwell_de_decode_model(struct ras_events *ras, struct mce_event *e) { uint64_t status = e->status; uint32_t mca = status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan; + unsigned int rank0 = -1, rank1 = -1, chan; switch (e->bank) { case 4: @@ -115,7 +115,7 @@ void broadwell_de_decode_model(struct ras_events *ras, struct mce_event *e) /* Ignore unless this is an corrected extended error from an iMC bank */ if (e->bank < 9 || e->bank > 16 || (status & MCI_STATUS_UC) || - !test_prefix(7, status & 0xefff)) + !test_prefix(7, status & 0xefff)) return; /* @@ -140,7 +140,7 @@ void broadwell_de_decode_model(struct ras_events *ras, struct mce_event *e) */ if (rank0 != -1 && rank1 != -1) mce_snprintf(e->mc_location, "ranks=%d and %d", - rank0, rank1); + rank0, rank1); else if (rank0 != -1) mce_snprintf(e->mc_location, "rank=%d", rank0); } diff --git a/mce-intel-broadwell-epex.c b/mce-intel-broadwell-epex.c index f7cd3b6..9c863d9 100644 --- a/mce-intel-broadwell-epex.c +++ b/mce-intel-broadwell-epex.c @@ -91,7 +91,7 @@ static char *qpi[] = { [0x22] = "Phy detected in-band reset (no width change)", [0x23] = "Link failover clock failover", [0x30] = "Rx detected CRC error - successful LLR after Phy re-init", - [0x31] = "Rx detected CRC error - successful LLR wihout Phy re-init", + [0x31] = "Rx detected CRC error - successful LLR without Phy re-init", }; static struct field qpi_mc[] = { @@ -118,7 +118,7 @@ void broadwell_epex_decode_model(struct ras_events *ras, struct mce_event *e) { uint64_t status = e->status; uint32_t mca = status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan; + unsigned int rank0 = -1, rank1 = -1, chan; switch (e->bank) { case 4: @@ -160,7 +160,7 @@ void broadwell_epex_decode_model(struct ras_events *ras, struct mce_event *e) /* Ignore unless this is an corrected extended error from an iMC bank */ if (e->bank < 9 || e->bank > 16 || (status & MCI_STATUS_UC) || - !test_prefix(7, status & 0xefff)) + !test_prefix(7, status & 0xefff)) return; /* @@ -185,7 +185,7 @@ void broadwell_epex_decode_model(struct ras_events *ras, struct mce_event *e) */ if (rank0 != -1 && rank1 != -1) mce_snprintf(e->mc_location, "ranks=%d and %d", - rank0, rank1); + rank0, rank1); else if (rank0 != -1) mce_snprintf(e->mc_location, "rank=%d", rank0); } diff --git a/mce-intel-dunnington.c b/mce-intel-dunnington.c index c695c62..71c3fb4 100644 --- a/mce-intel-dunnington.c +++ b/mce-intel-dunnington.c @@ -91,6 +91,7 @@ static void dunnington_decode_bus(struct mce_event *e, uint64_t status) static void dunnington_decode_internal(struct mce_event *e, uint64_t status) { uint32_t mca = (status >> 16) & 0xffff; + if ((mca & 0xfff0) == 0) decode_bitfield(e, mca, dnt_front_status); else if ((mca & 0xf0ff) == 0) @@ -104,6 +105,7 @@ static void dunnington_decode_internal(struct mce_event *e, uint64_t status) void dunnington_decode_model(struct mce_event *e) { uint64_t status = e->status; + if ((status & 0xffff) == 0xe0f) dunnington_decode_bus(e, status); else if ((status & 0xffff) == (1 << 10)) diff --git a/mce-intel-haswell.c b/mce-intel-haswell.c index 1791a36..195f6ed 100644 --- a/mce-intel-haswell.c +++ b/mce-intel-haswell.c @@ -23,7 +23,6 @@ #include "ras-mce-handler.h" #include "bitfield.h" - /* See IA32 SDM Vol3B Table 16-20 */ static char *pcu_1[] = { @@ -92,7 +91,7 @@ static char *qpi[] = { [0x22] = "Phy detected in-band reset (no width change)", [0x23] = "Link failover clock failover", [0x30] = "Rx detected CRC error - successful LLR after Phy re-init", - [0x31] = "Rx detected CRC error - successful LLR wihout Phy re-init", + [0x31] = "Rx detected CRC error - successful LLR without Phy re-init", }; static struct field qpi_mc[] = { @@ -120,7 +119,7 @@ void hsw_decode_model(struct ras_events *ras, struct mce_event *e) { uint64_t status = e->status; uint32_t mca = status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan; + unsigned int rank0 = -1, rank1 = -1, chan; switch (e->bank) { case 4: @@ -160,7 +159,7 @@ void hsw_decode_model(struct ras_events *ras, struct mce_event *e) /* Ignore unless this is an corrected extended error from an iMC bank */ if (e->bank < 9 || e->bank > 16 || (status & MCI_STATUS_UC) || - !test_prefix(7, status & 0xefff)) + !test_prefix(7, status & 0xefff)) return; /* @@ -185,7 +184,7 @@ void hsw_decode_model(struct ras_events *ras, struct mce_event *e) */ if (rank0 != -1 && rank1 != -1) mce_snprintf(e->mc_location, "ranks=%d and %d", - rank0, rank1); + rank0, rank1); else if (rank0 != -1) mce_snprintf(e->mc_location, "rank=%d", rank0); } diff --git a/mce-intel-ivb.c b/mce-intel-ivb.c index 0c5bebc..e5e6a7a 100644 --- a/mce-intel-ivb.c +++ b/mce-intel-ivb.c @@ -90,7 +90,7 @@ void ivb_decode_model(struct ras_events *ras, struct mce_event *e) struct mce_priv *mce = ras->mce_priv; uint64_t status = e->status; uint32_t mca = status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan; + unsigned int rank0 = -1, rank1 = -1, chan; switch (e->bank) { case 4: @@ -121,7 +121,7 @@ void ivb_decode_model(struct ras_events *ras, struct mce_event *e) /* Ignore unless this is an corrected extended error from an iMC bank */ if (e->bank < 9 || e->bank > 16 || (status & MCI_STATUS_UC) || - !test_prefix(7, status & 0xefff)) + !test_prefix(7, status & 0xefff)) return; /* @@ -146,7 +146,7 @@ void ivb_decode_model(struct ras_events *ras, struct mce_event *e) */ if (rank0 >= 0 && rank1 >= 0) mce_snprintf(e->mc_location, "ranks=%d and %d", - rank0, rank1); + rank0, rank1); else if (rank0 >= 0) mce_snprintf(e->mc_location, "rank=%d", rank0); else @@ -162,7 +162,7 @@ void ivb_decode_model(struct ras_events *ras, struct mce_event *e) * faling rank to a DIMM slot. */ #if 0 -static int failrank2dimm(unsigned failrank, int socket, int channel) +static int failrank2dimm(unsigned int failrank, int socket, int channel) { switch (failrank) { case 0: case 1: case 2: case 3: diff --git a/mce-intel-knl.c b/mce-intel-knl.c index 7062fbb..0e2ea80 100644 --- a/mce-intel-knl.c +++ b/mce-intel-knl.c @@ -36,7 +36,7 @@ void knl_decode_model(struct ras_events *ras, struct mce_event *e) { uint64_t status = e->status; uint32_t mca = status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan = 0; + unsigned int rank0 = -1, rank1 = -1, chan = 0; switch (e->bank) { case 5: diff --git a/mce-intel-nehalem.c b/mce-intel-nehalem.c index ad4ce69..18992d1 100644 --- a/mce-intel-nehalem.c +++ b/mce-intel-nehalem.c @@ -112,9 +112,9 @@ void nehalem_decode_model(struct mce_event *e) uint64_t status = e->status; uint32_t mca = status & 0xffff; uint64_t misc = e->misc; - unsigned channel, dimm; + unsigned int channel, dimm; - if ((mca >> 11) == 1) { /* bus and interconnect QPI */ + if ((mca >> 11) == 1) { /* bus and interconnect QPI */ decode_bitfield(e, status, qpi_status); if (status & MCI_STATUS_MISCV) { decode_numfield(e, misc, qpi_numbers); @@ -143,6 +143,7 @@ void xeon75xx_decode_model(struct mce_event *e) { uint64_t status = e->status; uint32_t mca = status & 0xffff; + if (mca == 0x0001) { /* internal unspecified */ decode_bitfield(e, status, internal_error_status); decode_numfield(e, status, internal_error_numbers); diff --git a/mce-intel-p4-p6.c b/mce-intel-p4-p6.c index 5c6c3ff..2751d34 100644 --- a/mce-intel-p4-p6.c +++ b/mce-intel-p4-p6.c @@ -66,8 +66,8 @@ static struct field p6_shared_status[] = { FIELD(25, bus_queue_error_type), SBITFIELD(30, "internal BINIT"), SBITFIELD(36, "received parity error on response transaction"), - SBITFIELD(38, "timeout BINIT (ROB timeout)." - " No micro-instruction retired for some time"), + SBITFIELD(38, + "timeout BINIT (ROB timeout). No micro-instruction retired for some time"), FIELD_NULL(39), SBITFIELD(42, "bus transaction received hard error response"), SBITFIELD(43, "failure that caused IERR"), @@ -86,7 +86,7 @@ static struct field p6old_status[] = { FIELD_NULL(31), FIELD_NULL(32), SBITFIELD(35, "BINIT received from external bus"), - SBITFIELD(37, "Received hard error reponse on split transaction (Bus BINIT)"), + SBITFIELD(37, "Received hard error response on split transaction (Bus BINIT)"), {} }; @@ -109,7 +109,7 @@ static struct numfield p6old_status_numbers[] = { static struct { int value; char *str; -} p4_model []= { +} p4_model[] = { {16, "FSB address parity"}, {17, "Response hard fail"}, {18, "Response parity"}, @@ -123,7 +123,7 @@ static struct { void p4_decode_model(struct mce_event *e) { uint32_t model = e->status & 0xffff0000L; - unsigned i; + unsigned int i; for (i = 0; i < ARRAY_SIZE(p4_model); i++) { if (model & (1 << p4_model[i].value)) diff --git a/mce-intel-sb.c b/mce-intel-sb.c index e754496..385b125 100644 --- a/mce-intel-sb.c +++ b/mce-intel-sb.c @@ -82,7 +82,7 @@ void snb_decode_model(struct ras_events *ras, struct mce_event *e) { struct mce_priv *mce = ras->mce_priv; uint32_t mca = e->status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan; + unsigned int rank0 = -1, rank1 = -1, chan; switch (e->bank) { case 4: @@ -113,7 +113,7 @@ void snb_decode_model(struct ras_events *ras, struct mce_event *e) /* Ignore unless this is an corrected extended error from an iMC bank */ if (e->bank < 8 || e->bank > 11 || (e->status & MCI_STATUS_UC) || - !test_prefix(7, e->status & 0xefff)) + !test_prefix(7, e->status & 0xefff)) return; /* @@ -138,7 +138,7 @@ void snb_decode_model(struct ras_events *ras, struct mce_event *e) */ if (rank0 >= 0 && rank1 >= 0) mce_snprintf(e->mc_location, "ranks=%d and %d", - rank0, rank1); + rank0, rank1); else if (rank0 >= 0) mce_snprintf(e->mc_location, "rank=%d", rank0); else @@ -162,7 +162,7 @@ void snb_decode_model(struct ras_events *ras, struct mce_event *e) * can be converted to a DIMM number within a channel for systems with either * two or three DIMMs per channel. */ -static int failrank2dimm(unsigned failrank, int socket, int channel) +static int failrank2dimm(unsigned int failrank, int socket, int channel) { switch (failrank) { case 0: case 1: case 2: case 3: diff --git a/mce-intel-skylake-xeon.c b/mce-intel-skylake-xeon.c index 680578a..37e5e11 100644 --- a/mce-intel-skylake-xeon.c +++ b/mce-intel-skylake-xeon.c @@ -170,7 +170,7 @@ void skylake_s_decode_model(struct ras_events *ras, struct mce_event *e) { uint64_t status = e->status; uint32_t mca = status & 0xffff; - unsigned rank0 = -1, rank1 = -1, chan; + unsigned int rank0 = -1, rank1 = -1, chan; switch (e->bank) { case 4: @@ -221,7 +221,7 @@ void skylake_s_decode_model(struct ras_events *ras, struct mce_event *e) /* Ignore unless this is an corrected extended error from an iMC bank */ if (e->bank < 13 || e->bank > 18 || (status & MCI_STATUS_UC) || - !test_prefix(7, status & 0xefff)) + !test_prefix(7, status & 0xefff)) return; /* @@ -246,7 +246,7 @@ void skylake_s_decode_model(struct ras_events *ras, struct mce_event *e) */ if (rank0 != -1 && rank1 != -1) mce_snprintf(e->mc_location, "ranks=%d and %d", - rank0, rank1); + rank0, rank1); else if (rank0 != -1) mce_snprintf(e->mc_location, "rank=%d", rank0); } diff --git a/mce-intel-tulsa.c b/mce-intel-tulsa.c index e59bf06..f38d638 100644 --- a/mce-intel-tulsa.c +++ b/mce-intel-tulsa.c @@ -105,6 +105,7 @@ static void tulsa_decode_bus(struct mce_event *e, uint64_t status) static void tulsa_decode_internal(struct mce_event *e, uint64_t status) { uint32_t mca = (status >> 16) & 0xffff; + if ((mca & 0xfff0) == 0) decode_bitfield(e, mca, tls_front_status); else if ((mca & 0xf0ff) == 0) diff --git a/mce-intel.c b/mce-intel.c index 18a9072..7f48cc4 100644 --- a/mce-intel.c +++ b/mce-intel.c @@ -57,8 +57,7 @@ #define BUS_PP_MASK 0x600 /*bit 9, bit 10*/ #define BUS_PP_SHIFT 0x9 -#define MCG_TES_P (1ULL<<11) /* Yellow bit cache threshold supported */ - +#define MCG_TES_P BIT_ULL(11) /* Yellow bit cache threshold supported */ static char *TT[] = { "Instruction", @@ -76,8 +75,8 @@ static char *LL[] = { static struct { uint8_t value; - char* str; -} RRRR [] = { + char *str; +} RRRR[] = { {0, "Generic"}, {1, "Read"}, {2, "Write" }, @@ -121,7 +120,7 @@ static char *mca_msg[] = { static char *tracking_msg[] = { [1] = "green", [2] = "yellow", - [3] ="res3" + [3] = "res3" }; static const char *arstate[4] = { @@ -157,9 +156,9 @@ static void decode_memory_controller(struct mce_event *e, uint32_t status) sprintf(channel, "%u", status & 0xf); mce_snprintf(e->error_msg, "MEMORY CONTROLLER %s_CHANNEL%s_ERR", - mmm_mnemonic[(status >> 4) & 7], channel); + mmm_mnemonic[(status >> 4) & 7], channel); mce_snprintf(e->error_msg, "Transaction: %s", - mmm_desc[(status >> 4) & 7]); + mmm_desc[(status >> 4) & 7]); } static void decode_termal_bank(struct mce_event *e) @@ -207,7 +206,7 @@ static void bank_name(struct mce_event *e) static char *get_RRRR_str(uint8_t rrrr) { - unsigned i; + unsigned int i; for (i = 0; i < ARRAY_SIZE(RRRR); i++) { if (RRRR[i].value == rrrr) { @@ -220,7 +219,7 @@ static char *get_RRRR_str(uint8_t rrrr) #define decode_attr(arr, val) ({ \ char *__str; \ - if ((unsigned)(val) >= ARRAY_SIZE(arr)) \ + if ((unsigned int)(val) >= ARRAY_SIZE(arr)) \ __str = "UNKNOWN"; \ else \ __str = (arr)[val]; \ @@ -248,17 +247,17 @@ static void decode_mca(struct mce_event *e, uint64_t track, int *ismemerr) decode_attr(LL, mca & 3)); } else if (test_prefix(4, mca)) { mce_snprintf(e->mcastatus_msg, "%s TLB %s Error", - decode_attr(TT, (mca & TLB_TT_MASK) >> TLB_TT_SHIFT), - decode_attr(LL, (mca & TLB_LL_MASK) >> TLB_LL_SHIFT)); + decode_attr(TT, (mca & TLB_TT_MASK) >> TLB_TT_SHIFT), + decode_attr(LL, (mca & TLB_LL_MASK) >> TLB_LL_SHIFT)); } else if (test_prefix(8, mca)) { - unsigned typenum = (mca & CACHE_TT_MASK) >> CACHE_TT_SHIFT; - unsigned levelnum = (mca & CACHE_LL_MASK) >> CACHE_LL_SHIFT; + unsigned int typenum = (mca & CACHE_TT_MASK) >> CACHE_TT_SHIFT; + unsigned int levelnum = (mca & CACHE_LL_MASK) >> CACHE_LL_SHIFT; char *type = decode_attr(TT, typenum); char *level = decode_attr(LL, levelnum); + mce_snprintf(e->mcastatus_msg, "%s CACHE %s %s Error", type, level, - get_RRRR_str((mca & CACHE_RRRR_MASK) >> - CACHE_RRRR_SHIFT)); + get_RRRR_str((mca & CACHE_RRRR_MASK) >> CACHE_RRRR_SHIFT)); #if 0 /* FIXME: We shouldn't mix parsing with actions */ if (track == 2) @@ -313,15 +312,13 @@ static void decode_mci(struct mce_event *e, int *ismemerr) else mce_snprintf(e->mcistatus_msg, "Corrected_error"); - if (e->status & MCI_STATUS_EN) mce_snprintf(e->mcistatus_msg, "Error_enabled"); - if (e->status & MCI_STATUS_PCC) mce_snprintf(e->mcistatus_msg, "Processor_context_corrupt"); - if (e->status & (MCI_STATUS_S|MCI_STATUS_AR)) + if (e->status & (MCI_STATUS_S | MCI_STATUS_AR)) mce_snprintf(e->mcistatus_msg, "%s", arstate[(e->status >> 55) & 3]); @@ -350,14 +347,14 @@ int parse_intel_event(struct ras_events *ras, struct mce_event *e) /* Check if the error is at the memory controller */ if (((e->status & 0xffff) >> 7) == 1) { - unsigned corr_err_cnt; + unsigned int corr_err_cnt; corr_err_cnt = EXTRACT(e->status, 38, 52); mce_snprintf(e->mc_location, "n_errors=%d", corr_err_cnt); } if (test_prefix(11, (e->status & 0xffffL))) { - switch(mce->cputype) { + switch (mce->cputype) { case CPU_P6OLD: p6old_decode_model(e); break; @@ -375,7 +372,7 @@ int parse_intel_event(struct ras_events *ras, struct mce_event *e) break; } } - switch(mce->cputype) { + switch (mce->cputype) { case CPU_NEHALEM: nehalem_decode_model(e); break; @@ -447,18 +444,18 @@ static int domsr(int cpu, int msr, int bit) return -EINVAL; } } - if (pread(fd, &data, sizeof data, msr) != sizeof data) { + if (pread(fd, &data, sizeof(data), msr) != sizeof(data)) { log(ALL, LOG_ERR, "Cannot read MSR_ERROR_CONTROL from %s\n", fpath); return -EINVAL; } data |= bit; - if (pwrite(fd, &data, sizeof data, msr) != sizeof data) { + if (pwrite(fd, &data, sizeof(data), msr) != sizeof(data)) { log(ALL, LOG_ERR, "Cannot write MSR_ERROR_CONTROL to %s\n", fpath); return -EINVAL; } - if (pread(fd, &data, sizeof data, msr) != sizeof data) { + if (pread(fd, &data, sizeof(data), msr) != sizeof(data)) { log(ALL, LOG_ERR, "Cannot re-read MSR_ERROR_CONTROL from %s\n", fpath); return -EINVAL; @@ -472,7 +469,7 @@ static int domsr(int cpu, int msr, int bit) return 0; } -int set_intel_imc_log(enum cputype cputype, unsigned ncpus) +int set_intel_imc_log(enum cputype cputype, unsigned int ncpus) { int cpu, msr, bit, rc; diff --git a/non-standard-ampere.c b/non-standard-ampere.c index 21331a1..905e0c5 100644 --- a/non-standard-ampere.c +++ b/non-standard-ampere.c @@ -31,6 +31,7 @@ static const char * const disp_payload0_err_reg_name[] = { "MISC2:", "MISC3:", }; + /*PCIe AER Error Payload Type 1*/ static const char * const disp_payload1_err_reg_name[] = { "Error Type:", @@ -86,7 +87,6 @@ static const char * const err_cpm_sub_type[] = { "ARMv8 Core 1", }; - static const char * const err_mcu_sub_type[] = { "ERR0", "ERR1", @@ -155,8 +155,6 @@ static char *err_smmu_sub_type(int etype) return "unknown error"; } - - static const char * const err_pcie_aer_sub_type[] = { "Root Port", "Device", @@ -173,7 +171,6 @@ static char *err_peci_rasdp_sub_type(int etype) return "unknown error"; } - static const char * const err_ocm_sub_type[] = { "ERR0", "ERR1", @@ -327,7 +324,7 @@ static const struct amp_ras_type_info amp_payload_error_type[] = { /*get the error type name*/ static const char *oem_type_name(const struct amp_ras_type_info *info, - uint8_t type_id) + uint8_t type_id) { const struct amp_ras_type_info *type = &info[0]; @@ -350,7 +347,7 @@ static const char *oem_subtype_name(const struct amp_ras_type_info *info, if (type->id != type_id) continue; - if (type->sub == NULL) + if (!type->sub) return type->name; if (sub_type_id >= type->sub_num) return "unknown"; @@ -477,7 +474,7 @@ static void record_amp_data(struct ras_ns_ev_decoder *ev_decoder, } static int store_amp_err_data(struct ras_ns_ev_decoder *ev_decoder, - const char *name) + const char *name) { int rc; @@ -502,37 +499,37 @@ static int store_amp_err_data(struct ras_ns_ev_decoder *ev_decoder, /*save all Ampere Specific Error Payload type 0 to sqlite3 database*/ static void record_amp_payload0_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, + const char *type_str, const char *subtype_str, const struct amp_payload0_type_sec *err) { - if (ev_decoder != NULL) { + if (ev_decoder) { record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - AMP_PAYLOAD0_FIELD_TYPE, 0, type_str); + AMP_PAYLOAD0_FIELD_TYPE, 0, type_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - AMP_PAYLOAD0_FIELD_SUB_TYPE, 0, subtype_str); + AMP_PAYLOAD0_FIELD_SUB_TYPE, 0, subtype_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD0_FIELD_INS, INSTANCE(err->instance), NULL); + AMP_PAYLOAD0_FIELD_INS, INSTANCE(err->instance), NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD0_FIELD_SOCKET_NUM, + AMP_PAYLOAD0_FIELD_SOCKET_NUM, SOCKET_NUM(err->instance), NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD0_FIELD_STATUS_REG, err->err_status, NULL); + AMP_PAYLOAD0_FIELD_STATUS_REG, err->err_status, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD0_FIELD_ADDR_REG, + AMP_PAYLOAD0_FIELD_ADDR_REG, err->err_addr, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD0_FIELD_MISC0, + AMP_PAYLOAD0_FIELD_MISC0, err->err_misc_0, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD0_FIELD_MISC1, + AMP_PAYLOAD0_FIELD_MISC1, err->err_misc_1, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD0_FIELD_MISC2, + AMP_PAYLOAD0_FIELD_MISC2, err->err_misc_2, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD0_FIELD_MISC3, + AMP_PAYLOAD0_FIELD_MISC3, err->err_misc_3, NULL); store_amp_err_data(ev_decoder, "amp_payload0_event_tab"); } @@ -540,10 +537,10 @@ static void record_amp_payload0_err(struct ras_ns_ev_decoder *ev_decoder, /*save all Ampere Specific Error Payload type 1 to sqlite3 database*/ static void record_amp_payload1_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, + const char *type_str, const char *subtype_str, const struct amp_payload1_type_sec *err) { - if (ev_decoder != NULL) { + if (ev_decoder) { record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, AMP_PAYLOAD1_FIELD_TYPE, 0, type_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, @@ -590,45 +587,45 @@ static void record_amp_payload1_err(struct ras_ns_ev_decoder *ev_decoder, /*save all Ampere Specific Error Payload type 2 to sqlite3 database*/ static void record_amp_payload2_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, - const struct amp_payload2_type_sec *err) + const char *type_str, const char *subtype_str, + const struct amp_payload2_type_sec *err) { - if (ev_decoder != NULL) { + if (ev_decoder) { record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - AMP_PAYLOAD2_FIELD_TYPE, 0, type_str); + AMP_PAYLOAD2_FIELD_TYPE, 0, type_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - AMP_PAYLOAD2_FIELD_SUB_TYPE, 0, subtype_str); + AMP_PAYLOAD2_FIELD_SUB_TYPE, 0, subtype_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_INS, INSTANCE(err->instance), NULL); + AMP_PAYLOAD2_FIELD_INS, INSTANCE(err->instance), NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_SOCKET_NUM, + AMP_PAYLOAD2_FIELD_SOCKET_NUM, SOCKET_NUM(err->instance), NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_CE_REPORT_REG, + AMP_PAYLOAD2_FIELD_CE_REPORT_REG, err->ce_register, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_CE_LOACATION, + AMP_PAYLOAD2_FIELD_CE_LOACATION, err->ce_location, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_CE_ADDR, + AMP_PAYLOAD2_FIELD_CE_ADDR, err->ce_addr, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_UE_REPORT_REG, + AMP_PAYLOAD2_FIELD_UE_REPORT_REG, err->ue_register, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_UE_LOCATION, + AMP_PAYLOAD2_FIELD_UE_LOCATION, err->ue_location, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_UE_ADDR, + AMP_PAYLOAD2_FIELD_UE_ADDR, err->ue_addr, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD2_FIELD_RESERVED1, + AMP_PAYLOAD2_FIELD_RESERVED1, err->reserved1, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD2_FIELD_RESERVED2, + AMP_PAYLOAD2_FIELD_RESERVED2, err->reserved2, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD2_FIELD_RESERVED3, + AMP_PAYLOAD2_FIELD_RESERVED3, err->reserved3, NULL); store_amp_err_data(ev_decoder, "amp_payload2_event_tab"); } @@ -636,36 +633,36 @@ static void record_amp_payload2_err(struct ras_ns_ev_decoder *ev_decoder, /*save all Ampere Specific Error Payload type 3 to sqlite3 database*/ static void record_amp_payload3_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, + const char *type_str, const char *subtype_str, const struct amp_payload3_type_sec *err) { - if (ev_decoder != NULL) { + if (ev_decoder) { record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - AMP_PAYLOAD3_FIELD_TYPE, 0, type_str); + AMP_PAYLOAD3_FIELD_TYPE, 0, type_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - AMP_PAYLOAD3_FIELD_SUB_TYPE, 0, subtype_str); + AMP_PAYLOAD3_FIELD_SUB_TYPE, 0, subtype_str); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD3_FIELD_INS, INSTANCE(err->instance), NULL); + AMP_PAYLOAD3_FIELD_INS, INSTANCE(err->instance), NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD3_FIELD_SOCKET_NUM, + AMP_PAYLOAD3_FIELD_SOCKET_NUM, SOCKET_NUM(err->instance), NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT, - AMP_PAYLOAD3_FIELD_FW_SPEC_DATA0, + AMP_PAYLOAD3_FIELD_FW_SPEC_DATA0, err->fw_speci_data0, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD3_FIELD_FW_SPEC_DATA1, + AMP_PAYLOAD3_FIELD_FW_SPEC_DATA1, err->fw_speci_data1, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD3_FIELD_FW_SPEC_DATA2, + AMP_PAYLOAD3_FIELD_FW_SPEC_DATA2, err->fw_speci_data2, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD3_FIELD_FW_SPEC_DATA3, + AMP_PAYLOAD3_FIELD_FW_SPEC_DATA3, err->fw_speci_data3, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD3_FIELD_FW_SPEC_DATA4, + AMP_PAYLOAD3_FIELD_FW_SPEC_DATA4, err->fw_speci_data4, NULL); record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64, - AMP_PAYLOAD3_FIELD_FW_SPEC_DATA5, + AMP_PAYLOAD3_FIELD_FW_SPEC_DATA5, err->fw_speci_data5, NULL); store_amp_err_data(ev_decoder, "amp_payload3_event_tab"); } @@ -679,26 +676,26 @@ static void record_amp_data(struct ras_ns_ev_decoder *ev_decoder, } static void record_amp_payload0_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, - const struct amp_payload0_type_sec *err) + const char *type_str, const char *subtype_str, + const struct amp_payload0_type_sec *err) { } static void record_amp_payload1_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, - const struct amp_payload1_type_sec *err) + const char *type_str, const char *subtype_str, + const struct amp_payload1_type_sec *err) { } static void record_amp_payload2_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, - const struct amp_payload2_type_sec *err) + const char *type_str, const char *subtype_str, + const struct amp_payload2_type_sec *err) { } static void record_amp_payload3_err(struct ras_ns_ev_decoder *ev_decoder, - const char *type_str, const char *subtype_str, - const struct amp_payload3_type_sec *err) + const char *type_str, const char *subtype_str, + const struct amp_payload3_type_sec *err) { } @@ -711,7 +708,7 @@ static int store_amp_err_data(struct ras_ns_ev_decoder *ev_decoder, char *name) /*decode ampere specific error payload type 0, the CPU's data is save*/ /*to sqlite by ras-arm-handler, others are saved by this function.*/ void decode_amp_payload0_err_regs(struct ras_ns_ev_decoder *ev_decoder, - struct trace_seq *s, + struct trace_seq *s, const struct amp_payload0_type_sec *err) { char buf[AMP_PAYLOAD0_BUF_LEN]; @@ -798,8 +795,8 @@ void decode_amp_payload0_err_regs(struct ras_ns_ev_decoder *ev_decoder, /*decode ampere specific error payload type 1 and save to sqlite db*/ static void decode_amp_payload1_err_regs(struct ras_ns_ev_decoder *ev_decoder, - struct trace_seq *s, - const struct amp_payload1_type_sec *err) + struct trace_seq *s, + const struct amp_payload1_type_sec *err) { char buf[AMP_PAYLOAD0_BUF_LEN]; char *p = buf; @@ -882,8 +879,8 @@ static void decode_amp_payload1_err_regs(struct ras_ns_ev_decoder *ev_decoder, /*decode ampere specific error payload type 2 and save to sqlite db*/ static void decode_amp_payload2_err_regs(struct ras_ns_ev_decoder *ev_decoder, - struct trace_seq *s, - const struct amp_payload2_type_sec *err) + struct trace_seq *s, + const struct amp_payload2_type_sec *err) { char buf[AMP_PAYLOAD0_BUF_LEN]; char *p = buf; @@ -898,7 +895,7 @@ static void decode_amp_payload2_err_regs(struct ras_ns_ev_decoder *ev_decoder, subtype_str = err_peci_rasdp_sub_type(err->subtype); else subtype_str = oem_subtype_name(amp_payload_error_type, - TYPE(err->type), err->subtype); + TYPE(err->type), err->subtype); //display error type p += snprintf(p, end - p, " %s", disp_payload2_err_reg_name[i++]); p += snprintf(p, end - p, " %s\n", type_str); @@ -967,8 +964,8 @@ static void decode_amp_payload2_err_regs(struct ras_ns_ev_decoder *ev_decoder, /*decode ampere specific error payload type 3 and save to sqlite db*/ static void decode_amp_payload3_err_regs(struct ras_ns_ev_decoder *ev_decoder, - struct trace_seq *s, - const struct amp_payload3_type_sec *err) + struct trace_seq *s, + const struct amp_payload3_type_sec *err) { char buf[AMP_PAYLOAD0_BUF_LEN]; char *p = buf; @@ -984,7 +981,6 @@ static void decode_amp_payload3_err_regs(struct ras_ns_ev_decoder *ev_decoder, p += snprintf(p, end - p, " %s", disp_payload3_err_reg_name[i++]); p += snprintf(p, end - p, " %s\n", type_str); - //display error subtype p += snprintf(p, end - p, " %s", disp_payload3_err_reg_name[i++]); p += snprintf(p, end - p, " %s\n", subtype_str); @@ -1069,13 +1065,13 @@ static int decode_amp_oem_type_error(struct ras_events *ras, if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record, &db_tab) != SQLITE_OK) { trace_seq_printf(s, - "create sql %s fail\n", - sqlite3_table_list[payload_type]); + "create sql %s fail\n", + sqlite3_table_list[payload_type]); return -1; } } record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT, - id, 0, event->timestamp); + id, 0, event->timestamp); #endif if (payload_type == PAYLOAD_TYPE_0) { diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c index 0899812..e482a7a 100644 --- a/non-standard-hisi_hip08.c +++ b/non-standard-hisi_hip08.c @@ -453,7 +453,7 @@ static const char *oem_submodule_name(const struct hisi_module_info *info, if (module->id != module_id) continue; - if (module->sub == NULL) + if (!module->sub) return module->name; if (sub_module_id >= module->sub_num) @@ -675,7 +675,7 @@ static int decode_hip08_oem_type1_error(struct ras_events *ras, struct ras_non_standard_event *event) { const struct hisi_oem_type1_err_sec *err = - (struct hisi_oem_type1_err_sec*)event->error; + (struct hisi_oem_type1_err_sec *)event->error; if (err->val_bits == 0) { trace_seq_printf(s, "%s: no valid error information\n", diff --git a/non-standard-hisilicon.c b/non-standard-hisilicon.c index 7296d28..e9ea5df 100644 --- a/non-standard-hisilicon.c +++ b/non-standard-hisilicon.c @@ -88,10 +88,10 @@ struct hisi_event { #ifdef HAVE_SQLITE3 void record_vendor_data(struct ras_ns_ev_decoder *ev_decoder, - enum hisi_oem_data_type data_type, + enum hisi_oem_data_type data_type, int id, int64_t data, const char *text) { - if (ev_decoder->stmt_dec_record == NULL) + if (!ev_decoder->stmt_dec_record) return; switch (data_type) { @@ -111,7 +111,7 @@ int step_vendor_data_tab(struct ras_ns_ev_decoder *ev_decoder, const char *name) { int rc; - if (ev_decoder->stmt_dec_record == NULL) + if (!ev_decoder->stmt_dec_record) return 0; rc = sqlite3_step(ev_decoder->stmt_dec_record); @@ -171,13 +171,13 @@ static const struct db_table_descriptor hisi_common_section_tab = { }; #endif -static const char* soc_desc[] = { +static const char *soc_desc[] = { "Kunpeng916", "Kunpeng920", "Kunpeng930", }; -static const char* module_name[] = { +static const char *module_name[] = { "MN", "PLL", "SLLC", @@ -221,9 +221,9 @@ static const char* module_name[] = { "HBMC", }; -static const char* get_soc_desc(uint8_t soc_id) +static const char *get_soc_desc(uint8_t soc_id) { - if (soc_id >= sizeof(soc_desc)/sizeof(char *)) + if (soc_id >= sizeof(soc_desc) / sizeof(char *)) return "unknown"; return soc_desc[soc_id]; @@ -232,7 +232,7 @@ static const char* get_soc_desc(uint8_t soc_id) static void decode_module(struct ras_ns_ev_decoder *ev_decoder, struct hisi_event *event, uint8_t module_id) { - if (module_id >= sizeof(module_name)/sizeof(char *)) { + if (module_id >= sizeof(module_name) / sizeof(char *)) { HISI_SNPRINTF(event->error_msg, "module=unknown(id=%hhu) ", module_id); record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT, HISI_COMMON_FIELD_MODULE_ID, @@ -246,7 +246,7 @@ static void decode_module(struct ras_ns_ev_decoder *ev_decoder, } static void decode_hisi_common_section_hdr(struct ras_ns_ev_decoder *ev_decoder, - const struct hisi_common_error_section *err, + const struct hisi_common_error_section *err, struct hisi_event *event) { HISI_SNPRINTF(event->error_msg, "[ table_version=%hhu", err->version); diff --git a/non-standard-jaguarmicro.c b/non-standard-jaguarmicro.c index d909d7a..cb0a78d 100644 --- a/non-standard-jaguarmicro.c +++ b/non-standard-jaguarmicro.c @@ -24,7 +24,7 @@ #define JM_SNPRINTF mce_snprintf static void record_jm_data(struct ras_ns_ev_decoder *ev_decoder, - enum jm_oem_data_type data_type, + enum jm_oem_data_type data_type, int id, int64_t data, const char *text); struct jm_event { @@ -168,7 +168,6 @@ static const char * const iosub_module_desc[] = { "OTHER", }; - static const char * const scp_module_desc[] = { "SRAM", "WDT", @@ -184,6 +183,7 @@ static const char * const imu_module_desc[] = { "SRAM", "WDT", }; + /* JaguarMicro DPE sub system module definitions */ #define JM_SUBSYS_DPE_MOD_EPG 0 #define JM_SUBSYS_DPE_MOD_PIPE 1 @@ -301,7 +301,7 @@ static const char * const default_dev_desc[] = { static const char *get_jm_soc_desc(uint8_t soc_id) { - if (soc_id >= sizeof(soc_desc)/sizeof(char *)) + if (soc_id >= sizeof(soc_desc) / sizeof(char *)) return "unknown"; return soc_desc[soc_id]; @@ -309,7 +309,7 @@ static const char *get_jm_soc_desc(uint8_t soc_id) static const char *get_jm_subsystem_desc(uint8_t subsys_id) { - if (subsys_id >= sizeof(subsystem_desc)/sizeof(char *)) + if (subsys_id >= sizeof(subsystem_desc) / sizeof(char *)) return "unknown"; return subsystem_desc[subsys_id]; @@ -323,54 +323,54 @@ static const char *get_jm_module_desc(uint8_t subsys_id, uint8_t mod_id) switch (subsys_id) { case JM_SUB_SYS_CMN: module = cmn_module_desc; - tbl_size = sizeof(cmn_module_desc)/sizeof(char *); + tbl_size = sizeof(cmn_module_desc) / sizeof(char *); break; case JM_SUB_SYS_DDRH: case JM_SUB_SYS_DDRV: module = ddr_module_desc; - tbl_size = sizeof(ddr_module_desc)/sizeof(char *); + tbl_size = sizeof(ddr_module_desc) / sizeof(char *); break; case JM_SUB_SYS_GIC: module = gic_module_desc; - tbl_size = sizeof(gic_module_desc)/sizeof(char *); + tbl_size = sizeof(gic_module_desc) / sizeof(char *); break; case JM_SUB_SYS_IOSUB: module = iosub_module_desc; - tbl_size = sizeof(iosub_module_desc)/sizeof(char *); + tbl_size = sizeof(iosub_module_desc) / sizeof(char *); break; case JM_SUB_SYS_SCP: module = scp_module_desc; - tbl_size = sizeof(scp_module_desc)/sizeof(char *); + tbl_size = sizeof(scp_module_desc) / sizeof(char *); break; case JM_SUB_SYS_MCP: module = mcp_module_desc; - tbl_size = sizeof(mcp_module_desc)/sizeof(char *); + tbl_size = sizeof(mcp_module_desc) / sizeof(char *); break; case JM_SUB_SYS_IMU0: case JM_SUB_SYS_IMU1: module = imu_module_desc; - tbl_size = sizeof(imu_module_desc)/sizeof(char *); + tbl_size = sizeof(imu_module_desc) / sizeof(char *); break; case JM_SUB_SYS_DPE: module = dpe_module_desc; - tbl_size = sizeof(dpe_module_desc)/sizeof(char *); + tbl_size = sizeof(dpe_module_desc) / sizeof(char *); break; case JM_SUB_SYS_RPE: module = rpe_module_desc; - tbl_size = sizeof(rpe_module_desc)/sizeof(char *); + tbl_size = sizeof(rpe_module_desc) / sizeof(char *); break; case JM_SUB_SYS_PSUB: module = psub_module_desc; - tbl_size = sizeof(psub_module_desc)/sizeof(char *); + tbl_size = sizeof(psub_module_desc) / sizeof(char *); break; case JM_SUB_SYS_HAC: module = hac_module_desc; - tbl_size = sizeof(hac_module_desc)/sizeof(char *); + tbl_size = sizeof(hac_module_desc) / sizeof(char *); break; case JM_SUB_SYS_TCM: module = tcm_module_desc; - tbl_size = sizeof(tcm_module_desc)/sizeof(char *); + tbl_size = sizeof(tcm_module_desc) / sizeof(char *); break; default: @@ -378,7 +378,7 @@ static const char *get_jm_module_desc(uint8_t subsys_id, uint8_t mod_id) break; } - if ((module == NULL) || (mod_id >= tbl_size)) + if ((!module) || (mod_id >= tbl_size)) return "unknown"; return module[mod_id]; @@ -391,43 +391,42 @@ static const char *get_jm_submod_desc(uint8_t subsys_id, uint8_t mod_id, uint8_t if (subsys_id == JM_SUB_SYS_IOSUB && mod_id == JM_SUBSYS_IOSUB_MOD_SMMU) { sub_module = iosub_smmu_sub_desc; - tbl_size = sizeof(iosub_smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(iosub_smmu_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_IOSUB && mod_id == JM_SUBSYS_IOSUB_MOD_OTHER) { sub_module = iosub_other_sub_desc; - tbl_size = sizeof(iosub_other_sub_desc)/sizeof(char *); + tbl_size = sizeof(iosub_other_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_DPE && mod_id == JM_SUBSYS_DPE_MOD_SMMU) { sub_module = smmu_sub_desc; - tbl_size = sizeof(smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(smmu_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_RPE && mod_id == JM_SUBSYS_RPE_MOD_SMMU) { sub_module = smmu_sub_desc; - tbl_size = sizeof(smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(smmu_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_PSUB && mod_id == JM_SUBSYS_PSUB_MOD_PCIE0) { sub_module = psub_pcie0_sub_desc; - tbl_size = sizeof(psub_pcie0_sub_desc)/sizeof(char *); + tbl_size = sizeof(psub_pcie0_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_PSUB && mod_id == JM_SUBSYS_PSUB_MOD_X2RC_SMMU) { sub_module = smmu_sub_desc; - tbl_size = sizeof(smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(smmu_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_PSUB && mod_id == JM_SUBSYS_PSUB_MOD_X16RC_SMMU) { sub_module = smmu_sub_desc; - tbl_size = sizeof(smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(smmu_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_PSUB && mod_id == JM_SUBSYS_PSUB_MOD_SDMA_SMMU) { sub_module = smmu_sub_desc; - tbl_size = sizeof(smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(smmu_sub_desc) / sizeof(char *); } else if (subsys_id == JM_SUB_SYS_TCM && mod_id == JM_SUBSYS_TCM_MOD_SMMU) { sub_module = smmu_sub_desc; - tbl_size = sizeof(smmu_sub_desc)/sizeof(char *); + tbl_size = sizeof(smmu_sub_desc) / sizeof(char *); } else { sub_module = NULL; tbl_size = 0; } - if ((sub_module == NULL) || (sub_id >= tbl_size)) + if ((!sub_module) || (sub_id >= tbl_size)) return "unknown"; return sub_module[sub_id]; } - static const char *get_jm_dev_desc(uint8_t subsys_id, uint8_t mod_id, uint8_t sub_id) { if (subsys_id == JM_SUB_SYS_CSUB) @@ -440,7 +439,6 @@ static const char *get_jm_dev_desc(uint8_t subsys_id, uint8_t mod_id, uint8_t su return default_dev_desc[0]; } - #define JM_ERR_SEVERITY_NFE 0 #define JM_ERR_SEVERITY_FE 1 #define JM_ERR_SEVERITY_CE 2 @@ -461,82 +459,78 @@ static inline char *jm_err_severity(uint8_t err_sev) } static void decode_jm_common_sec_head(struct ras_ns_ev_decoder *ev_decoder, - const struct jm_common_sec_head *err, + const struct jm_common_sec_head *err, struct jm_event *event) { if (err->val_bits & BIT(JM_COMMON_VALID_SOC_ID)) { JM_SNPRINTF(event->error_msg, "[ table_version=%hhu decode_version:%hhu", - err->version, PAYLOAD_VERSION); + err->version, PAYLOAD_VERSION); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_INT, - JM_PAYLOAD_FIELD_VERSION, + JM_PAYLOAD_FIELD_VERSION, err->version, NULL); } if (err->val_bits & BIT(JM_COMMON_VALID_SOC_ID)) { JM_SNPRINTF(event->error_msg, " soc=%s", get_jm_soc_desc(err->soc_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_INT, - JM_PAYLOAD_FIELD_SOC_ID, + JM_PAYLOAD_FIELD_SOC_ID, err->soc_id, NULL); } if (err->val_bits & BIT(JM_COMMON_VALID_SUBSYSTEM_ID)) { JM_SNPRINTF(event->error_msg, " sub system=%s", - get_jm_subsystem_desc(err->subsystem_id)); + get_jm_subsystem_desc(err->subsystem_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - JM_PAYLOAD_FIELD_SUB_SYS, + JM_PAYLOAD_FIELD_SUB_SYS, 0, get_jm_subsystem_desc(err->subsystem_id)); } if (err->val_bits & BIT(JM_COMMON_VALID_MODULE_ID)) { JM_SNPRINTF(event->error_msg, " module=%s", - get_jm_module_desc(err->subsystem_id, err->module_id)); + get_jm_module_desc(err->subsystem_id, err->module_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - JM_PAYLOAD_FIELD_MODULE, + JM_PAYLOAD_FIELD_MODULE, 0, get_jm_module_desc(err->subsystem_id, err->module_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_INT, - JM_PAYLOAD_FIELD_MODULE_ID, + JM_PAYLOAD_FIELD_MODULE_ID, err->module_id, NULL); } if (err->val_bits & BIT(JM_COMMON_VALID_SUBMODULE_ID)) { JM_SNPRINTF(event->error_msg, " sub module=%s", - get_jm_submod_desc(err->subsystem_id, err->module_id, err->submodule_id)); + get_jm_submod_desc(err->subsystem_id, err->module_id, err->submodule_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - JM_PAYLOAD_FIELD_SUB_MODULE, + JM_PAYLOAD_FIELD_SUB_MODULE, 0, get_jm_submod_desc(err->subsystem_id, err->module_id, err->submodule_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_INT, - JM_PAYLOAD_FIELD_MODULE_ID, + JM_PAYLOAD_FIELD_MODULE_ID, err->submodule_id, NULL); } - if (err->val_bits & BIT(JM_COMMON_VALID_DEV_ID)) { JM_SNPRINTF(event->error_msg, " dev=%s", - get_jm_dev_desc(err->subsystem_id, err->module_id, err->submodule_id)); + get_jm_dev_desc(err->subsystem_id, err->module_id, err->submodule_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - JM_PAYLOAD_FIELD_DEV, + JM_PAYLOAD_FIELD_DEV, 0, get_jm_dev_desc(err->subsystem_id, err->module_id, err->submodule_id)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_INT, - JM_PAYLOAD_FIELD_DEV_ID, + JM_PAYLOAD_FIELD_DEV_ID, err->dev_id, NULL); - } - if (err->val_bits & BIT(JM_COMMON_VALID_ERR_TYPE)) { JM_SNPRINTF(event->error_msg, " err_type=%hu", err->err_type); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_INT, - JM_PAYLOAD_FIELD_ERR_TYPE, + JM_PAYLOAD_FIELD_ERR_TYPE, err->err_type, NULL); } - if (err->val_bits & BIT(JM_COMMON_VALID_ERR_SEVERITY)) { JM_SNPRINTF(event->error_msg, " err_severity=%s", - jm_err_severity(err->err_severity)); + jm_err_severity(err->err_severity)); record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - JM_PAYLOAD_FIELD_ERR_SEVERITY, + JM_PAYLOAD_FIELD_ERR_SEVERITY, 0, jm_err_severity(err->err_severity)); } @@ -544,7 +538,7 @@ static void decode_jm_common_sec_head(struct ras_ns_ev_decoder *ev_decoder, } static void decode_jm_common_sec_tail(struct ras_ns_ev_decoder *ev_decoder, - const struct jm_common_sec_tail *err, + const struct jm_common_sec_tail *err, struct jm_event *event, uint32_t val_bits) { if (val_bits & BIT(JM_COMMON_VALID_REG_ARRAY_SIZE) && err->reg_array_size > 0) { @@ -553,7 +547,7 @@ static void decode_jm_common_sec_tail(struct ras_ns_ev_decoder *ev_decoder, JM_SNPRINTF(event->reg_msg, "Extended Register Dump:"); for (i = 0; i < err->reg_array_size; i++) { JM_SNPRINTF(event->reg_msg, "reg%02d=0x%08x", - i, err->reg_array[i]); + i, err->reg_array[i]); } } } @@ -586,7 +580,7 @@ static const struct db_table_descriptor jm_payload0_event_tab = { /*Save data with different type into sqlite3 db*/ static void record_jm_data(struct ras_ns_ev_decoder *ev_decoder, - enum jm_oem_data_type data_type, int id, + enum jm_oem_data_type data_type, int id, int64_t data, const char *text) { switch (data_type) { @@ -598,7 +592,7 @@ static void record_jm_data(struct ras_ns_ev_decoder *ev_decoder, break; case JM_OEM_DATA_TYPE_TEXT: sqlite3_bind_text(ev_decoder->stmt_dec_record, id, text, - -1, NULL); + -1, NULL); break; default: break; @@ -606,62 +600,60 @@ static void record_jm_data(struct ras_ns_ev_decoder *ev_decoder, } static int store_jm_err_data(struct ras_ns_ev_decoder *ev_decoder, - const char *tab_name) + const char *tab_name) { int rc; rc = sqlite3_step(ev_decoder->stmt_dec_record); if (rc != SQLITE_OK && rc != SQLITE_DONE) log(TERM, LOG_ERR, - "Failed to do step on sqlite. Table = %s error = %d\n", + "Failed to do step on sqlite. Table = %s error = %d\n", tab_name, rc); rc = sqlite3_reset(ev_decoder->stmt_dec_record); if (rc != SQLITE_OK && rc != SQLITE_DONE) log(TERM, LOG_ERR, - "Failed to reset on sqlite. Table = %s error = %d\n", + "Failed to reset on sqlite. Table = %s error = %d\n", tab_name, rc); rc = sqlite3_clear_bindings(ev_decoder->stmt_dec_record); if (rc != SQLITE_OK && rc != SQLITE_DONE) log(TERM, LOG_ERR, - "Failed to clear bindings on sqlite. Table = %s error = %d\n", + "Failed to clear bindings on sqlite. Table = %s error = %d\n", tab_name, rc); return rc; } - /*save all JaguarMicro Specific Error Payload type 0 to sqlite3 database*/ static void record_jm_payload_err(struct ras_ns_ev_decoder *ev_decoder, - const char *reg_str) + const char *reg_str) { - if (ev_decoder != NULL) { + if (ev_decoder) { record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - JM_PAYLOAD_FIELD_REGS_DUMP, 0, reg_str); + JM_PAYLOAD_FIELD_REGS_DUMP, 0, reg_str); store_jm_err_data(ev_decoder, "jm_payload0_event_tab"); } } #else static void record_jm_data(struct ras_ns_ev_decoder *ev_decoder, - enum jm_oem_data_type data_type, + enum jm_oem_data_type data_type, int id, int64_t data, const char *text) { } static void record_jm_payload_err(struct ras_ns_ev_decoder *ev_decoder, - const char *reg_str) + const char *reg_str) { } #endif - /*decode JaguarMicro specific error payload type 0, the CPU's data is save*/ /*to sqlite by ras-arm-handler, others are saved by this function.*/ static void decode_jm_payload0_err_regs(struct ras_ns_ev_decoder *ev_decoder, - struct trace_seq *s, + struct trace_seq *s, const struct jm_payload0_type_sec *err) { int i = 0; @@ -781,11 +773,9 @@ static void decode_jm_payload1_err_regs(struct ras_ns_ev_decoder *ev_decoder, JM_SNPRINTF(jmevent.reg_msg, " %s", disp_payload1_err_reg_name[i++]); JM_SNPRINTF(jmevent.reg_msg, " 0x%x\n", err->errgen); - trace_seq_printf(s, "Register Dump:\n"); decode_jm_common_sec_tail(ev_decoder, common_tail, &jmevent, common_head->val_bits); - record_jm_payload_err(ev_decoder, jmevent.reg_msg); trace_seq_printf(s, "%s\n", jmevent.reg_msg); @@ -808,7 +798,6 @@ static void decode_jm_payload2_err_regs(struct ras_ns_ev_decoder *ev_decoder, decode_jm_common_sec_head(ev_decoder, common_head, &jmevent); trace_seq_printf(s, "%s\n", jmevent.error_msg); - //display ecc_1bit_error_interrupt_low JM_SNPRINTF(jmevent.reg_msg, " %s", disp_payload2_err_reg_name[i++]); JM_SNPRINTF(jmevent.reg_msg, " 0x%x; ", err->ecc_1bit_int_low); @@ -825,7 +814,6 @@ static void decode_jm_payload2_err_regs(struct ras_ns_ev_decoder *ev_decoder, JM_SNPRINTF(jmevent.reg_msg, " %s", disp_payload2_err_reg_name[i++]); JM_SNPRINTF(jmevent.reg_msg, " 0x%x\n", err->ecc_2bit_int_high); - trace_seq_printf(s, "Register Dump:\n"); decode_jm_common_sec_tail(ev_decoder, common_tail, &jmevent, common_head->val_bits); @@ -915,7 +903,6 @@ static void decode_jm_payload5_err_regs(struct ras_ns_ev_decoder *ev_decoder, trace_seq_printf(s, "%s\n", jmevent.reg_msg); } - /*decode JaguarMicro specific error payload type 6 and save to sqlite db*/ static void decode_jm_payload6_err_regs(struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, @@ -973,7 +960,7 @@ static void decode_jm_payload6_err_regs(struct ras_ns_ev_decoder *ev_decoder, /* error data decoding functions */ static int decode_jm_oem_type_error(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder, + struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, struct ras_non_standard_event *event, int payload_type) @@ -981,7 +968,7 @@ static int decode_jm_oem_type_error(struct ras_events *ras, int id = JM_PAYLOAD_FIELD_TIMESTAMP; record_jm_data(ev_decoder, JM_OEM_DATA_TYPE_TEXT, - id, 0, event->timestamp); + id, 0, event->timestamp); if (payload_type == PAYLOAD_TYPE_0) { const struct jm_payload0_type_sec *err = @@ -1013,7 +1000,7 @@ static int decode_jm_oem_type_error(struct ras_events *ras, /* error type0 data decoding functions */ static int decode_jm_oem_type0_error(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder, + struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, struct ras_non_standard_event *event) { @@ -1022,15 +1009,16 @@ static int decode_jm_oem_type0_error(struct ras_events *ras, /* error type1 data decoding functions */ static int decode_jm_oem_type1_error(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder, + struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, struct ras_non_standard_event *event) { return decode_jm_oem_type_error(ras, ev_decoder, s, event, PAYLOAD_TYPE_1); } + /* error type2 data decoding functions */ static int decode_jm_oem_type2_error(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder, + struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, struct ras_non_standard_event *event) { @@ -1039,7 +1027,7 @@ static int decode_jm_oem_type2_error(struct ras_events *ras, /* error type5 data decoding functions */ static int decode_jm_oem_type5_error(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder, + struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, struct ras_non_standard_event *event) { @@ -1048,7 +1036,7 @@ static int decode_jm_oem_type5_error(struct ras_events *ras, /* error type6 data decoding functions */ static int decode_jm_oem_type6_error(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder, + struct ras_ns_ev_decoder *ev_decoder, struct trace_seq *s, struct ras_non_standard_event *event) { @@ -1060,7 +1048,7 @@ static int add_jm_oem_type0_table(struct ras_events *ras, struct ras_ns_ev_decod #ifdef HAVE_SQLITE3 if (ras->record_events && !ev_decoder->stmt_dec_record) { if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record, - &jm_payload0_event_tab) != SQLITE_OK) { + &jm_payload0_event_tab) != SQLITE_OK) { log(TERM, LOG_WARNING, "Failed to create sql jm_payload0_event_tab\n"); return -1; } @@ -1069,7 +1057,6 @@ static int add_jm_oem_type0_table(struct ras_events *ras, struct ras_ns_ev_decod return 0; } - struct ras_ns_ev_decoder jm_ns_oem_type_decoder[] = { { .sec_type = "82d78ba3-fa14-407a-ba0e-f3ba8170013c", @@ -1106,4 +1093,3 @@ static void __attribute__((constructor)) jm_init(void) register_ns_ev_decoder(&jm_ns_oem_type_decoder[i]); } - diff --git a/non-standard-yitian.c b/non-standard-yitian.c index 4c30514..daadb95 100644 --- a/non-standard-yitian.c +++ b/non-standard-yitian.c @@ -86,25 +86,25 @@ static const struct db_table_descriptor yitian_ddr_payload_section_tab = { }; int record_yitian_ddr_reg_dump_event(struct ras_ns_ev_decoder *ev_decoder, - struct ras_yitian_ddr_payload_event *ev) + struct ras_yitian_ddr_payload_event *ev) { int rc; struct sqlite3_stmt *stmt = ev_decoder->stmt_dec_record; log(TERM, LOG_INFO, "yitian_ddr_reg_dump_event store: %p\n", stmt); - sqlite3_bind_text (stmt, 1, ev->timestamp, -1, NULL); - sqlite3_bind_int64 (stmt, 2, ev->address); - sqlite3_bind_text (stmt, 3, ev->reg_msg, -1, NULL); + sqlite3_bind_text(stmt, 1, ev->timestamp, -1, NULL); + sqlite3_bind_int64(stmt, 2, ev->address); + sqlite3_bind_text(stmt, 3, ev->reg_msg, -1, NULL); rc = sqlite3_step(stmt); if (rc != SQLITE_OK && rc != SQLITE_DONE) log(TERM, LOG_ERR, - "Failed to do yitian_ddr_reg_dump_event step on sqlite: error = %d\n", rc); + "Failed to do yitian_ddr_reg_dump_event step on sqlite: error = %d\n", rc); rc = sqlite3_reset(stmt); if (rc != SQLITE_OK && rc != SQLITE_DONE) log(TERM, LOG_ERR, - "Failed reset yitian_ddr_reg_dump_event on sqlite: error = %d\n", rc); + "Failed reset yitian_ddr_reg_dump_event on sqlite: error = %d\n", rc); log(TERM, LOG_INFO, "register inserted at db\n"); return rc; @@ -112,7 +112,7 @@ int record_yitian_ddr_reg_dump_event(struct ras_ns_ev_decoder *ev_decoder, #endif static const char *oem_type_name(const struct yitian_ras_type_info *info, - uint8_t type_id) + uint8_t type_id) { const struct yitian_ras_type_info *type = &info[0]; @@ -134,7 +134,7 @@ static const char *oem_subtype_name(const struct yitian_ras_type_info *info, if (type->id != type_id) continue; - if (type->sub == NULL) + if (!type->sub) return type->name; if (sub_type_id >= type->sub_num) return "unknown"; @@ -144,7 +144,7 @@ static const char *oem_subtype_name(const struct yitian_ras_type_info *info, } void decode_yitian_ddr_payload_err_regs(struct ras_ns_ev_decoder *ev_decoder, - struct trace_seq *s, + struct trace_seq *s, const struct yitian_ddr_payload_type_sec *err, struct ras_events *ras) { @@ -168,7 +168,7 @@ void decode_yitian_ddr_payload_err_regs(struct ras_ns_ev_decoder *ev_decoder, tm = localtime(&now); if (tm) strftime(ev.timestamp, sizeof(ev.timestamp), - "%Y-%m-%d %H:%M:%S %z", tm); + "%Y-%m-%d %H:%M:%S %z", tm); //display error type p += snprintf(p, end - p, " %s", yitian_ddr_payload_err_reg_name[i++]); p += snprintf(p, end - p, " %s,", type_str); @@ -204,18 +204,17 @@ void decode_yitian_ddr_payload_err_regs(struct ras_ns_ev_decoder *ev_decoder, #ifdef HAVE_SQLITE3 record_yitian_ddr_reg_dump_event(ev_decoder, &ev); #endif - } static int add_yitian_common_table(struct ras_events *ras, - struct ras_ns_ev_decoder *ev_decoder) + struct ras_ns_ev_decoder *ev_decoder) { #ifdef HAVE_SQLITE3 if (ras->record_events && !ev_decoder->stmt_dec_record) { if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record, - &yitian_ddr_payload_section_tab) != SQLITE_OK) { + &yitian_ddr_payload_section_tab) != SQLITE_OK) { log(TERM, LOG_WARNING, - "Failed to create sql yitian_ddr_payload_section_tab\n"); + "Failed to create sql yitian_ddr_payload_section_tab\n"); return -1; } } @@ -253,6 +252,7 @@ struct ras_ns_ev_decoder yitian_ns_oem_decoder[] = { static void __attribute__((constructor)) yitian_ns_init(void) { int i; + for (i = 0; i < ARRAY_SIZE(yitian_ns_oem_decoder); i++) register_ns_ev_decoder(&yitian_ns_oem_decoder[i]); } diff --git a/queue.c b/queue.c index 65b6fb8..a90ed6a 100644 --- a/queue.c +++ b/queue.c @@ -29,7 +29,7 @@ struct link_queue *init_queue(void) struct link_queue *queue = NULL; queue = (struct link_queue *)malloc(sizeof(struct link_queue)); - if (queue == NULL) { + if (!queue) { log(TERM, LOG_ERR, "Failed to allocate memory for queue.\n"); return NULL; } @@ -43,13 +43,13 @@ struct link_queue *init_queue(void) void clear_queue(struct link_queue *queue) { - if (queue == NULL) + if (!queue) return; struct queue_node *node = queue->head; struct queue_node *tmp = NULL; - while (node != NULL) { + while (node) { tmp = node; node = node->next; free(tmp); @@ -72,7 +72,7 @@ void free_queue(struct link_queue *queue) void push(struct link_queue *queue, struct queue_node *node) { /* there is no element in the queue */ - if (queue->head == NULL) + if (!queue->head) queue->head = node; else queue->tail->next = node; @@ -85,7 +85,7 @@ int pop(struct link_queue *queue) { struct queue_node *tmp = NULL; - if (queue == NULL || is_empty(queue)) + if (!queue || is_empty(queue)) return -1; tmp = queue->head; @@ -98,7 +98,7 @@ int pop(struct link_queue *queue) struct queue_node *front(struct link_queue *queue) { - if (queue == NULL) + if (!queue) return NULL; return queue->head; @@ -109,7 +109,7 @@ struct queue_node *node_create(time_t time, unsigned int value) struct queue_node *node = NULL; node = (struct queue_node *)malloc(sizeof(struct queue_node)); - if (node != NULL) { + if (node) { node->time = time; node->value = value; node->next = NULL; diff --git a/ras-aer-handler.c b/ras-aer-handler.c index 1aa0867..bb1a6f6 100644 --- a/ras-aer-handler.c +++ b/ras-aer-handler.c @@ -81,7 +81,7 @@ int ras_aer_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -176,7 +176,7 @@ int ras_aer_event_handler(struct trace_seq *s, sel_data[4] = (((dev & 0x1f) << 3) | (fn & 0x7)); sprintf(ipmi_add_sel, - "ipmitool raw 0x0a 0x44 0x00 0x00 0xc0 0x00 0x00 0x00 0x00 0x3a 0xcd 0x00 0xc0 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", + "ipmitool raw 0x0a 0x44 0x00 0x00 0xc0 0x00 0x00 0x00 0x00 0x3a 0xcd 0x00 0xc0 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", sel_data[0], sel_data[1], sel_data[2], sel_data[3], sel_data[4]); system(ipmi_add_sel); diff --git a/ras-arm-handler.c b/ras-arm-handler.c index bab4285..0cff842 100644 --- a/ras-arm-handler.c +++ b/ras-arm-handler.c @@ -29,7 +29,7 @@ #define BIT2 2 void display_raw_data(struct trace_seq *s, - const uint8_t *buf, + const uint8_t *buf, uint32_t datalen) { int i = 0, line_count = 0; @@ -72,7 +72,7 @@ static int count_errors(struct ras_arm_event *ev, int sev) if (ev->pei_len % err_info_size != 0) { log(TERM, LOG_ERR, - "The event data does not match to the ARM Processor Error Information Structure\n"); + "The event data does not match to the ARM Processor Error Information Structure\n"); return num; } num_pei = ev->pei_len / err_info_size; @@ -172,7 +172,7 @@ int ras_arm_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -242,7 +242,7 @@ int ras_arm_event_handler(struct trace_seq *s, #ifdef HAVE_AMP_NS_DECODE //decode ampere specific error decode_amp_payload0_err_regs(NULL, s, - (struct amp_payload0_type_sec *)ev.vsei_error); + (struct amp_payload0_type_sec *)ev.vsei_error); #else display_raw_data(s, ev.vsei_error, ev.oem_len); #endif diff --git a/ras-cpu-isolation.c b/ras-cpu-isolation.c index 90633fd..8af31e9 100644 --- a/ras-cpu-isolation.c +++ b/ras-cpu-isolation.c @@ -120,7 +120,7 @@ static int init_cpu_info(unsigned int cpus) cpu_infos = (struct cpu_info *)malloc(sizeof(*cpu_infos) * cpus); if (!cpu_infos) { log(TERM, LOG_ERR, - "Failed to allocate memory for cpu infos in %s.\n", __func__); + "Failed to allocate memory for cpu infos in %s.\n", __func__); return -1; } @@ -130,9 +130,9 @@ static int init_cpu_info(unsigned int cpus) cpu_infos[i].state = get_cpu_status(i); cpu_infos[i].ce_queue = init_queue(); - if (cpu_infos[i].ce_queue == NULL) { + if (!cpu_infos[i].ce_queue) { log(TERM, LOG_ERR, - "Failed to allocate memory for cpu ce queue in %s.\n", __func__); + "Failed to allocate memory for cpu ce queue in %s.\n", __func__); return -1; } } @@ -147,7 +147,7 @@ static void check_config(struct isolation_param *config) { if (config->value > config->limit) { log(TERM, LOG_WARNING, "Value: %lu exceed limit: %lu, set to limit\n", - config->value, config->limit); + config->value, config->limit); config->value = config->limit; } } @@ -173,7 +173,7 @@ static int parse_ul_config(struct isolation_param *config, char *env, unsigned l for (int i = 0; i < env_size; ++i) { if (isdigit(env[i])) { if (*value > ULONG_MAX / DEC_CHECK || - (*value == ULONG_MAX / DEC_CHECK && env[i] - '0' > LAST_BIT_OF_UL)) { + (*value == ULONG_MAX / DEC_CHECK && env[i] - '0' > LAST_BIT_OF_UL)) { log(TERM, LOG_ERR, "%s is out of range: %lu\n", env, ULONG_MAX); return -1; } @@ -208,7 +208,7 @@ static void init_config(struct isolation_param *config) if (parse_ul_config(config, env, &value) < 0) { log(TERM, LOG_ERR, "Invalid %s: %s! Use default value %lu.\n", - config->name, env, config->value); + config->name, env, config->value); return; } @@ -220,7 +220,7 @@ static int check_config_status(void) { char *env = getenv("CPU_ISOLATION_ENABLE"); - if (env == NULL || strcasecmp(env, "yes")) + if (!env || strcasecmp(env, "yes")) return -1; return 0; @@ -295,12 +295,12 @@ static int do_ce_handler(unsigned int cpu) cpu_infos[cpu].ce_nums -= tmp; } log(TERM, LOG_INFO, - "Current number of Corrected Errors in cpu%d in the cycle is %lu\n", + "Current number of Corrected Errors in cpu%d in the cycle is %lu\n", cpu, cpu_infos[cpu].ce_nums); if (cpu_infos[cpu].ce_nums >= threshold.value) { log(TERM, LOG_INFO, - "Corrected Errors exceeded threshold %lu, try to offline cpu%u\n", + "Corrected Errors exceeded threshold %lu, try to offline cpu%u\n", threshold.value, cpu); return do_cpu_offline(cpu); } @@ -341,7 +341,7 @@ static void record_error_info(unsigned int cpu, struct error_info *err_info) { struct queue_node *node = node_create(err_info->time, err_info->nums); - if (node == NULL) { + if (!node) { log(TERM, LOG_ERR, "Fail to allocate memory for queue node\n"); return; } @@ -366,7 +366,7 @@ void ras_record_cpu_error(struct error_info *err_info, int cpu) if (cpu >= ncores || cpu < 0) { log(TERM, LOG_ERR, - "The current cpu %d has exceed the total number of cpu:%u\n", cpu, ncores); + "The current cpu %d has exceed the total number of cpu:%u\n", cpu, ncores); return; } @@ -385,7 +385,7 @@ void ras_record_cpu_error(struct error_info *err_info, int cpu) */ if (ncores - sysconf(_SC_NPROCESSORS_ONLN) >= cpu_limit.value) { log(TERM, LOG_WARNING, - "Offlined cpus have exceeded limit: %lu, choose to do nothing\n", + "Offlined cpus have exceeded limit: %lu, choose to do nothing\n", cpu_limit.value); return; } @@ -395,11 +395,11 @@ void ras_record_cpu_error(struct error_info *err_info, int cpu) log(TERM, LOG_WARNING, "Doing nothing in the cpu%d\n", cpu); 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]); + 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 log(TERM, LOG_WARNING, "Offline cpu%d fail, the state is %s\n", - cpu, cpu_state[cpu_infos[cpu].state]); + cpu, cpu_state[cpu_infos[cpu].state]); } diff --git a/ras-cxl-handler.c b/ras-cxl-handler.c index a0b6780..16a5f76 100644 --- a/ras-cxl-handler.c +++ b/ras-cxl-handler.c @@ -83,7 +83,7 @@ static char *uuid_be(const char *uu) static const unsigned char be[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; for (i = 0; i < 16; i++) { - p += sprintf(p, "%.2x", (unsigned char) uu[be[i]]); + p += sprintf(p, "%.2x", (unsigned char)uu[be[i]]); switch (i) { case 3: case 5: @@ -99,7 +99,7 @@ static char *uuid_be(const char *uu) return uuid; } -static const char* get_cxl_type_str(const char** type_array, uint8_t num_elems, uint8_t type) +static const char *get_cxl_type_str(const char **type_array, uint8_t num_elems, uint8_t type) { if (type >= num_elems) return "Unknown"; @@ -244,7 +244,7 @@ int ras_cxl_poison_event_handler(struct trace_seq *s, if (ev.flags & CXL_POISON_FLAG_OVERFLOW) { if (tep_get_field_val(s, event, "overflow_ts", record, &val, 1) < 0) return -1; - convert_timestamp(val, ev.overflow_ts, sizeof(ev.overflow_ts)); + convert_timestamp(val, ev.overflow_ts, sizeof(ev.overflow_ts)); } else strncpy(ev.overflow_ts, "1970-01-01 00:00:00 +0000", sizeof(ev.overflow_ts)); if (trace_seq_printf(s, "overflow timestamp:%s\n", ev.overflow_ts) <= 0) @@ -491,7 +491,6 @@ enum cxl_event_log_type { static char *cxl_event_log_type_str(uint32_t log_type) { - switch (log_type) { case CXL_EVENT_TYPE_INFO: return "Informational"; @@ -701,7 +700,7 @@ int ras_cxl_generic_event_handler(struct trace_seq *s, if (trace_seq_printf(s, "\n %08x: ", i) <= 0) break; if (trace_seq_printf(s, "%02x%02x%02x%02x ", - buf[i], buf[i+1], buf[i+2], buf[i+3]) <= 0) + buf[i], buf[i + 1], buf[i + 2], buf[i + 3]) <= 0) break; } @@ -745,13 +744,13 @@ static const struct cxl_event_flags cxl_gmer_event_desc_flags[] = { #define CXL_GMER_VALID_DEVICE BIT(2) #define CXL_GMER_VALID_COMPONENT BIT(3) -static const char* cxl_gmer_mem_event_type[] = { +static const char *cxl_gmer_mem_event_type[] = { "ECC Error", "Invalid Address", "Data Path Error", }; -static const char* cxl_gmer_trans_type[] = { +static const char *cxl_gmer_trans_type[] = { "Unknown", "Host Read", "Host Write", @@ -801,7 +800,7 @@ int ras_cxl_general_media_event_handler(struct trace_seq *s, return -1; ev.type = val; if (trace_seq_printf(s, "type:%s ", get_cxl_type_str(cxl_gmer_mem_event_type, - ARRAY_SIZE(cxl_gmer_mem_event_type), ev.type)) <= 0) + ARRAY_SIZE(cxl_gmer_mem_event_type), ev.type)) <= 0) return -1; if (tep_get_field_val(s, event, "transaction_type", record, &val, 1) < 0) @@ -920,7 +919,7 @@ int ras_cxl_dram_event_handler(struct trace_seq *s, return -1; ev.type = val; if (trace_seq_printf(s, "type:%s ", get_cxl_type_str(cxl_gmer_mem_event_type, - ARRAY_SIZE(cxl_gmer_mem_event_type), ev.type)) <= 0) + ARRAY_SIZE(cxl_gmer_mem_event_type), ev.type)) <= 0) return -1; if (tep_get_field_val(s, event, "transaction_type", record, &val, 1) < 0) @@ -1022,7 +1021,7 @@ int ras_cxl_dram_event_handler(struct trace_seq *s, * * CXL res 3.0 section 8.2.9.2.1.3; Table 8-45 */ -static const char* cxl_dev_evt_type[] = { +static const char *cxl_dev_evt_type[] = { "Health Status Change", "Media Status Change", "Life Used Change", @@ -1046,7 +1045,7 @@ static const struct cxl_event_flags cxl_health_status[] = { { .bit = CXL_DHI_HS_HW_REPLACEMENT_NEEDED, .flag = "REPLACEMENT_NEEDED" }, }; -static const char* cxl_media_status[] = { +static const char *cxl_media_status[] = { "Normal", "Not Ready", "Write Persistency Lost", @@ -1059,13 +1058,13 @@ static const char* cxl_media_status[] = { "All Data Loss Imminent", }; -static const char* cxl_two_bit_status[] = { +static const char *cxl_two_bit_status[] = { "Normal", "Warning", "Critical", }; -static const char* cxl_one_bit_status[] = { +static const char *cxl_one_bit_status[] = { "Normal", "Warning", }; @@ -1091,7 +1090,7 @@ int ras_cxl_memory_module_event_handler(struct trace_seq *s, return -1; ev.event_type = val; if (trace_seq_printf(s, "event_type:%s ", get_cxl_type_str(cxl_dev_evt_type, - ARRAY_SIZE(cxl_dev_evt_type), ev.event_type)) <= 0) + ARRAY_SIZE(cxl_dev_evt_type), ev.event_type)) <= 0) return -1; if (tep_get_field_val(s, event, "health_status", record, &val, 1) < 0) @@ -1107,26 +1106,26 @@ int ras_cxl_memory_module_event_handler(struct trace_seq *s, return -1; ev.media_status = val; if (trace_seq_printf(s, "media_status:%s ", get_cxl_type_str(cxl_media_status, - ARRAY_SIZE(cxl_media_status), ev.media_status)) <= 0) + ARRAY_SIZE(cxl_media_status), ev.media_status)) <= 0) return -1; if (tep_get_field_val(s, event, "add_status", record, &val, 1) < 0) return -1; ev.add_status = val; if (trace_seq_printf(s, "as_life_used:%s ", get_cxl_type_str(cxl_two_bit_status, - ARRAY_SIZE(cxl_two_bit_status), + ARRAY_SIZE(cxl_two_bit_status), CXL_DHI_AS_LIFE_USED(ev.add_status))) <= 0) return -1; if (trace_seq_printf(s, "as_dev_temp:%s ", get_cxl_type_str(cxl_two_bit_status, - ARRAY_SIZE(cxl_two_bit_status), + ARRAY_SIZE(cxl_two_bit_status), CXL_DHI_AS_DEV_TEMP(ev.add_status))) <= 0) return -1; if (trace_seq_printf(s, "as_cor_vol_err_cnt:%s ", get_cxl_type_str(cxl_one_bit_status, - ARRAY_SIZE(cxl_one_bit_status), + ARRAY_SIZE(cxl_one_bit_status), CXL_DHI_AS_COR_VOL_ERR_CNT(ev.add_status))) <= 0) return -1; if (trace_seq_printf(s, "as_cor_per_err_cnt:%s ", get_cxl_type_str(cxl_one_bit_status, - ARRAY_SIZE(cxl_one_bit_status), + ARRAY_SIZE(cxl_one_bit_status), CXL_DHI_AS_COR_PER_ERR_CNT(ev.add_status))) <= 0) return -1; diff --git a/ras-devlink-handler.c b/ras-devlink-handler.c index d68f9b0..dcecc6d 100644 --- a/ras-devlink-handler.c +++ b/ras-devlink-handler.c @@ -38,7 +38,7 @@ int ras_net_xmit_timeout_handler(struct trace_seq *s, struct devlink_event ev; if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -78,7 +78,6 @@ int ras_net_xmit_timeout_handler(struct trace_seq *s, free(ev.msg); return 0; - } int ras_devlink_event_handler(struct trace_seq *s, @@ -104,7 +103,7 @@ int ras_devlink_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -125,7 +124,7 @@ int ras_devlink_event_handler(struct trace_seq *s, return -1; ev.driver_name = tep_get_field_raw(s, event, "driver_name", - record, &len, 1); + record, &len, 1); if (!ev.driver_name) return -1; diff --git a/ras-diskerror-handler.c b/ras-diskerror-handler.c index 638cb4d..02bb5a7 100644 --- a/ras-diskerror-handler.c +++ b/ras-diskerror-handler.c @@ -30,7 +30,6 @@ #include "ras-logger.h" #include "ras-report.h" - static const struct { int error; const char *name; @@ -82,7 +81,7 @@ int ras_diskerror_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); diff --git a/ras-events.c b/ras-events.c index f92c6a9..a097238 100644 --- a/ras-events.c +++ b/ras-events.c @@ -60,7 +60,7 @@ #define ENDIAN KBUFFER_ENDIAN_BIG #endif -extern char* choices_disable; +extern char *choices_disable; static int get_debugfs_dir(char *tracing_dir, size_t len) { @@ -68,7 +68,7 @@ static int get_debugfs_dir(char *tracing_dir, size_t len) char line[MAX_PATH + 1 + 256]; char *p, *type, *dir; - fp = fopen("/proc/mounts","r"); + fp = fopen("/proc/mounts", "r"); if (!fp) { log(ALL, LOG_INFO, "Can't open /proc/mounts"); return errno; @@ -96,7 +96,7 @@ static int get_debugfs_dir(char *tracing_dir, size_t len) tracing_dir[len - 1] = '\0'; return 0; } - } while(1); + } while (1); fclose(fp); log(ALL, LOG_INFO, "Can't find debugfs\n"); @@ -141,7 +141,7 @@ static int get_tracing_dir(struct ras_events *ras) strcat(ras->tracing, "/tracing"); if (has_instances) { strcat(ras->tracing, "/instances/" TOOL_NAME); - rc = mkdir(ras->tracing, S_IRWXU); + rc = mkdir(ras->tracing, 0700); if (rc < 0 && errno != EEXIST) { log(ALL, LOG_INFO, "Unable to create " TOOL_NAME " instance at %s\n", @@ -152,13 +152,14 @@ static int get_tracing_dir(struct ras_events *ras) return 0; } -static int is_disabled_event(char *group, char *event) { +static int is_disabled_event(char *group, char *event) +{ char ras_event_name[MAX_PATH + 1]; snprintf(ras_event_name, sizeof(ras_event_name), "%s:%s", - group, event); + group, event); - if (choices_disable != NULL && 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; @@ -172,6 +173,7 @@ static int __toggle_ras_mc_event(struct ras_events *ras, { int fd, rc; char fname[MAX_PATH + 1]; + enable = is_disabled_event(group, event) ? 0 : 1; snprintf(fname, sizeof(fname), "%s%s:%s\n", @@ -185,7 +187,7 @@ static int __toggle_ras_mc_event(struct ras_events *ras, return errno; } - rc = write(fd, fname,strlen(fname)); + rc = write(fd, fname, strlen(fname)); if (rc < 0) { log(ALL, LOG_WARNING, "Can't write to set_event\n"); close(fd); @@ -248,7 +250,7 @@ int toggle_ras_mc_event(int enable) #endif #ifdef HAVE_DISKERROR -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) rc |= __toggle_ras_mc_event(ras, "block", "block_rq_error", enable); #else rc |= __toggle_ras_mc_event(ras, "block", "block_rq_complete", enable); @@ -275,7 +277,7 @@ free_ras: return rc; } -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) /* * Set kernel filter. libtrace doesn't provide an API for setting filters * in kernel, we have to implement it here. @@ -293,7 +295,7 @@ static int filter_ras_mc_event(struct ras_events *ras, char *group, char *event, return errno; } - rc = write(fd, filter_str ,strlen(filter_str)); + rc = write(fd, filter_str, strlen(filter_str)); if (rc < 0) { log(ALL, LOG_WARNING, "Can't write to filter file\n"); close(fd); @@ -331,7 +333,6 @@ static int get_pagesize(struct ras_events *ras, struct tep_handle *pevent) error: close(fd); return page_size; - } static void parse_ras_data(struct pthread_data *pdata, struct kbuffer *kbuf, @@ -354,9 +355,9 @@ static void parse_ras_data(struct pthread_data *pdata, struct kbuffer *kbuf, trace_seq_init(&s); tep_print_event(pdata->ras->pevent, &s, &record, "%16s-%-5d [%03d] %s %6.1000d %s %s", - TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU, - TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, - TEP_PRINT_INFO); + TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU, + TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, + TEP_PRINT_INFO); trace_seq_do_printf(&s); printf("\n"); fflush(stdout); @@ -416,7 +417,7 @@ static int set_buffer_percent(struct ras_events *ras, int percent) } static int read_ras_event_all_cpus(struct pthread_data *pdata, - unsigned n_cpus) + unsigned int n_cpus) { ssize_t size; unsigned long long time_stamp; @@ -467,7 +468,7 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata, /* FIXME: use select to open for all CPUs */ snprintf(pipe_raw, sizeof(pipe_raw), - "per_cpu/cpu%d/trace_pipe_raw", i); + "per_cpu/cpu%d/trace_pipe_raw", i); fds[i].fd = open_trace(pdata[0].ras, pipe_raw, O_RDONLY); if (fds[i].fd < 0) { @@ -517,7 +518,7 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata, fdsiginfo.ssi_signo == SIGTERM || fdsiginfo.ssi_signo == SIGHUP || fdsiginfo.ssi_signo == SIGQUIT) { - log(TERM, LOG_INFO, "Recevied signal=%d\n", + log(TERM, LOG_INFO, "Received signal=%d\n", fdsiginfo.ssi_signo); goto cleanup; } else { @@ -722,7 +723,7 @@ static int select_tracing_timestamp(struct ras_events *ras) int fd, rc; time_t uptime, now; size_t size; - unsigned j1; + unsigned int j1; char buf[4096]; /* Check if uptime is supported (kernel 3.10-rc1 or upper) */ @@ -781,12 +782,12 @@ static int select_tracing_timestamp(struct ras_events *ras) } static int add_event_handler(struct ras_events *ras, struct tep_handle *pevent, - unsigned page_size, char *group, char *event, + unsigned int page_size, char *group, char *event, tep_event_handler_func func, char *filter_str, int id) { int fd, size, rc; char *page, fname[MAX_PATH + 1]; - struct tep_event_filter * filter = NULL; + struct tep_event_filter *filter = NULL; snprintf(fname, sizeof(fname), "events/%s/%s/format", group, event); @@ -856,7 +857,7 @@ static int add_event_handler(struct ras_events *ras, struct tep_handle *pevent, if (is_disabled_event(group, event)) { log(ALL, LOG_INFO, "Disabled %s:%s tracing from config\n", - group, event); + group, event); return -EINVAL; } @@ -879,7 +880,7 @@ int handle_ras_events(int record_events) { int rc, page_size, i; int num_events = 0; - unsigned cpus; + unsigned int cpus; struct tep_handle *pevent = NULL; struct pthread_data *data = NULL; struct ras_events *ras = NULL; @@ -1013,7 +1014,7 @@ int handle_ras_events(int record_events) #endif #ifdef HAVE_DISKERROR -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) rc = add_event_handler(ras, pevent, page_size, "block", "block_rq_error", ras_diskerror_event_handler, NULL, DISKERROR_EVENT); @@ -1124,7 +1125,6 @@ int handle_ras_events(int record_events) if (!data) goto err; - for (i = 0; i < cpus; i++) { data[i].ras = ras; data[i].cpu = i; @@ -1139,14 +1139,14 @@ int handle_ras_events(int record_events) } log(SYSLOG, LOG_INFO, - "Opening one thread per cpu (%d threads)\n", cpus); + "Opening one thread per cpu (%d threads)\n", cpus); for (i = 0; i < cpus; i++) { rc = pthread_create(&data[i].thread, NULL, - handle_ras_events_cpu, + handle_ras_events_cpu, (void *)&data[i]); if (rc) { log(SYSLOG, LOG_INFO, - "Failed to create thread for cpu %d. Aborting.\n", + "Failed to create thread for cpu %d. Aborting.\n", i); while (--i) pthread_cancel(data[i].thread); diff --git a/ras-extlog-handler.c b/ras-extlog-handler.c index 49d01e2..e9e79f5 100644 --- a/ras-extlog-handler.c +++ b/ras-extlog-handler.c @@ -139,7 +139,7 @@ static char *err_cper_data(const char *c) p += sprintf(p, "card_handle: %d ", cpd->mem_array_handle); if (cpd->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) p += sprintf(p, "module_handle: %d ", cpd->mem_dev_handle); - p += sprintf(p-1, ")"); + p += sprintf(p - 1, ")"); return buf; } @@ -149,10 +149,10 @@ static char *uuid_le(const char *uu) static char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; char *p = uuid; int i; - static const unsigned char le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; + static const unsigned char le[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}; for (i = 0; i < 16; i++) { - p += sprintf(p, "%.2x", (unsigned char) uu[le[i]]); + p += sprintf(p, "%.2x", (unsigned char)uu[le[i]]); switch (i) { case 3: case 5: @@ -168,14 +168,13 @@ static char *uuid_le(const char *uu) return uuid; } - static void report_extlog_mem_event(struct ras_events *ras, struct tep_record *record, struct trace_seq *s, struct ras_extlog_event *ev) { trace_seq_printf(s, "%d %s error: %s physical addr: 0x%llx mask: 0x%llx%s %s %s", - ev->error_seq, err_severity(ev->severity), + ev->error_seq, err_severity(ev->severity), err_type(ev->etype), ev->address, err_mask(ev->pa_mask_lsb), err_cper_data(ev->cper_data), @@ -204,7 +203,7 @@ int ras_extlog_mem_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); diff --git a/ras-mc-handler.c b/ras-mc-handler.c index 1be9e7e..d93ba57 100644 --- a/ras-mc-handler.c +++ b/ras-mc-handler.c @@ -48,7 +48,7 @@ int ras_mc_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -121,22 +121,22 @@ int ras_mc_event_handler(struct trace_seq *s, if (tep_get_field_val(s, event, "top_layer", record, &val, 1) < 0) goto parse_error; parsed_fields++; - ev.top_layer = (signed char) val; + ev.top_layer = (signed char)val; if (tep_get_field_val(s, event, "middle_layer", record, &val, 1) < 0) goto parse_error; parsed_fields++; - ev.middle_layer = (signed char) val; + ev.middle_layer = (signed char)val; if (tep_get_field_val(s, event, "lower_layer", record, &val, 1) < 0) goto parse_error; parsed_fields++; - ev.lower_layer = (signed char) val; + ev.lower_layer = (signed char)val; if (ev.top_layer >= 0 || ev.middle_layer >= 0 || ev.lower_layer >= 0) { if (ev.lower_layer >= 0) trace_seq_printf(s, " location: %d:%d:%d", - ev.top_layer, ev.middle_layer, ev.lower_layer); + ev.top_layer, ev.middle_layer, ev.lower_layer); else if (ev.middle_layer >= 0) trace_seq_printf(s, " location: %d:%d", ev.top_layer, ev.middle_layer); @@ -159,7 +159,6 @@ int ras_mc_event_handler(struct trace_seq *s, ev.grain = val; trace_seq_printf(s, " grain: %lld", ev.grain); - if (tep_get_field_val(s, event, "syndrome", record, &val, 1) < 0) goto parse_error; parsed_fields++; diff --git a/ras-mce-handler.c b/ras-mce-handler.c index 410541e..93568e3 100644 --- a/ras-mce-handler.c +++ b/ras-mce-handler.c @@ -114,11 +114,11 @@ static enum cputype select_intel_cputype(struct mce_priv *mce) else if (mce->model == 0x6a) return CPU_ICELAKE_XEON; else if (mce->model == 0x6c) - return CPU_ICELAKE_DE; + return CPU_ICELAKE_DE; else if (mce->model == 0x86) - return CPU_TREMONT_D; + return CPU_TREMONT_D; else if (mce->model == 0x8f) - return CPU_SAPPHIRERAPIDS; + return CPU_SAPPHIRERAPIDS; else if (mce->model == 0xcf) return CPU_EMERALDRAPIDS; @@ -161,7 +161,7 @@ static int detect_cpu(struct mce_priv *mce) mce->mhz = 0; mce->vendor[0] = '\0'; - f = fopen("/proc/cpuinfo","r"); + f = fopen("/proc/cpuinfo", "r"); if (!f) { log(ALL, LOG_INFO, "Can't open /proc/cpuinfo\n"); return errno; @@ -169,7 +169,7 @@ static int detect_cpu(struct mce_priv *mce) while (seen != CPU_ALL && getdelim(&line, &linelen, '\n', f) > 0) { if (sscanf(line, "vendor_id : %63[^\n]", - (char *)&mce->vendor) == 1) + (char *)&mce->vendor) == 1) seen |= CPU_VENDOR; else if (sscanf(line, "cpu family : %d", &mce->family) == 1) seen |= CPU_FAMILY; @@ -189,7 +189,7 @@ static int detect_cpu(struct mce_priv *mce) if (seen != CPU_ALL) { log(ALL, LOG_INFO, "Can't parse /proc/cpuinfo: missing%s%s%s%s%s\n", - (seen & CPU_VENDOR) ? "" : " [vendor_id]", + (seen & CPU_VENDOR) ? "" : " [vendor_id]", (seen & CPU_FAMILY) ? "" : " [cpu family]", (seen & CPU_MODEL) ? "" : " [model]", (seen & CPU_MHZ) ? "" : " [cpu MHz]", @@ -215,12 +215,12 @@ static int detect_cpu(struct mce_priv *mce) ret = EINVAL; } goto ret; - } else if (!strcmp(mce->vendor,"HygonGenuine")) { + } else if (!strcmp(mce->vendor, "HygonGenuine")) { if (mce->family == 24) { mce->cputype = CPU_DHYANA; } goto ret; - } else if (!strcmp(mce->vendor,"GenuineIntel")) { + } else if (!strcmp(mce->vendor, "GenuineIntel")) { mce->cputype = select_intel_cputype(mce); } else { ret = EINVAL; @@ -233,7 +233,7 @@ ret: return ret; } -int register_mce_handler(struct ras_events *ras, unsigned ncpus) +int register_mce_handler(struct ras_events *ras, unsigned int ncpus) { int rc; struct mce_priv *mce; @@ -249,8 +249,8 @@ int register_mce_handler(struct ras_events *ras, unsigned ncpus) rc = detect_cpu(mce); if (rc) { if (mce->processor_flags) - free (mce->processor_flags); - free (ras->mce_priv); + free(mce->processor_flags); + free(ras->mce_priv); ras->mce_priv = NULL; return (rc); } @@ -290,7 +290,7 @@ static void report_mce_event(struct ras_events *ras, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -378,13 +378,13 @@ static void report_mce_event(struct ras_events *ras, if (strlen(e->frutext)) { trace_seq_printf(s, ", FRU Text= %s", e->frutext); trace_seq_printf(s, ", Vendor Data= "); - for (int i = 2; i < e->vdata_len/8; i++) { + for (int i = 2; i < e->vdata_len / 8; i++) { trace_seq_printf(s, "0x%lx", e->vdata[i]); trace_seq_printf(s, " "); } } else { trace_seq_printf(s, ", Vendor Data= "); - for (int i = 0; i < e->vdata_len/8; i ++) { + for (int i = 0; i < e->vdata_len / 8; i++) { trace_seq_printf(s, "0x%lx", e->vdata[i]); trace_seq_printf(s, " "); } @@ -477,7 +477,7 @@ int ras_offline_mce_event(struct ras_mc_offline_event *event) mce->ipid = event->ipid; if (!mce->ipid || !mce->status) { log(TERM, LOG_ERR, "%s MSR required.\n", - mce->ipid ? "Status" : "Ipid"); + mce->ipid ? "Status" : "Ipid"); rc = -EINVAL; goto free_mce; } diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c index c74541f..97e8840 100644 --- a/ras-memory-failure-handler.c +++ b/ras-memory-failure-handler.c @@ -118,7 +118,6 @@ static const char *get_action_result(int result) return "unknown"; } - int ras_memory_failure_event_handler(struct trace_seq *s, struct tep_record *record, struct tep_event *event, void *context) @@ -139,7 +138,7 @@ int ras_memory_failure_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); diff --git a/ras-non-standard-handler.c b/ras-non-standard-handler.c index 9bb9e2f..f58e6a2 100644 --- a/ras-non-standard-handler.c +++ b/ras-non-standard-handler.c @@ -24,8 +24,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]); +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]); } static char *uuid_le(const char *uu) @@ -33,10 +34,10 @@ static char *uuid_le(const char *uu) static char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; char *p = uuid; int i; - static const unsigned char le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; + static const unsigned char le[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}; for (i = 0; i < 16; i++) { - p += sprintf(p, "%.2x", (unsigned char) uu[le[i]]); + p += sprintf(p, "%.2x", (unsigned char)uu[le[i]]); switch (i) { case 3: case 5: @@ -167,7 +168,7 @@ int ras_non_standard_event_handler(struct trace_seq *s, */ if (ras->use_uptime) - now = record->ts/user_hz + ras->uptime_diff; + now = record->ts / user_hz + ras->uptime_diff; else now = time(NULL); @@ -197,12 +198,12 @@ int ras_non_standard_event_handler(struct trace_seq *s, ev.sec_type = tep_get_field_raw(s, event, "sec_type", record, &len, 1); - if(!ev.sec_type) + if (!ev.sec_type) return -1; if (strcmp(uuid_le(ev.sec_type), "e8ed898d-df16-43cc-8ecc-54f060ef157f") == 0) trace_seq_printf(s, "\n section type: %s", - "Ampere Specific Error\n"); + "Ampere Specific Error\n"); else trace_seq_printf(s, " section type: %s", uuid_le(ev.sec_type)); @@ -219,7 +220,7 @@ int ras_non_standard_event_handler(struct trace_seq *s, trace_seq_printf(s, " length: %d", ev.length); ev.error = tep_get_field_raw(s, event, "buf", record, &len, 1); - if(!ev.error) + if (!ev.error) return -1; if (!find_ns_ev_decoder(ev.sec_type, &ns_ev_decoder)) { diff --git a/ras-page-isolation.c b/ras-page-isolation.c index caa8c31..89f8c15 100644 --- a/ras-page-isolation.c +++ b/ras-page-isolation.c @@ -116,7 +116,7 @@ static void parse_isolation_env(struct isolation *config) int unit_matched = 0; unsigned long value, tmp; - /* check if env is vaild */ + /* check if env is valid */ if (env && strlen(env)) { /* All the character before unit must be digit */ for (i = 0; i < strlen(env) - 1; i++) { @@ -125,7 +125,7 @@ static void parse_isolation_env(struct isolation *config) } if (sscanf(env, "%lu", &value) < 1 || !value) goto parse; - /* check if the unit is vaild */ + /* check if the unit is valid */ unit = env + strlen(env) - 1; /* no unit, all the character are value character */ if (isdigit(*unit)) { @@ -151,7 +151,7 @@ parse: config->unit = unit; } else { log(TERM, LOG_INFO, "Improper %s, set to default %s.\n", - config->name, config->env); + config->name, config->env); } /* if env value string is greater than ulong_max, truncate the last digit */ @@ -177,10 +177,11 @@ static void parse_env_string(struct isolation *config, char *str, unsigned int s if (config->overflow) { /* when overflow, use basic unit */ - for (i = 0; config->units[i].name; i++) ; - snprintf(str, size, "%lu%s", config->val, config->units[i-1].name); + for (i = 0; config->units[i].name; i++) + ; + snprintf(str, size, "%lu%s", config->val, config->units[i - 1].name); log(TERM, LOG_INFO, "%s is set overflow(%s), truncate it\n", - config->name, config->env); + config->name, config->env); } else { snprintf(str, size, "%s%s", config->env, config->unit); } @@ -202,7 +203,7 @@ static void page_isolation_init(void) parse_env_string(&threshold, threshold_string, sizeof(threshold_string)); parse_env_string(&cycle, cycle_string, sizeof(cycle_string)); log(TERM, LOG_INFO, "Threshold of memory Corrected Errors is %s / %s\n", - threshold_string, cycle_string); + threshold_string, cycle_string); } void ras_page_account_init(void) @@ -239,7 +240,7 @@ static void page_offline(struct page_record *pr) /* Offlining page is not required */ if (offline <= OFFLINE_ACCOUNT) { log(TERM, LOG_INFO, "PAGE_CE_ACTION=%s, ignore to offline page at %#llx\n", - offline_choice[offline].name, addr); + offline_choice[offline].name, addr); return; } @@ -264,7 +265,7 @@ static void page_offline(struct page_record *pr) addr, page_state[pr->offlined]); } -static void page_record(struct page_record *pr, unsigned count, time_t time) +static void page_record(struct page_record *pr, unsigned int count, time_t time) { unsigned long period = time - pr->start; unsigned long tolerate; @@ -328,7 +329,7 @@ static struct page_record *page_lookup_insert(unsigned long long addr) return find; } -void ras_record_page_error(unsigned long long addr, unsigned count, time_t time) +void ras_record_page_error(unsigned long long addr, unsigned int count, time_t time) { struct page_record *pr = NULL; diff --git a/ras-record.c b/ras-record.c index 6b050bb..f3ffafb 100644 --- a/ras-record.c +++ b/ras-record.c @@ -42,20 +42,20 @@ */ static const struct db_fields mc_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="err_count", .type="INTEGER" }, - { .name="err_type", .type="TEXT" }, - { .name="err_msg", .type="TEXT" }, - { .name="label", .type="TEXT" }, - { .name="mc", .type="INTEGER" }, - { .name="top_layer", .type="INTEGER" }, - { .name="middle_layer", .type="INTEGER" }, - { .name="lower_layer", .type="INTEGER" }, - { .name="address", .type="INTEGER" }, - { .name="grain", .type="INTEGER" }, - { .name="syndrome", .type="INTEGER" }, - { .name="driver_detail", .type="TEXT" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "err_count", .type = "INTEGER" }, + { .name = "err_type", .type = "TEXT" }, + { .name = "err_msg", .type = "TEXT" }, + { .name = "label", .type = "TEXT" }, + { .name = "mc", .type = "INTEGER" }, + { .name = "top_layer", .type = "INTEGER" }, + { .name = "middle_layer", .type = "INTEGER" }, + { .name = "lower_layer", .type = "INTEGER" }, + { .name = "address", .type = "INTEGER" }, + { .name = "grain", .type = "INTEGER" }, + { .name = "syndrome", .type = "INTEGER" }, + { .name = "driver_detail", .type = "TEXT" }, }; static const struct db_table_descriptor mc_event_tab = { @@ -82,9 +82,9 @@ int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev) sqlite3_bind_int (priv->stmt_mc_event, 7, ev->top_layer); sqlite3_bind_int (priv->stmt_mc_event, 8, ev->middle_layer); sqlite3_bind_int (priv->stmt_mc_event, 9, ev->lower_layer); - sqlite3_bind_int64 (priv->stmt_mc_event, 10, ev->address); - sqlite3_bind_int64 (priv->stmt_mc_event, 11, ev->grain); - sqlite3_bind_int64 (priv->stmt_mc_event, 12, ev->syndrome); + sqlite3_bind_int64(priv->stmt_mc_event, 10, ev->address); + sqlite3_bind_int64(priv->stmt_mc_event, 11, ev->grain); + sqlite3_bind_int64(priv->stmt_mc_event, 12, ev->syndrome); sqlite3_bind_text(priv->stmt_mc_event, 13, ev->driver_detail, -1, NULL); rc = sqlite3_step(priv->stmt_mc_event); if (rc != SQLITE_OK && rc != SQLITE_DONE) @@ -106,11 +106,11 @@ int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev) #ifdef HAVE_AER static const struct db_fields aer_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="dev_name", .type="TEXT" }, - { .name="err_type", .type="TEXT" }, - { .name="err_msg", .type="TEXT" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "dev_name", .type = "TEXT" }, + { .name = "err_type", .type = "TEXT" }, + { .name = "err_msg", .type = "TEXT" }, }; static const struct db_table_descriptor aer_event_tab = { @@ -154,13 +154,13 @@ int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev) #ifdef HAVE_NON_STANDARD static const struct db_fields non_standard_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="sec_type", .type="BLOB" }, - { .name="fru_id", .type="BLOB" }, - { .name="fru_text", .type="TEXT" }, - { .name="severity", .type="TEXT" }, - { .name="error", .type="BLOB" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "sec_type", .type = "BLOB" }, + { .name = "fru_id", .type = "BLOB" }, + { .name = "fru_text", .type = "TEXT" }, + { .name = "severity", .type = "TEXT" }, + { .name = "error", .type = "BLOB" }, }; static const struct db_table_descriptor non_standard_event_tab = { @@ -178,12 +178,12 @@ int ras_store_non_standard_record(struct ras_events *ras, struct ras_non_standar return 0; log(TERM, LOG_INFO, "non_standard_event store: %p\n", priv->stmt_non_standard_record); - sqlite3_bind_text (priv->stmt_non_standard_record, 1, ev->timestamp, -1, NULL); - sqlite3_bind_blob (priv->stmt_non_standard_record, 2, ev->sec_type, -1, NULL); - sqlite3_bind_blob (priv->stmt_non_standard_record, 3, ev->fru_id, 16, NULL); - sqlite3_bind_text (priv->stmt_non_standard_record, 4, ev->fru_text, -1, NULL); - sqlite3_bind_text (priv->stmt_non_standard_record, 5, ev->severity, -1, NULL); - sqlite3_bind_blob (priv->stmt_non_standard_record, 6, ev->error, ev->length, NULL); + sqlite3_bind_text(priv->stmt_non_standard_record, 1, ev->timestamp, -1, NULL); + sqlite3_bind_blob(priv->stmt_non_standard_record, 2, ev->sec_type, -1, NULL); + sqlite3_bind_blob(priv->stmt_non_standard_record, 3, ev->fru_id, 16, NULL); + sqlite3_bind_text(priv->stmt_non_standard_record, 4, ev->fru_text, -1, NULL); + sqlite3_bind_text(priv->stmt_non_standard_record, 5, ev->severity, -1, NULL); + sqlite3_bind_blob(priv->stmt_non_standard_record, 6, ev->error, ev->length, NULL); rc = sqlite3_step(priv->stmt_non_standard_record); if (rc != SQLITE_OK && rc != SQLITE_DONE) @@ -205,16 +205,16 @@ int ras_store_non_standard_record(struct ras_events *ras, struct ras_non_standar #ifdef HAVE_ARM static const struct db_fields arm_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="error_count", .type="INTEGER" }, - { .name="affinity", .type="INTEGER" }, - { .name="mpidr", .type="INTEGER" }, - { .name="running_state", .type="INTEGER" }, - { .name="psci_state", .type="INTEGER" }, - { .name="err_info", .type="BLOB" }, - { .name="context_info", .type="BLOB" }, - { .name="vendor_info", .type="BLOB" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "error_count", .type = "INTEGER" }, + { .name = "affinity", .type = "INTEGER" }, + { .name = "mpidr", .type = "INTEGER" }, + { .name = "running_state", .type = "INTEGER" }, + { .name = "psci_state", .type = "INTEGER" }, + { .name = "err_info", .type = "BLOB" }, + { .name = "context_info", .type = "BLOB" }, + { .name = "vendor_info", .type = "BLOB" }, }; static const struct db_table_descriptor arm_event_tab = { @@ -232,18 +232,18 @@ int ras_store_arm_record(struct ras_events *ras, struct ras_arm_event *ev) return 0; log(TERM, LOG_INFO, "arm_event store: %p\n", priv->stmt_arm_record); - sqlite3_bind_text (priv->stmt_arm_record, 1, ev->timestamp, -1, NULL); + sqlite3_bind_text(priv->stmt_arm_record, 1, ev->timestamp, -1, NULL); sqlite3_bind_int (priv->stmt_arm_record, 2, ev->error_count); sqlite3_bind_int (priv->stmt_arm_record, 3, ev->affinity); - sqlite3_bind_int64 (priv->stmt_arm_record, 4, ev->mpidr); + sqlite3_bind_int64(priv->stmt_arm_record, 4, ev->mpidr); sqlite3_bind_int (priv->stmt_arm_record, 5, ev->running_state); sqlite3_bind_int (priv->stmt_arm_record, 6, ev->psci_state); - sqlite3_bind_blob (priv->stmt_arm_record, 7, - ev->pei_error, ev->pei_len, NULL); - sqlite3_bind_blob (priv->stmt_arm_record, 8, - ev->ctx_error, ev->ctx_len, NULL); - sqlite3_bind_blob (priv->stmt_arm_record, 9, - ev->vsei_error, ev->oem_len, NULL); + sqlite3_bind_blob(priv->stmt_arm_record, 7, + ev->pei_error, ev->pei_len, NULL); + sqlite3_bind_blob(priv->stmt_arm_record, 8, + ev->ctx_error, ev->ctx_len, NULL); + sqlite3_bind_blob(priv->stmt_arm_record, 9, + ev->vsei_error, ev->oem_len, NULL); rc = sqlite3_step(priv->stmt_arm_record); if (rc != SQLITE_OK && rc != SQLITE_DONE) @@ -262,15 +262,15 @@ int ras_store_arm_record(struct ras_events *ras, struct ras_arm_event *ev) #ifdef HAVE_EXTLOG static const struct db_fields extlog_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="etype", .type="INTEGER" }, - { .name="error_count", .type="INTEGER" }, - { .name="severity", .type="INTEGER" }, - { .name="address", .type="INTEGER" }, - { .name="fru_id", .type="BLOB" }, - { .name="fru_text", .type="TEXT" }, - { .name="cper_data", .type="BLOB" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "etype", .type = "INTEGER" }, + { .name = "error_count", .type = "INTEGER" }, + { .name = "severity", .type = "INTEGER" }, + { .name = "address", .type = "INTEGER" }, + { .name = "fru_id", .type = "BLOB" }, + { .name = "fru_text", .type = "TEXT" }, + { .name = "cper_data", .type = "BLOB" }, }; static const struct db_table_descriptor extlog_event_tab = { @@ -288,14 +288,14 @@ int ras_store_extlog_mem_record(struct ras_events *ras, struct ras_extlog_event return 0; log(TERM, LOG_INFO, "extlog_record store: %p\n", priv->stmt_extlog_record); - sqlite3_bind_text (priv->stmt_extlog_record, 1, ev->timestamp, -1, NULL); + sqlite3_bind_text(priv->stmt_extlog_record, 1, ev->timestamp, -1, NULL); sqlite3_bind_int (priv->stmt_extlog_record, 2, ev->etype); sqlite3_bind_int (priv->stmt_extlog_record, 3, ev->error_seq); sqlite3_bind_int (priv->stmt_extlog_record, 4, ev->severity); - sqlite3_bind_int64 (priv->stmt_extlog_record, 5, ev->address); - sqlite3_bind_blob (priv->stmt_extlog_record, 6, ev->fru_id, 16, NULL); - sqlite3_bind_text (priv->stmt_extlog_record, 7, ev->fru_text, -1, NULL); - sqlite3_bind_blob (priv->stmt_extlog_record, 8, ev->cper_data, ev->cper_data_length, NULL); + sqlite3_bind_int64(priv->stmt_extlog_record, 5, ev->address); + sqlite3_bind_blob(priv->stmt_extlog_record, 6, ev->fru_id, 16, NULL); + sqlite3_bind_text(priv->stmt_extlog_record, 7, ev->fru_text, -1, NULL); + sqlite3_bind_blob(priv->stmt_extlog_record, 8, ev->cper_data, ev->cper_data_length, NULL); rc = sqlite3_step(priv->stmt_extlog_record); if (rc != SQLITE_OK && rc != SQLITE_DONE) @@ -318,34 +318,34 @@ int ras_store_extlog_mem_record(struct ras_events *ras, struct ras_extlog_event #ifdef HAVE_MCE static const struct db_fields mce_record_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, /* MCE registers */ - { .name="mcgcap", .type="INTEGER" }, - { .name="mcgstatus", .type="INTEGER" }, - { .name="status", .type="INTEGER" }, - { .name="addr", .type="INTEGER" }, // 5 - { .name="misc", .type="INTEGER" }, - { .name="ip", .type="INTEGER" }, - { .name="tsc", .type="INTEGER" }, - { .name="walltime", .type="INTEGER" }, - { .name="cpu", .type="INTEGER" }, // 10 - { .name="cpuid", .type="INTEGER" }, - { .name="apicid", .type="INTEGER" }, - { .name="socketid", .type="INTEGER" }, - { .name="cs", .type="INTEGER" }, - { .name="bank", .type="INTEGER" }, //15 - { .name="cpuvendor", .type="INTEGER" }, + { .name = "mcgcap", .type = "INTEGER" }, + { .name = "mcgstatus", .type = "INTEGER" }, + { .name = "status", .type = "INTEGER" }, + { .name = "addr", .type = "INTEGER" }, // 5 + { .name = "misc", .type = "INTEGER" }, + { .name = "ip", .type = "INTEGER" }, + { .name = "tsc", .type = "INTEGER" }, + { .name = "walltime", .type = "INTEGER" }, + { .name = "cpu", .type = "INTEGER" }, // 10 + { .name = "cpuid", .type = "INTEGER" }, + { .name = "apicid", .type = "INTEGER" }, + { .name = "socketid", .type = "INTEGER" }, + { .name = "cs", .type = "INTEGER" }, + { .name = "bank", .type = "INTEGER" }, //15 + { .name = "cpuvendor", .type = "INTEGER" }, /* Parsed data - will likely change */ - { .name="bank_name", .type="TEXT" }, - { .name="error_msg", .type="TEXT" }, - { .name="mcgstatus_msg", .type="TEXT" }, - { .name="mcistatus_msg", .type="TEXT" }, // 20 - { .name="mcastatus_msg", .type="TEXT" }, - { .name="user_action", .type="TEXT" }, - { .name="mc_location", .type="TEXT" }, + { .name = "bank_name", .type = "TEXT" }, + { .name = "error_msg", .type = "TEXT" }, + { .name = "mcgstatus_msg", .type = "TEXT" }, + { .name = "mcistatus_msg", .type = "TEXT" }, // 20 + { .name = "mcastatus_msg", .type = "TEXT" }, + { .name = "user_action", .type = "TEXT" }, + { .name = "mc_location", .type = "TEXT" }, }; static const struct db_table_descriptor mce_record_tab = { @@ -363,15 +363,15 @@ int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev) return 0; log(TERM, LOG_INFO, "mce_record store: %p\n", priv->stmt_mce_record); - sqlite3_bind_text (priv->stmt_mce_record, 1, ev->timestamp, -1, NULL); + sqlite3_bind_text(priv->stmt_mce_record, 1, ev->timestamp, -1, NULL); sqlite3_bind_int (priv->stmt_mce_record, 2, ev->mcgcap); sqlite3_bind_int (priv->stmt_mce_record, 3, ev->mcgstatus); - sqlite3_bind_int64 (priv->stmt_mce_record, 4, ev->status); - sqlite3_bind_int64 (priv->stmt_mce_record, 5, ev->addr); - sqlite3_bind_int64 (priv->stmt_mce_record, 6, ev->misc); - sqlite3_bind_int64 (priv->stmt_mce_record, 7, ev->ip); - sqlite3_bind_int64 (priv->stmt_mce_record, 8, ev->tsc); - sqlite3_bind_int64 (priv->stmt_mce_record, 9, ev->walltime); + sqlite3_bind_int64(priv->stmt_mce_record, 4, ev->status); + sqlite3_bind_int64(priv->stmt_mce_record, 5, ev->addr); + sqlite3_bind_int64(priv->stmt_mce_record, 6, ev->misc); + sqlite3_bind_int64(priv->stmt_mce_record, 7, ev->ip); + sqlite3_bind_int64(priv->stmt_mce_record, 8, ev->tsc); + sqlite3_bind_int64(priv->stmt_mce_record, 9, ev->walltime); sqlite3_bind_int (priv->stmt_mce_record, 10, ev->cpu); sqlite3_bind_int (priv->stmt_mce_record, 11, ev->cpuid); sqlite3_bind_int (priv->stmt_mce_record, 12, ev->apicid); @@ -409,13 +409,13 @@ int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev) #ifdef HAVE_DEVLINK static const struct db_fields devlink_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="bus_name", .type="TEXT" }, - { .name="dev_name", .type="TEXT" }, - { .name="driver_name", .type="TEXT" }, - { .name="reporter_name", .type="TEXT" }, - { .name="msg", .type="TEXT" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "bus_name", .type = "TEXT" }, + { .name = "dev_name", .type = "TEXT" }, + { .name = "driver_name", .type = "TEXT" }, + { .name = "reporter_name", .type = "TEXT" }, + { .name = "msg", .type = "TEXT" }, }; static const struct db_table_descriptor devlink_event_tab = { @@ -461,14 +461,14 @@ int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev) #ifdef HAVE_DISKERROR static const struct db_fields diskerror_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="dev", .type="TEXT" }, - { .name="sector", .type="INTEGER" }, - { .name="nr_sector", .type="INTEGER" }, - { .name="error", .type="TEXT" }, - { .name="rwbs", .type="TEXT" }, - { .name="cmd", .type="TEXT" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "dev", .type = "TEXT" }, + { .name = "sector", .type = "INTEGER" }, + { .name = "nr_sector", .type = "INTEGER" }, + { .name = "error", .type = "TEXT" }, + { .name = "rwbs", .type = "TEXT" }, + { .name = "cmd", .type = "TEXT" }, }; static const struct db_table_descriptor diskerror_event_tab = { @@ -515,11 +515,11 @@ int ras_store_diskerror_event(struct ras_events *ras, struct diskerror_event *ev #ifdef HAVE_MEMORY_FAILURE static const struct db_fields mf_event_fields[] = { - { .name="id", .type="INTEGER PRIMARY KEY" }, - { .name="timestamp", .type="TEXT" }, - { .name="pfn", .type="TEXT" }, - { .name="page_type", .type="TEXT" }, - { .name="action_result", .type="TEXT" }, + { .name = "id", .type = "INTEGER PRIMARY KEY" }, + { .name = "timestamp", .type = "TEXT" }, + { .name = "pfn", .type = "TEXT" }, + { .name = "page_type", .type = "TEXT" }, + { .name = "action_result", .type = "TEXT" }, }; static const struct db_table_descriptor mf_event_tab = { @@ -1167,7 +1167,7 @@ static int ras_mc_alter_table(struct sqlite3_priv *priv, found = 0; for (j = 0; j < col_count; j++) { if (!strcmp(field->name, - sqlite3_column_name(*stmt, j))) { + sqlite3_column_name(*stmt, j))) { found = 1; break; } @@ -1258,13 +1258,13 @@ int ras_mc_finalize_vendor_table(sqlite3_stmt *stmt) return rc; } -int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) +int ras_mc_event_opendb(unsigned int cpu, struct ras_events *ras) { int rc; sqlite3 *db; struct sqlite3_priv *priv; - printf("Calling %s()\n", __FUNCTION__); + printf("Calling %s()\n", __func__); ras->db_ref_count++; if (ras->db_ref_count > 1) @@ -1277,6 +1277,7 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) return -1; struct stat st = {0}; + if (stat(RASSTATEDIR, &st) == -1) { if (errno != ENOENT) { log(TERM, LOG_ERR, @@ -1358,7 +1359,7 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) rc = ras_mc_create_table(priv, &non_standard_event_tab); if (rc == SQLITE_OK) { rc = ras_mc_prepare_stmt(priv, &priv->stmt_non_standard_record, - &non_standard_event_tab); + &non_standard_event_tab); if (rc != SQLITE_OK) goto error; } @@ -1368,7 +1369,7 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) rc = ras_mc_create_table(priv, &arm_event_tab); if (rc == SQLITE_OK) { rc = ras_mc_prepare_stmt(priv, &priv->stmt_arm_record, - &arm_event_tab); + &arm_event_tab); if (rc != SQLITE_OK) goto error; } @@ -1377,7 +1378,7 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) rc = ras_mc_create_table(priv, &devlink_event_tab); if (rc == SQLITE_OK) { rc = ras_mc_prepare_stmt(priv, &priv->stmt_devlink_event, - &devlink_event_tab); + &devlink_event_tab); if (rc != SQLITE_OK) goto error; } @@ -1387,7 +1388,7 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) rc = ras_mc_create_table(priv, &diskerror_event_tab); if (rc == SQLITE_OK) { rc = ras_mc_prepare_stmt(priv, &priv->stmt_diskerror_event, - &diskerror_event_tab); + &diskerror_event_tab); if (rc != SQLITE_OK) goto error; } @@ -1527,7 +1528,6 @@ int ras_mc_event_closedb(unsigned int cpu, struct ras_events *ras) } #endif - #ifdef HAVE_MCE if (priv->stmt_mce_record) { rc = sqlite3_finalize(priv->stmt_mce_record); diff --git a/ras-report.c b/ras-report.c index a30b66d..5cc55b6 100644 --- a/ras-report.c +++ b/ras-report.c @@ -21,13 +21,14 @@ #include "ras-report.h" -static int setup_report_socket(void){ +static int setup_report_socket(void) +{ int sockfd = -1; int rc = -1; struct sockaddr_un addr; sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd < 0){ + if (sockfd < 0) { return -1; } @@ -45,12 +46,13 @@ static int setup_report_socket(void){ return sockfd; } -static int commit_report_basic(int sockfd){ +static int commit_report_basic(int sockfd) +{ char buf[INPUT_BUFFER_SIZE]; struct utsname un; int rc = -1; - if(sockfd < 0){ + if (sockfd < 0) { return rc; } @@ -58,7 +60,7 @@ static int commit_report_basic(int sockfd){ memset(&un, 0, sizeof(struct utsname)); rc = uname(&un); - if(rc < 0){ + if (rc < 0) { return rc; } @@ -67,35 +69,36 @@ static int commit_report_basic(int sockfd){ */ 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; } -static int set_mc_event_backtrace(char *buf, struct ras_mc_event *ev){ +static int set_mc_event_backtrace(char *buf, struct ras_mc_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -131,10 +134,11 @@ static int set_mc_event_backtrace(char *buf, struct ras_mc_event *ev){ return 0; } -static int set_mce_event_backtrace(char *buf, struct mce_event *ev){ +static int set_mce_event_backtrace(char *buf, struct mce_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -190,10 +194,11 @@ static int set_mce_event_backtrace(char *buf, struct mce_event *ev){ return 0; } -static int set_aer_event_backtrace(char *buf, struct ras_aer_event *ev){ +static int set_aer_event_backtrace(char *buf, struct ras_aer_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -211,10 +216,11 @@ static int set_aer_event_backtrace(char *buf, struct ras_aer_event *ev){ return 0; } -static int set_non_standard_event_backtrace(char *buf, struct ras_non_standard_event *ev){ +static int set_non_standard_event_backtrace(char *buf, struct ras_non_standard_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -230,10 +236,11 @@ static int set_non_standard_event_backtrace(char *buf, struct ras_non_standard_e return 0; } -static int set_arm_event_backtrace(char *buf, struct ras_arm_event *ev){ +static int set_arm_event_backtrace(char *buf, struct ras_arm_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -257,10 +264,11 @@ static int set_arm_event_backtrace(char *buf, struct ras_arm_event *ev){ return 0; } -static int set_devlink_event_backtrace(char *buf, struct devlink_event *ev){ +static int set_devlink_event_backtrace(char *buf, struct devlink_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -282,10 +290,11 @@ static int set_devlink_event_backtrace(char *buf, struct devlink_event *ev){ return 0; } -static int set_diskerror_event_backtrace(char *buf, struct diskerror_event *ev) { +static int set_diskerror_event_backtrace(char *buf, struct diskerror_event *ev) +{ char bt_buf[MAX_BACKTRACE_SIZE]; - if(!buf || !ev) + if (!buf || !ev) return -1; sprintf(bt_buf, "BACKTRACE=" \ @@ -317,14 +326,14 @@ static int set_mf_event_backtrace(char *buf, struct ras_mf_event *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); + "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); @@ -661,19 +670,20 @@ static int set_cxl_memory_module_event_backtrace(char *buf, struct ras_cxl_memor return 0; } -static int commit_report_backtrace(int sockfd, int type, void *ev){ +static int commit_report_backtrace(int sockfd, int type, void *ev) +{ char buf[MAX_BACKTRACE_SIZE]; char *pbuf = buf; 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){ + switch (type) { case MC_EVENT: rc = set_mc_event_backtrace(buf, (struct ras_mc_event *)ev); break; @@ -726,15 +736,15 @@ static int commit_report_backtrace(int sockfd, int type, void *ev){ 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)){ + 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; } @@ -742,14 +752,15 @@ static int commit_report_backtrace(int sockfd, int type, void *ev){ } rc = write(sockfd, pbuf, buf_len + 1); - if(rc < buf_len){ + if (rc < buf_len) { return -1; } return 0; } -int ras_report_mc_event(struct ras_events *ras, struct ras_mc_event *ev){ +int ras_report_mc_event(struct ras_events *ras, struct ras_mc_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = -1; int done = 0; @@ -758,29 +769,29 @@ 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; } @@ -788,18 +799,19 @@ int ras_report_mc_event(struct ras_events *ras, struct ras_mc_event *ev){ mc_fail: - if(sockfd >= 0){ + if (sockfd >= 0) { close(sockfd); } - if(done){ + if (done) { return 0; - }else{ + } else { return -1; } } -int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev){ +int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = 0; int done = 0; @@ -808,29 +820,29 @@ 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; } @@ -838,18 +850,19 @@ int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev){ aer_fail: - if(sockfd >= 0){ + if (sockfd >= 0) { close(sockfd); } - if(done){ + if (done) { return 0; - }else{ + } else { return -1; } } -int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standard_event *ev){ +int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standard_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = 0; int rc = -1; @@ -857,29 +870,29 @@ 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; } @@ -887,14 +900,15 @@ int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standar non_standard_fail: - if(sockfd >= 0){ + if (sockfd >= 0) { close(sockfd); } return rc; } -int ras_report_arm_event(struct ras_events *ras, struct ras_arm_event *ev){ +int ras_report_arm_event(struct ras_events *ras, struct ras_arm_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = 0; int rc = -1; @@ -902,29 +916,29 @@ 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; } @@ -932,14 +946,15 @@ int ras_report_arm_event(struct ras_events *ras, struct ras_arm_event *ev){ arm_fail: - if(sockfd >= 0){ + if (sockfd >= 0) { close(sockfd); } return rc; } -int ras_report_mce_event(struct ras_events *ras, struct mce_event *ev){ +int ras_report_mce_event(struct ras_events *ras, struct mce_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = 0; int done = 0; @@ -948,29 +963,29 @@ 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; } @@ -978,18 +993,19 @@ int ras_report_mce_event(struct ras_events *ras, struct mce_event *ev){ mce_fail: - if(sockfd >= 0){ + if (sockfd >= 0) { close(sockfd); } - if(done){ + if (done) { return 0; - }else{ + } else { return -1; } } -int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev){ +int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = 0; int done = 0; @@ -998,29 +1014,29 @@ 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; } @@ -1028,18 +1044,19 @@ int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev){ devlink_fail: - if(sockfd >= 0){ + if (sockfd >= 0) { close(sockfd); } - if(done){ + if (done) { return 0; - }else{ + } else { return -1; } } -int ras_report_diskerror_event(struct ras_events *ras, struct diskerror_event *ev){ +int ras_report_diskerror_event(struct ras_events *ras, struct diskerror_event *ev) +{ char buf[MAX_MESSAGE_SIZE]; int sockfd = 0; int done = 0; @@ -1048,42 +1065,42 @@ 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{ + } else { return -1; } } @@ -1349,7 +1366,6 @@ cxl_generic_fail: return 0; else return -1; - } int ras_report_cxl_general_media_event(struct ras_events *ras, struct ras_cxl_general_media_event *ev) diff --git a/rasdaemon.c b/rasdaemon.c index 0db51c9..7a3f964 100644 --- a/rasdaemon.c +++ b/rasdaemon.c @@ -34,7 +34,7 @@ #define TOOL_DESCRIPTION "RAS daemon to log the RAS events." #define ARGS_DOC "" #define DISABLE "DISABLE" -char *choices_disable = NULL; +char *choices_disable; const char *argp_program_version = TOOL_NAME " " VERSION; const char *argp_program_bug_address = "Mauro Carvalho Chehab "; @@ -129,6 +129,7 @@ int main(int argc, char *argv[]) { struct arguments args; int idx = -1; + choices_disable = getenv(DISABLE); #ifdef HAVE_MCE @@ -179,7 +180,7 @@ int main(int argc, char *argv[]) .children = offline_parser, #endif }; - memset (&args, 0, sizeof(args)); + memset(&args, 0, sizeof(args)); user_hz = sysconf(_SC_CLK_TCK); @@ -208,7 +209,7 @@ int main(int argc, char *argv[]) openlog(TOOL_NAME, 0, LOG_DAEMON); if (!args.foreground) - if (daemon(0,0)) + if (daemon(0, 0)) exit(EXIT_FAILURE); handle_ras_events(args.record_events); diff --git a/rbtree.c b/rbtree.c index d9b1bd4..43da434 100644 --- a/rbtree.c +++ b/rbtree.c @@ -28,7 +28,8 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) struct rb_node *right = node->rb_right; struct rb_node *parent = rb_parent(node); - if ((node->rb_right = right->rb_left)) + node->rb_right = right->rb_left; + if (node->rb_right) rb_set_parent(right->rb_left, node); right->rb_left = node; @@ -40,8 +41,7 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) parent->rb_left = right; else parent->rb_right = right; - } - else + } else root->rb_node = right; rb_set_parent(node, right); } @@ -51,7 +51,8 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) struct rb_node *left = node->rb_left; struct rb_node *parent = rb_parent(node); - if ((node->rb_left = left->rb_right)) + node->rb_left = left->rb_right; + if (node->rb_left) rb_set_parent(left->rb_right, node); left->rb_right = node; @@ -63,8 +64,7 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) parent->rb_right = left; else parent->rb_left = left; - } - else + } else root->rb_node = left; rb_set_parent(node, left); } @@ -81,6 +81,7 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) { { register struct rb_node *uncle = gparent->rb_right; + if (uncle && rb_is_red(uncle)) { rb_set_black(uncle); @@ -94,6 +95,7 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) if (parent->rb_right == node) { struct rb_node *tmp; + __rb_rotate_left(parent, root); tmp = parent; parent = node; @@ -106,6 +108,7 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) } else { { struct rb_node *uncle = gparent->rb_left; + if (uncle && rb_is_red(uncle)) { rb_set_black(uncle); @@ -119,6 +122,7 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) if (parent->rb_left == node) { struct rb_node *tmp; + __rb_rotate_right(parent, root); tmp = parent; parent = node; @@ -157,8 +161,7 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, rb_set_red(other); node = parent; parent = rb_parent(node); - } - else + } else { if (!other->rb_right || rb_is_black(other->rb_right)) { @@ -174,8 +177,7 @@ 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)) @@ -191,8 +193,7 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, rb_set_red(other); node = parent; parent = rb_parent(node); - } - else + } else { if (!other->rb_left || rb_is_black(other->rb_left)) { @@ -272,8 +273,7 @@ void rb_erase(struct rb_node *node, struct rb_root *root) parent->rb_left = child; else parent->rb_right = child; - } - else + } else root->rb_node = child; color: @@ -320,7 +320,7 @@ struct rb_node *rb_next(const struct rb_node *node) if (node->rb_right) { node = node->rb_right; while (node->rb_left) - node=node->rb_left; + node = node->rb_left; return (struct rb_node *)node; } @@ -348,7 +348,7 @@ struct rb_node *rb_prev(const struct rb_node *node) if (node->rb_left) { node = node->rb_left; while (node->rb_right) - node=node->rb_right; + node = node->rb_right; return (struct rb_node *)node; }