From: Mauro Carvalho Chehab Date: Tue, 16 Jul 2024 23:06:52 +0000 (+0200) Subject: rasdaemon: coding style cleanup X-Git-Tag: v0.8.2~67 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7a69b22ccd965f9b84b94c1af1d9a6539160ce77;p=users%2Fmchehab%2Frasdaemon.git rasdaemon: coding style cleanup Solve lots of coding style issues reported by: ./scripts/checkpatch.pl --terse --show-types --strict \ -f $(git ls-files|grep -E '\.[ch]$') \ --ignore MACRO_ARG_REUSE,STRCPY,IF_0,UNNECESSARY_PARENTHESES,CAMELCASE,STRNCPY; done Signed-off-by: Mauro Carvalho Chehab --- diff --git a/bitfield.c b/bitfield.c index 2076683..17e154a 100644 --- a/bitfield.c +++ b/bitfield.c @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include @@ -25,7 +25,7 @@ #include "ras-mce-handler.h" #include "bitfield.h" -unsigned int bitfield_msg(char *buf, size_t len, const char **bitarray, +unsigned int bitfield_msg(char *buf, size_t len, const char * const *bitarray, unsigned int array_len, unsigned int bit_offset, unsigned int ignore_bits, uint64_t status) @@ -86,8 +86,9 @@ void decode_bitfield(struct mce_event *e, uint64_t status, continue; mce_snprintf(e->error_msg, "<%u:%llx>", f->start_bit, (long long)v); - } else + } else { mce_snprintf(e->error_msg, "%s", s); + } } } diff --git a/bitfield.h b/bitfield.h index 2b75b41..b38db42 100644 --- a/bitfield.h +++ b/bitfield.h @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include @@ -60,7 +60,7 @@ static inline int test_prefix(int nr, uint32_t value) /* Ancillary routines */ -unsigned int bitfield_msg(char *buf, size_t len, const char **bitarray, +unsigned int bitfield_msg(char *buf, size_t len, const char * const *bitarray, unsigned int array_len, unsigned int bit_offset, unsigned int ignore_bits, uint64_t status); diff --git a/mce-amd-k8.c b/mce-amd-k8.c index f27b823..7906c95 100644 --- a/mce-amd-k8.c +++ b/mce-amd-k8.c @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include @@ -33,7 +33,7 @@ #define K8_MCELOG_THRESHOLD_L3_CACHE (4 * 9 + 2) #define K8_MCELOG_THRESHOLD_FBDIMM (4 * 9 + 3) -static const char *k8bank[] = { +static const char * const k8bank[] = { "data cache", "instruction cache", "bus unit", @@ -42,7 +42,7 @@ static const char *k8bank[] = { "fixed-issue reoder" }; -static const char *k8threshold[] = { +static const char * const k8threshold[] = { [0 ... K8_MCELOG_THRESHOLD_DRAM_ECC - 1] = "Unknown threshold counter", [K8_MCELOG_THRESHOLD_DRAM_ECC] = "MC4_MISC0 DRAM threshold", [K8_MCELOG_THRESHOLD_LINK] = "MC4_MISC1 Link threshold", @@ -53,35 +53,35 @@ static const char *k8threshold[] = { "Unknown threshold counter", }; -static const char *transaction[] = { +static const char * const transaction[] = { "instruction", "data", "generic", "reserved" }; -static const char *cachelevel[] = { +static const char * const cachelevel[] = { "0", "1", "2", "generic" }; -static const char *memtrans[] = { +static const char * const memtrans[] = { "generic error", "generic read", "generic write", "data read", "data write", "instruction fetch", "prefetch", "evict", "snoop", "?", "?", "?", "?", "?", "?", "?" }; -static const char *partproc[] = { +static const char * const partproc[] = { "local node origin", "local node response", "local node observed", "generic participation" }; -static const char *timeout[] = { +static const char * const timeout[] = { "request didn't time out", "request timed out" }; -static const char *memoryio[] = { +static const char * const memoryio[] = { "memory", "res.", "i/o", "generic" }; -static const char *nbextendederr[] = { +static const char * const nbextendederr[] = { "RAM ECC error", "CRC error", "Sync error", @@ -103,7 +103,7 @@ static const char *nbextendederr[] = { "L3 Cache LRU Error" }; -static const char *highbits[32] = { +static const char * const highbits[32] = { [31] = "valid", [30] = "error overflow (multiple errors)", [29] = "error uncorrected", @@ -264,9 +264,8 @@ int parse_amd_k8_event(struct ras_events *ras, struct mce_event *e) if (e->bank == 4) { unsigned short exterrcode = (e->status >> 16) & 0x0f; - if (exterrcode == 5 && (e->status & (1ULL << 61))) { + if (exterrcode == 5 && (e->status & (1ULL << 61))) return -1; - } } bank_name(e); diff --git a/mce-amd.c b/mce-amd.c index ac0dbac..028a329 100644 --- a/mce-amd.c +++ b/mce-amd.c @@ -86,10 +86,11 @@ void decode_amd_errcode(struct mce_event *e) "Uncorrected, software restartable error."); strcpy(e->error_msg, "Uncorrected, software containable error."); - } else if (e->status & MCI_STATUS_DEFERRED) + } else if (e->status & MCI_STATUS_DEFERRED) { strcpy(e->error_msg, "Deferred error, no action required."); - else + } else { strcpy(e->error_msg, "Corrected error, no action required."); + } if (!(e->status & MCI_STATUS_VAL)) mce_snprintf(e->mcistatus_msg, "MCE_INVALID"); diff --git a/mce-intel-broadwell-de.c b/mce-intel-broadwell-de.c index 8210782..ad2421c 100644 --- a/mce-intel-broadwell-de.c +++ b/mce-intel-broadwell-de.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-broadwell-epex.c b/mce-intel-broadwell-epex.c index 9c863d9..52b3815 100644 --- a/mce-intel-broadwell-epex.c +++ b/mce-intel-broadwell-epex.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-dunnington.c b/mce-intel-dunnington.c index 71c3fb4..1114fd7 100644 --- a/mce-intel-dunnington.c +++ b/mce-intel-dunnington.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-haswell.c b/mce-intel-haswell.c index 195f6ed..12ec3c3 100644 --- a/mce-intel-haswell.c +++ b/mce-intel-haswell.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-i10nm.c b/mce-intel-i10nm.c index c4ace56..a486866 100644 --- a/mce-intel-i10nm.c +++ b/mce-intel-i10nm.c @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include @@ -299,18 +299,32 @@ static void i10nm_imc_misc(struct mce_event *e) uint32_t eccmode = EXTRACT(e->misc, 59, 62); uint32_t transient = EXTRACT(e->misc, 63, 63); - mce_snprintf(e->error_msg, "bank: 0x%x bankgroup: 0x%x row: 0x%x column: 0x%x", bank, bankgroup, row, column); + mce_snprintf(e->error_msg, + "bank: 0x%x bankgroup: 0x%x row: 0x%x column: 0x%x", + bank, bankgroup, row, column); if (!transient && !EXTRACT(e->status, 61, 61)) mce_snprintf(e->error_msg, "failed device: 0x%x", fdevice); mce_snprintf(e->error_msg, "rank: 0x%x subrank: 0x%x", rank, subrank); mce_snprintf(e->error_msg, "ecc mode: "); switch (eccmode) { - case 0: mce_snprintf(e->error_msg, "SDDC memory mode"); break; - case 1: mce_snprintf(e->error_msg, "SDDC"); break; - case 4: mce_snprintf(e->error_msg, "ADDDC memory mode"); break; - case 5: mce_snprintf(e->error_msg, "ADDDC"); break; - case 8: mce_snprintf(e->error_msg, "DDRT read"); break; - default: mce_snprintf(e->error_msg, "unknown"); break; + case 0: + mce_snprintf(e->error_msg, "SDDC memory mode"); + break; + case 1: + mce_snprintf(e->error_msg, "SDDC"); + break; + case 4: + mce_snprintf(e->error_msg, "ADDDC memory mode"); + break; + case 5: + mce_snprintf(e->error_msg, "ADDDC"); + break; + case 8: + mce_snprintf(e->error_msg, "DDRT read"); + break; + default: + mce_snprintf(e->error_msg, "unknown"); + break; } if (transient) mce_snprintf(e->error_msg, "transient"); @@ -359,7 +373,7 @@ static enum banktype sapphire[32] = { [13 ... 20] = BT_IMC, }; -void i10nm_memerr_misc(struct mce_event *e, int *channel); +static void i10nm_memerr_misc(struct mce_event *e, int *channel); void i10nm_decode_model(enum cputype cputype, struct ras_events *ras, struct mce_event *e) @@ -426,12 +440,24 @@ void i10nm_decode_model(enum cputype cputype, struct ras_events *ras, mce_snprintf(e->error_msg, "MemCtrl: "); f = EXTRACT(status, 16, 23); switch (EXTRACT(status, 24, 31)) { - case 0: decode_bitfield(e, f, imc0); break; - case 1: decode_bitfield(e, f, imc1); break; - case 2: decode_bitfield(e, f, imc2); break; - case 4: decode_bitfield(e, f, imc4); break; - case 8: decode_bitfield(e, f, imc8); break; - case 0x10: decode_bitfield(e, f, imc10); break; + case 0: + decode_bitfield(e, f, imc0); + break; + case 1: + decode_bitfield(e, f, imc1); + break; + case 2: + decode_bitfield(e, f, imc2); + break; + case 4: + decode_bitfield(e, f, imc4); + break; + case 8: + decode_bitfield(e, f, imc8); + break; + case 0x10: + decode_bitfield(e, f, imc10); + break; } i10nm_imc_misc(e); break; @@ -464,7 +490,7 @@ void i10nm_decode_model(enum cputype cputype, struct ras_events *ras, * we can derive the channel from the bank number. * There can be four memory controllers with two channels each. */ -void i10nm_memerr_misc(struct mce_event *e, int *channel) +static void i10nm_memerr_misc(struct mce_event *e, int *channel) { uint64_t status = e->status; unsigned int chan, imc; diff --git a/mce-intel-ivb.c b/mce-intel-ivb.c index e5e6a7a..3204b58 100644 --- a/mce-intel-ivb.c +++ b/mce-intel-ivb.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-knl.c b/mce-intel-knl.c index 0e2ea80..ff00ca9 100644 --- a/mce-intel-knl.c +++ b/mce-intel-knl.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-nehalem.c b/mce-intel-nehalem.c index 18992d1..1ab0ef3 100644 --- a/mce-intel-nehalem.c +++ b/mce-intel-nehalem.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-p4-p6.c b/mce-intel-p4-p6.c index 2751d34..ecd266f 100644 --- a/mce-intel-p4-p6.c +++ b/mce-intel-p4-p6.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-sb.c b/mce-intel-sb.c index 385b125..6c69f28 100644 --- a/mce-intel-sb.c +++ b/mce-intel-sb.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-skylake-xeon.c b/mce-intel-skylake-xeon.c index 37e5e11..fdf02b9 100644 --- a/mce-intel-skylake-xeon.c +++ b/mce-intel-skylake-xeon.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel-tulsa.c b/mce-intel-tulsa.c index f38d638..7607e02 100644 --- a/mce-intel-tulsa.c +++ b/mce-intel-tulsa.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include diff --git a/mce-intel.c b/mce-intel.c index 7f48cc4..58bcba3 100644 --- a/mce-intel.c +++ b/mce-intel.c @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include @@ -164,10 +164,15 @@ static void decode_memory_controller(struct mce_event *e, uint32_t status) static void decode_termal_bank(struct mce_event *e) { if (e->status & 1) { - mce_snprintf(e->mcgstatus_msg, "Processor %d heated above trip temperature. Throttling enabled.", e->cpu); - mce_snprintf(e->user_action, "Please check your system cooling. Performance will be impacted"); + mce_snprintf(e->mcgstatus_msg, + "Processor %d heated above trip temperature. Throttling enabled.", + e->cpu); + mce_snprintf(e->user_action, + "Please check your system cooling. Performance will be impacted"); } else { - mce_snprintf(e->error_msg, "Processor %d below trip temperature. Throttling disabled", e->cpu); + mce_snprintf(e->error_msg, + "Processor %d below trip temperature. Throttling disabled", + e->cpu); } } @@ -209,9 +214,8 @@ static char *get_RRRR_str(uint8_t rrrr) unsigned int i; for (i = 0; i < ARRAY_SIZE(RRRR); i++) { - if (RRRR[i].value == rrrr) { + if (RRRR[i].value == rrrr) return RRRR[i].str; - } } return "UNKNOWN"; @@ -281,8 +285,9 @@ static void decode_mca(struct mce_event *e, uint64_t track, int *ismemerr) } else if (test_prefix(7, mca)) { decode_memory_controller(e, mca); *ismemerr = 1; - } else + } else { mce_snprintf(e->mcastatus_msg, "Unknown Error %x", mca); + } } static void decode_tracking(struct mce_event *e, uint64_t track) diff --git a/non-standard-ampere.c b/non-standard-ampere.c index 905e0c5..0790323 100644 --- a/non-standard-ampere.c +++ b/non-standard-ampere.c @@ -1058,8 +1058,9 @@ static int decode_amp_oem_type_error(struct ras_events *ras, } else if (payload_type == PAYLOAD_TYPE_3) { db_tab = amp_payload3_event_tab; id = AMP_PAYLOAD3_FIELD_TIMESTAMP; - } else + } else { return -1; + } if (!ev_decoder->stmt_dec_record) { if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record, diff --git a/non-standard-ampere.h b/non-standard-ampere.h index 1bfe344..58c203a 100644 --- a/non-standard-ampere.h +++ b/non-standard-ampere.h @@ -14,10 +14,10 @@ #include "ras-events.h" #include -#define SOCKET_NUM(x) ((x >> 14) & 0x3) -#define PAYLOAD_TYPE(x) ((x >> 6) & 0x3) -#define TYPE(x) (x & 0x3f) -#define INSTANCE(x) (x & 0x3fff) +#define SOCKET_NUM(x) (((x) >> 14) & 0x3) +#define PAYLOAD_TYPE(x) (((x) >> 6) & 0x3) +#define TYPE(x) ((x) & 0x3f) +#define INSTANCE(x) ((x) & 0x3fff) #define AMP_PAYLOAD0_BUF_LEN 1024 #define PAYLOAD_TYPE_0 0x00 #define PAYLOAD_TYPE_1 0x01 diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c index e482a7a..d90c6bf 100644 --- a/non-standard-hisi_hip08.c +++ b/non-standard-hisi_hip08.c @@ -185,11 +185,11 @@ enum { struct hisi_module_info { int id; const char *name; - const char **sub; + const char * const *sub; int sub_num; }; -static const char *pll_submodule_name[] = { +static const char * const pll_submodule_name[] = { "TB_PLL0", "TB_PLL1", "TB_PLL2", @@ -205,7 +205,7 @@ static const char *pll_submodule_name[] = { "NIMBUS_PLL4", }; -static const char *sllc_submodule_name[] = { +static const char * const sllc_submodule_name[] = { "TB_SLLC0", "TB_SLLC1", "TB_SLLC2", @@ -216,7 +216,7 @@ static const char *sllc_submodule_name[] = { "NIMBUS_SLLC1", }; -static const char *sioe_submodule_name[] = { +static const char * const sioe_submodule_name[] = { "TB_SIOE0", "TB_SIOE1", "TB_SIOE2", @@ -229,12 +229,12 @@ static const char *sioe_submodule_name[] = { "NIMBUS_SIOE1", }; -static const char *poe_submodule_name[] = { +static const char * const poe_submodule_name[] = { "TB_POE", "TA_POE", }; -static const char *disp_submodule_name[] = { +static const char * const disp_submodule_name[] = { "TB_PERI_DISP", "TB_POE_DISP", "TB_GIC_DISP", @@ -247,7 +247,7 @@ static const char *disp_submodule_name[] = { "NETWORK_DISP", }; -static const char *sas_submodule_name[] = { +static const char * const sas_submodule_name[] = { "SAS0", "SAS1", }; @@ -321,27 +321,27 @@ static const struct hisi_module_info hisi_oem_type1_module[] = { } }; -static const char *smmu_submodule_name[] = { +static const char * const smmu_submodule_name[] = { "HAC_SMMU", "PCIE_SMMU", "MGMT_SMMU", "NIC_SMMU", }; -static const char *hllc_submodule_name[] = { +static const char * const hllc_submodule_name[] = { "HLLC0", "HLLC1", "HLLC2", }; -static const char *hha_submodule_name[] = { +static const char * const hha_submodule_name[] = { "TB_HHA0", "TB_HHA1", "TA_HHA0", "TA_HHA1" }; -static const char *ddrc_submodule_name[] = { +static const char * const ddrc_submodule_name[] = { "TB_DDRC0", "TB_DDRC1", "TB_DDRC2", @@ -352,7 +352,7 @@ static const char *ddrc_submodule_name[] = { "TA_DDRC3", }; -static const char *l3tag_submodule_name[] = { +static const char * const l3tag_submodule_name[] = { "TB_PARTITION0", "TB_PARTITION1", "TB_PARTITION2", @@ -371,7 +371,7 @@ static const char *l3tag_submodule_name[] = { "TA_PARTITION7", }; -static const char *l3data_submodule_name[] = { +static const char * const l3data_submodule_name[] = { "TB_BANK0", "TB_BANK1", "TB_BANK2", @@ -427,8 +427,8 @@ static const struct hisi_module_info hisi_oem_type2_module[] = { } }; -static const char *oem_module_name(const struct hisi_module_info *info, - uint8_t module_id) +static const char * const oem_module_name(const struct hisi_module_info *info, + uint8_t module_id) { const struct hisi_module_info *module = &info[0]; @@ -442,13 +442,13 @@ static const char *oem_module_name(const struct hisi_module_info *info, return "unknown"; } -static const char *oem_submodule_name(const struct hisi_module_info *info, - uint8_t module_id, uint8_t sub_module_id) +static const char * const oem_submodule_name(const struct hisi_module_info *info, + uint8_t module_id, uint8_t sub_module_id) { const struct hisi_module_info *module = &info[0]; for (; module->name; module++) { - const char **submodule = module->sub; + const char * const *submodule = module->sub; if (module->id != module_id) continue; diff --git a/non-standard-hisilicon.c b/non-standard-hisilicon.c index e9ea5df..00388ec 100644 --- a/non-standard-hisilicon.c +++ b/non-standard-hisilicon.c @@ -171,13 +171,13 @@ static const struct db_table_descriptor hisi_common_section_tab = { }; #endif -static const char *soc_desc[] = { +static const char * const soc_desc[] = { "Kunpeng916", "Kunpeng920", "Kunpeng930", }; -static const char *module_name[] = { +static const char * const module_name[] = { "MN", "PLL", "SLLC", @@ -221,7 +221,7 @@ static const char *module_name[] = { "HBMC", }; -static const char *get_soc_desc(uint8_t soc_id) +static const char * const get_soc_desc(uint8_t soc_id) { if (soc_id >= sizeof(soc_desc) / sizeof(char *)) return "unknown"; diff --git a/non-standard-jaguarmicro.c b/non-standard-jaguarmicro.c index cb0a78d..fb887d3 100644 --- a/non-standard-jaguarmicro.c +++ b/non-standard-jaguarmicro.c @@ -448,10 +448,14 @@ static const char *get_jm_dev_desc(uint8_t subsys_id, uint8_t mod_id, uint8_t su static inline char *jm_err_severity(uint8_t err_sev) { switch (err_sev) { - case JM_ERR_SEVERITY_NFE: return "recoverable"; - case JM_ERR_SEVERITY_FE: return "fatal"; - case JM_ERR_SEVERITY_CE: return "corrected"; - case JM_ERR_SEVERITY_NONE: return "none"; + case JM_ERR_SEVERITY_NFE: + return "recoverable"; + case JM_ERR_SEVERITY_FE: + return "fatal"; + case JM_ERR_SEVERITY_CE: + return "corrected"; + case JM_ERR_SEVERITY_NONE: + return "none"; default: break; } @@ -498,11 +502,13 @@ static void decode_jm_common_sec_head(struct ras_ns_ev_decoder *ev_decoder, 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, 0, - 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_INT, JM_PAYLOAD_FIELD_MODULE_ID, err->submodule_id, NULL); @@ -510,10 +516,12 @@ static void decode_jm_common_sec_head(struct ras_ns_ev_decoder *ev_decoder, 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, - 0, get_jm_dev_desc(err->subsystem_id, err->module_id, err->submodule_id)); + 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, err->dev_id, NULL); diff --git a/ras-aer-handler.c b/ras-aer-handler.c index 414d89e..bc6e774 100644 --- a/ras-aer-handler.c +++ b/ras-aer-handler.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #include #include #include diff --git a/ras-aer-handler.h b/ras-aer-handler.h index 4394921..cb99550 100644 --- a/ras-aer-handler.h +++ b/ras-aer-handler.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_AER_HANDLER_H #define __RAS_AER_HANDLER_H diff --git a/ras-arm-handler.c b/ras-arm-handler.c index c07d957..1fa510e 100644 --- a/ras-arm-handler.c +++ b/ras-arm-handler.c @@ -42,8 +42,9 @@ void display_raw_data(struct trace_seq *s, if (++line_count == 4) { trace_seq_printf(s, "\n %08x: ", i); line_count = 0; - } else + } else { trace_seq_printf(s, " "); + } } } diff --git a/ras-cpu-isolation.c b/ras-cpu-isolation.c index 8af31e9..2b37ebe 100644 --- a/ras-cpu-isolation.c +++ b/ras-cpu-isolation.c @@ -84,7 +84,7 @@ static int open_sys_file(unsigned int cpu, int __oflag, const char *format) char real_path[PATH_MAX] = ""; snprintf(path, sizeof(path), format, cpu); - if (strlen(path) > PATH_MAX || realpath(path, real_path) == NULL) { + if (strlen(path) > PATH_MAX || !realpath(path, real_path)) { log(TERM, LOG_ERR, "[%s]:open file: %s failed\n", __func__, path); return -1; } @@ -178,8 +178,9 @@ static int parse_ul_config(struct isolation_param *config, char *env, unsigned l return -1; } *value = DEC_CHECK * (*value) + (env[i] - '0'); - } else + } else { return -1; + } } if (!has_unit) @@ -391,15 +392,16 @@ void ras_record_cpu_error(struct error_info *err_info, int cpu) } ret = error_handler(cpu, err_info); - if (ret == HANDLE_NOTHING) + if (ret == HANDLE_NOTHING) { log(TERM, LOG_WARNING, "Doing nothing in the cpu%d\n", cpu); - else if (ret == HANDLE_SUCCEED) { + } else if (ret == HANDLE_SUCCEED) { log(TERM, LOG_INFO, "Offline cpu%d succeed, the state is %s\n", cpu, cpu_state[cpu_infos[cpu].state]); clear_queue(cpu_infos[cpu].ce_queue); cpu_infos[cpu].ce_nums = 0; cpu_infos[cpu].uce_nums = 0; - } else + } else { log(TERM, LOG_WARNING, "Offline cpu%d fail, the state is %s\n", cpu, cpu_state[cpu_infos[cpu].state]); + } } diff --git a/ras-cxl-handler.c b/ras-cxl-handler.c index 16a5f76..cbad347 100644 --- a/ras-cxl-handler.c +++ b/ras-cxl-handler.c @@ -99,7 +99,8 @@ 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 * const get_cxl_type_str(const char * const *type_array, + uint8_t num_elems, uint8_t type) { if (type >= num_elems) return "Unknown"; @@ -245,8 +246,11 @@ int ras_cxl_poison_event_handler(struct trace_seq *s, 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)); - } else - strncpy(ev.overflow_ts, "1970-01-01 00:00:00 +0000", 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) return -1; @@ -744,13 +748,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 * const cxl_gmer_mem_event_type[] = { "ECC Error", "Invalid Address", "Data Path Error", }; -static const char *cxl_gmer_trans_type[] = { +static const char * const cxl_gmer_trans_type[] = { "Unknown", "Host Read", "Host Write", @@ -799,8 +803,9 @@ int ras_cxl_general_media_event_handler(struct trace_seq *s, if (tep_get_field_val(s, event, "type", record, &val, 1) < 0) 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) + 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) return -1; if (tep_get_field_val(s, event, "transaction_type", record, &val, 1) < 0) @@ -903,7 +908,8 @@ int ras_cxl_dram_event_handler(struct trace_seq *s, ev.dpa_flags = val; if (trace_seq_printf(s, "dpa_flags:") <= 0) return -1; - if (decode_cxl_event_flags(s, ev.dpa_flags, cxl_dpa_flags, ARRAY_SIZE(cxl_dpa_flags)) < 0) + if (decode_cxl_event_flags(s, ev.dpa_flags, cxl_dpa_flags, + ARRAY_SIZE(cxl_dpa_flags)) < 0) return -1; if (tep_get_field_val(s, event, "descriptor", record, &val, 1) < 0) @@ -918,8 +924,10 @@ int ras_cxl_dram_event_handler(struct trace_seq *s, if (tep_get_field_val(s, event, "type", record, &val, 1) < 0) 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) + 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) return -1; if (tep_get_field_val(s, event, "transaction_type", record, &val, 1) < 0) @@ -1021,7 +1029,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 * const cxl_dev_evt_type[] = { "Health Status Change", "Media Status Change", "Life Used Change", @@ -1045,7 +1053,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 * const cxl_media_status[] = { "Normal", "Not Ready", "Write Persistency Lost", @@ -1058,21 +1066,21 @@ static const char *cxl_media_status[] = { "All Data Loss Imminent", }; -static const char *cxl_two_bit_status[] = { +static const char * const cxl_two_bit_status[] = { "Normal", "Warning", "Critical", }; -static const char *cxl_one_bit_status[] = { +static const char * const cxl_one_bit_status[] = { "Normal", "Warning", }; -#define CXL_DHI_AS_LIFE_USED(as) (as & 0x3) -#define CXL_DHI_AS_DEV_TEMP(as) ((as & 0xC) >> 2) -#define CXL_DHI_AS_COR_VOL_ERR_CNT(as) ((as & 0x10) >> 4) -#define CXL_DHI_AS_COR_PER_ERR_CNT(as) ((as & 0x20) >> 5) +#define CXL_DHI_AS_LIFE_USED(as) ((as) & 0x3) +#define CXL_DHI_AS_DEV_TEMP(as) (((as) & 0xC) >> 2) +#define CXL_DHI_AS_COR_VOL_ERR_CNT(as) (((as) & 0x10) >> 4) +#define CXL_DHI_AS_COR_PER_ERR_CNT(as) (((as) & 0x20) >> 5) int ras_cxl_memory_module_event_handler(struct trace_seq *s, struct tep_record *record, @@ -1089,8 +1097,10 @@ int ras_cxl_memory_module_event_handler(struct trace_seq *s, if (tep_get_field_val(s, event, "event_type", record, &val, 1) < 0) 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) + 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) return -1; if (tep_get_field_val(s, event, "health_status", record, &val, 1) < 0) @@ -1105,27 +1115,33 @@ int ras_cxl_memory_module_event_handler(struct trace_seq *s, if (tep_get_field_val(s, event, "media_status", record, &val, 1) < 0) 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) + if (trace_seq_printf(s, "media_status:%s ", + get_cxl_type_str(cxl_media_status, + 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), + if (trace_seq_printf(s, "as_life_used:%s ", + get_cxl_type_str(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), + if (trace_seq_printf(s, "as_dev_temp:%s ", + get_cxl_type_str(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), + 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), 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), + 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), 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 dcecc6d..e281cd0 100644 --- a/ras-devlink-handler.c +++ b/ras-devlink-handler.c @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ + #define _GNU_SOURCE #include #include diff --git a/ras-devlink-handler.h b/ras-devlink-handler.h index 39139e9..ccda865 100644 --- a/ras-devlink-handler.h +++ b/ras-devlink-handler.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_DEVLINK_HANDLER_H #define __RAS_DEVLINK_HANDLER_H diff --git a/ras-diskerror-handler.c b/ras-diskerror-handler.c index 02bb5a7..0fd27ae 100644 --- a/ras-diskerror-handler.c +++ b/ras-diskerror-handler.c @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ + #define _GNU_SOURCE #include #include diff --git a/ras-diskerror-handler.h b/ras-diskerror-handler.h index ba4c1ab..5f86a9e 100644 --- a/ras-diskerror-handler.h +++ b/ras-diskerror-handler.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_DISKERROR_HANDLER_H #define __RAS_DISKERROR_HANDLER_H diff --git a/ras-events.c b/ras-events.c index 7fe98c5..89896a0 100644 --- a/ras-events.c +++ b/ras-events.c @@ -14,36 +14,38 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ + #include #include #include #include +#include #include #include #include -#include -#include -#include #include -#include #include -#include +#include +#include #include -#include "ras-mc-handler.h" +#include +#include + #include "ras-aer-handler.h" -#include "ras-non-standard-handler.h" #include "ras-arm-handler.h" -#include "ras-mce-handler.h" -#include "ras-extlog-handler.h" +#include "ras-cpu-isolation.h" +#include "ras-cxl-handler.h" #include "ras-devlink-handler.h" #include "ras-diskerror-handler.h" -#include "ras-memory-failure-handler.h" -#include "ras-cxl-handler.h" -#include "ras-record.h" +#include "ras-extlog-handler.h" #include "ras-logger.h" +#include "ras-mce-handler.h" +#include "ras-mc-handler.h" +#include "ras-memory-failure-handler.h" +#include "ras-non-standard-handler.h" #include "ras-page-isolation.h" -#include "ras-cpu-isolation.h" +#include "ras-record.h" #include "trigger.h" /* @@ -105,7 +107,7 @@ static int get_debugfs_dir(char *tracing_dir, size_t len) fclose(fp); log(ALL, LOG_INFO, "Can't find debugfs\n"); - return ENOENT; + return -ENOENT; } static int open_trace(struct ras_events *ras, char *name, int flags) @@ -164,7 +166,8 @@ static int is_disabled_event(char *group, char *event) snprintf(ras_event_name, sizeof(ras_event_name), "%s:%s", group, event); - if (choices_disable && strlen(choices_disable) != 0 && strstr(choices_disable, ras_event_name)) { + if (choices_disable && strlen(choices_disable) != 0 && + strstr(choices_disable, ras_event_name)) { return 1; } return 0; @@ -519,9 +522,8 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata, do { ready = poll(fds, (n_cpus + 1), -1); - if (ready < 0) { + if (ready < 0) log(TERM, LOG_WARNING, "poll\n"); - } /* check for the signal */ if (fds[n_cpus].revents & POLLIN) { @@ -1139,7 +1141,7 @@ int handle_ras_events(int record_events) goto err; } - data = calloc(sizeof(*data), cpus); + data = calloc(cpus, sizeof(*data)); if (!data) goto err; diff --git a/ras-events.h b/ras-events.h index f3c53ca..75ca506 100644 --- a/ras-events.h +++ b/ras-events.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_EVENTS_H #define __RAS_EVENTS_H diff --git a/ras-extlog-handler.c b/ras-extlog-handler.c index e9e79f5..6ffe906 100644 --- a/ras-extlog-handler.c +++ b/ras-extlog-handler.c @@ -14,18 +14,20 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ + #include #include +#include #include #include #include #include -#include #include + #include "ras-extlog-handler.h" -#include "ras-record.h" #include "ras-logger.h" +#include "ras-record.h" #include "ras-report.h" static char *err_type(int etype) diff --git a/ras-extlog-handler.h b/ras-extlog-handler.h index ce72b4a..d9a7b1d 100644 --- a/ras-extlog-handler.h +++ b/ras-extlog-handler.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_EXTLOG_HANDLER_H #define __RAS_EXTLOG_HANDLER_H diff --git a/ras-logger.h b/ras-logger.h index 8cab83e..dbf1cb0 100644 --- a/ras-logger.h +++ b/ras-logger.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_LOGGER_H @@ -35,14 +35,14 @@ #define ALL (SYSLOG | TERM) /* TODO: global logging limit mask */ -#define log(where, level, fmt, args...) do {\ - if (where & SYSLOG)\ - syslog(level, fmt, ##args);\ - if (where & TERM) {\ - fprintf(stderr, "%s: ", TOOL_NAME);\ - fprintf(stderr, fmt, ##args);\ - fflush(stderr);\ - }\ +#define log(where, level, fmt, args...) do { \ + if ((where) & SYSLOG) \ + syslog(level, fmt, ##args); \ + if ((where) & TERM) { \ + fprintf(stderr, "%s: ", TOOL_NAME); \ + fprintf(stderr, fmt, ##args); \ + fflush(stderr); \ + } \ } while (0) #define __RAS_LOGGER_H diff --git a/ras-mc-handler.c b/ras-mc-handler.c index 7bc6c91..5062f9f 100644 --- a/ras-mc-handler.c +++ b/ras-mc-handler.c @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ + #define _GNU_SOURCE #include #include @@ -166,8 +167,8 @@ int ras_mc_event_handler(struct trace_seq *s, case HW_EVENT_ERR_FATAL: ev.error_type = "Fatal"; break; - default: case HW_EVENT_ERR_INFO: + default: ev.error_type = "Info"; } diff --git a/ras-mc-handler.h b/ras-mc-handler.h index a7637b2..c39fee3 100644 --- a/ras-mc-handler.h +++ b/ras-mc-handler.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_MC_HANDLER_H #define __RAS_MC_HANDLER_H diff --git a/ras-mce-handler.c b/ras-mce-handler.c index f58e291..fc08988 100644 --- a/ras-mce-handler.c +++ b/ras-mce-handler.c @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ + #include #include #include @@ -23,6 +24,7 @@ #include #include #include + #include "ras-mce-handler.h" #include "ras-record.h" #include "ras-logger.h" @@ -164,20 +166,19 @@ static int detect_cpu(struct mce_priv *mce) f = fopen("/proc/cpuinfo", "r"); if (!f) { log(ALL, LOG_INFO, "Can't open /proc/cpuinfo\n"); - return errno; + return -errno; } while (seen != CPU_ALL && getdelim(&line, &linelen, '\n', f) > 0) { - if (sscanf(line, "vendor_id : %63[^\n]", - (char *)&mce->vendor) == 1) + if (sscanf(line, "vendor_id : %63[^\n]", (char *)&mce->vendor) == 1) { seen |= CPU_VENDOR; - else if (sscanf(line, "cpu family : %d", &mce->family) == 1) + } else if (sscanf(line, "cpu family : %d", &mce->family) == 1) { seen |= CPU_FAMILY; - else if (sscanf(line, "model : %d", &mce->model) == 1) + } else if (sscanf(line, "model : %d", &mce->model) == 1) { seen |= CPU_MODEL; - else if (sscanf(line, "cpu MHz : %lf", &mce->mhz) == 1) + } else if (sscanf(line, "cpu MHz : %lf", &mce->mhz) == 1) { seen |= CPU_MHZ; - else if (!strncmp(line, "flags", 5) && isspace(line[6])) { + } else if (!strncmp(line, "flags", 5) && isspace(line[6])) { if (mce->processor_flags) free(mce->processor_flags); mce->processor_flags = line; @@ -187,7 +188,8 @@ static int detect_cpu(struct mce_priv *mce) } } if (!seen) { - log(ALL, LOG_INFO, "Can't find a x86 CPU at /proc/cpuinfo. Disabling MCE handler.\n"); + log(ALL, LOG_INFO, + "Can't find a x86 CPU at /proc/cpuinfo. Disabling MCE handler.\n"); ret = -ENOENT; goto ret; } @@ -199,7 +201,7 @@ static int detect_cpu(struct mce_priv *mce) (seen & CPU_MODEL) ? "" : " [model]", (seen & CPU_MHZ) ? "" : " [cpu MHz]", (seen & CPU_FLAGS) ? "" : " [flags]"); - ret = EINVAL; + ret = -EINVAL; goto ret; } @@ -217,18 +219,18 @@ static int detect_cpu(struct mce_priv *mce) log(ALL, LOG_INFO, "Can't parse MCE for this AMD CPU yet %d\n", mce->family); - ret = EINVAL; + ret = -EINVAL; } goto ret; } else if (!strcmp(mce->vendor, "HygonGenuine")) { - if (mce->family == 24) { + if (mce->family == 24) mce->cputype = CPU_DHYANA; - } + goto ret; } else if (!strcmp(mce->vendor, "GenuineIntel")) { mce->cputype = select_intel_cputype(mce); } else { - ret = EINVAL; + ret = -EINVAL; } ret: @@ -257,7 +259,7 @@ int register_mce_handler(struct ras_events *ras, unsigned int ncpus) free(mce->processor_flags); free(ras->mce_priv); ras->mce_priv = NULL; - return (rc); + return rc; } switch (mce->cputype) { case CPU_SANDY_BRIDGE_EP: diff --git a/ras-mce-handler.h b/ras-mce-handler.h index 407ee45..74d913a 100644 --- a/ras-mce-handler.h +++ b/ras-mce-handler.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_MCE_HANDLER_H #define __RAS_MCE_HANDLER_H diff --git a/ras-memory-failure-handler.h b/ras-memory-failure-handler.h index 7fbfd33..e299eae 100644 --- a/ras-memory-failure-handler.h +++ b/ras-memory-failure-handler.h @@ -10,7 +10,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -*/ + */ #ifndef __RAS_MEMORY_FAILURE_HANDLER_H #define __RAS_MEMORY_FAILURE_HANDLER_H diff --git a/ras-non-standard-handler.c b/ras-non-standard-handler.c index e21455a..19dd0c9 100644 --- a/ras-non-standard-handler.c +++ b/ras-non-standard-handler.c @@ -26,7 +26,9 @@ static struct ras_ns_ev_decoder *ras_ns_ev_dec_list; void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index) { - trace_seq_printf(s, "%02x%02x%02x%02x", buf[index + 3], buf[index + 2], buf[index + 1], buf[index]); + trace_seq_printf(s, "%02x%02x%02x%02x", + buf[index + 3], buf[index + 2], + buf[index + 1], buf[index]); } static char *uuid_le(const char *uu) @@ -253,8 +255,9 @@ int ras_non_standard_event_handler(struct trace_seq *s, if (++line_count == 4) { trace_seq_printf(s, "\n %08x: ", i); line_count = 0; - } else + } else { trace_seq_printf(s, " "); + } } } diff --git a/ras-page-isolation.c b/ras-page-isolation.c index 89f8c15..4ef3cae 100644 --- a/ras-page-isolation.c +++ b/ras-page-isolation.c @@ -10,16 +10,17 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -*/ + */ #include +#include +#include #include -#include #include -#include +#include #include -#include -#include +#include + #include "ras-logger.h" #include "ras-page-isolation.h" @@ -53,7 +54,7 @@ static struct isolation cycle = { .unit = "h", }; -static const char *kernel_offline[] = { +static const char * const kernel_offline[] = { [OFFLINE_SOFT] = "/sys/devices/system/memory/soft_offline_page", [OFFLINE_HARD] = "/sys/devices/system/memory/hard_offline_page", [OFFLINE_SOFT_THEN_HARD] = "/sys/devices/system/memory/soft_offline_page", @@ -68,7 +69,7 @@ static const struct config offline_choice[] = { {} }; -static const char *page_state[] = { +static const char * const page_state[] = { [PAGE_ONLINE] = "online", [PAGE_OFFLINE] = "offlined", [PAGE_OFFLINE_FAILED] = "offline-failed", @@ -150,8 +151,8 @@ parse: if (!no_unit) config->unit = unit; } else { - log(TERM, LOG_INFO, "Improper %s, set to default %s.\n", - config->name, config->env); + log(TERM, LOG_INFO, "Improper %s, set to default %s.\n", + config->name, config->env); } /* if env value string is greater than ulong_max, truncate the last digit */ @@ -219,15 +220,18 @@ static int do_page_offline(unsigned long long addr, enum otype type) fd = open(kernel_offline[type], O_WRONLY); if (fd == -1) { - log(TERM, LOG_ERR, "[%s]:open file: %s failed\n", __func__, kernel_offline[type]); + log(TERM, LOG_ERR, "[%s]:open file: %s failed\n", __func__, + kernel_offline[type]); return -1; } sprintf(buf, "%#llx", addr); rc = write(fd, buf, strlen(buf)); - if (rc < 0) { - log(TERM, LOG_ERR, "page offline addr(%s) by %s failed, errno:%d\n", buf, kernel_offline[type], errno); - } + if (rc < 0) + log(TERM, LOG_ERR, + "page offline addr(%s) by %s failed, errno:%d\n", + buf, kernel_offline[type], errno); + close(fd); return rc; } @@ -307,13 +311,12 @@ static struct page_record *page_lookup_insert(unsigned long long addr) while (*entry) { parent = *entry; pr = rb_entry(parent, struct page_record, entry); - if (addr == pr->addr) { + if (addr == pr->addr) return pr; - } else if (addr < pr->addr) { + else if (addr < pr->addr) entry = &(*entry)->rb_left; - } else { + else entry = &(*entry)->rb_right; - } } find = calloc(1, sizeof(struct page_record)); diff --git a/ras-page-isolation.h b/ras-page-isolation.h index 0482e1e..7ccfca1 100644 --- a/ras-page-isolation.h +++ b/ras-page-isolation.h @@ -10,7 +10,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -*/ + */ #ifndef __RAS_PAGE_ISOLATION_H #define __RAS_PAGE_ISOLATION_H diff --git a/ras-record.c b/ras-record.c index 56c25cb..490934e 100644 --- a/ras-record.c +++ b/ras-record.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ /* * BuildRequires: sqlite-devel @@ -885,7 +885,8 @@ static const struct db_table_descriptor cxl_general_media_event_tab = { .num_fields = ARRAY_SIZE(cxl_general_media_event_fields), }; -int ras_store_cxl_general_media_event(struct ras_events *ras, struct ras_cxl_general_media_event *ev) +int ras_store_cxl_general_media_event(struct ras_events *ras, + struct ras_cxl_general_media_event *ev) { int rc; struct sqlite3_priv *priv = ras->db_priv; @@ -1031,7 +1032,8 @@ static const struct db_table_descriptor cxl_memory_module_event_tab = { .num_fields = ARRAY_SIZE(cxl_memory_module_event_fields), }; -int ras_store_cxl_memory_module_event(struct ras_events *ras, struct ras_cxl_memory_module_event *ev) +int ras_store_cxl_memory_module_event(struct ras_events *ras, + struct ras_cxl_memory_module_event *ev) { int rc; struct sqlite3_priv *priv = ras->db_priv; diff --git a/ras-record.h b/ras-record.h index c3738ba..e8ed263 100644 --- a/ras-record.h +++ b/ras-record.h @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ #ifndef __RAS_RECORD_H #define __RAS_RECORD_H @@ -321,41 +321,71 @@ int ras_mc_finalize_vendor_table(sqlite3_stmt *stmt); int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev); int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev); int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev); -int ras_store_extlog_mem_record(struct ras_events *ras, struct ras_extlog_event *ev); -int ras_store_non_standard_record(struct ras_events *ras, struct ras_non_standard_event *ev); +int ras_store_extlog_mem_record(struct ras_events *ras, + struct ras_extlog_event *ev); +int ras_store_non_standard_record(struct ras_events *ras, + struct ras_non_standard_event *ev); int ras_store_arm_record(struct ras_events *ras, struct ras_arm_event *ev); int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev); -int ras_store_diskerror_event(struct ras_events *ras, struct diskerror_event *ev); +int ras_store_diskerror_event(struct ras_events *ras, + struct diskerror_event *ev); int ras_store_mf_event(struct ras_events *ras, struct ras_mf_event *ev); -int ras_store_cxl_poison_event(struct ras_events *ras, struct ras_cxl_poison_event *ev); -int ras_store_cxl_aer_ue_event(struct ras_events *ras, struct ras_cxl_aer_ue_event *ev); -int ras_store_cxl_aer_ce_event(struct ras_events *ras, struct ras_cxl_aer_ce_event *ev); -int ras_store_cxl_overflow_event(struct ras_events *ras, struct ras_cxl_overflow_event *ev); -int ras_store_cxl_generic_event(struct ras_events *ras, struct ras_cxl_generic_event *ev); -int ras_store_cxl_general_media_event(struct ras_events *ras, struct ras_cxl_general_media_event *ev); -int ras_store_cxl_dram_event(struct ras_events *ras, struct ras_cxl_dram_event *ev); -int ras_store_cxl_memory_module_event(struct ras_events *ras, struct ras_cxl_memory_module_event *ev); +int ras_store_cxl_poison_event(struct ras_events *ras, + struct ras_cxl_poison_event *ev); +int ras_store_cxl_aer_ue_event(struct ras_events *ras, + struct ras_cxl_aer_ue_event *ev); +int ras_store_cxl_aer_ce_event(struct ras_events *ras, + struct ras_cxl_aer_ce_event *ev); +int ras_store_cxl_overflow_event(struct ras_events *ras, + struct ras_cxl_overflow_event *ev); +int ras_store_cxl_generic_event(struct ras_events *ras, + struct ras_cxl_generic_event *ev); +int ras_store_cxl_general_media_event(struct ras_events *ras, + struct ras_cxl_general_media_event *ev); +int ras_store_cxl_dram_event(struct ras_events *ras, + struct ras_cxl_dram_event *ev); +int ras_store_cxl_memory_module_event(struct ras_events *ras, + struct ras_cxl_memory_module_event *ev); #else -static inline int ras_mc_event_opendb(unsigned int cpu, struct ras_events *ras) { return 0; }; -static inline int ras_mc_event_closedb(unsigned int cpu, struct ras_events *ras) { return 0; }; -static inline int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev) { return 0; }; -static inline int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev) { return 0; }; -static inline int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev) { return 0; }; -static inline int ras_store_extlog_mem_record(struct ras_events *ras, struct ras_extlog_event *ev) { return 0; }; -static inline int ras_store_non_standard_record(struct ras_events *ras, struct ras_non_standard_event *ev) { return 0; }; -static inline int ras_store_arm_record(struct ras_events *ras, struct ras_arm_event *ev) { return 0; }; -static inline int ras_store_devlink_event(struct ras_events *ras, struct devlink_event *ev) { return 0; }; -static inline int ras_store_diskerror_event(struct ras_events *ras, struct diskerror_event *ev) { return 0; }; -static inline int ras_store_mf_event(struct ras_events *ras, struct ras_mf_event *ev) { return 0; }; -static inline int ras_store_cxl_poison_event(struct ras_events *ras, struct ras_cxl_poison_event *ev) { return 0; }; -static inline int ras_store_cxl_aer_ue_event(struct ras_events *ras, struct ras_cxl_aer_ue_event *ev) { return 0; }; -static inline int ras_store_cxl_aer_ce_event(struct ras_events *ras, struct ras_cxl_aer_ce_event *ev) { return 0; }; -static inline int ras_store_cxl_overflow_event(struct ras_events *ras, struct ras_cxl_overflow_event *ev) { return 0; }; -static inline int ras_store_cxl_generic_event(struct ras_events *ras, struct ras_cxl_generic_event *ev) { return 0; }; -static inline int ras_store_cxl_general_media_event(struct ras_events *ras, struct ras_cxl_general_media_event *ev) { return 0; }; -static inline int ras_store_cxl_dram_event(struct ras_events *ras, struct ras_cxl_dram_event *ev) { return 0; }; -static inline int ras_store_cxl_memory_module_event(struct ras_events *ras, struct ras_cxl_memory_module_event *ev) { return 0; }; +static inline int ras_mc_event_opendb(unsigned int cpu, + struct ras_events *ras) { return 0; }; +static inline int ras_mc_event_closedb(unsigned int cpu, + struct ras_events *ras) { return 0; }; +static inline int ras_store_mc_event(struct ras_events *ras, + struct ras_mc_event *ev) { return 0; }; +static inline int ras_store_aer_event(struct ras_events *ras, + struct ras_aer_event *ev) { return 0; }; +static inline int ras_store_mce_record(struct ras_events *ras, + struct mce_event *ev) { return 0; }; +static inline int ras_store_extlog_mem_record(struct ras_events *ras, + struct ras_extlog_event *ev) { return 0; }; +static inline int ras_store_non_standard_record(struct ras_events *ras, + struct ras_non_standard_event *ev) { return 0; }; +static inline int ras_store_arm_record(struct ras_events *ras, + struct ras_arm_event *ev) { return 0; }; +static inline int ras_store_devlink_event(struct ras_events *ras, + struct devlink_event *ev) { return 0; }; +static inline int ras_store_diskerror_event(struct ras_events *ras, + struct diskerror_event *ev) { return 0; }; +static inline int ras_store_mf_event(struct ras_events *ras, + struct ras_mf_event *ev) { return 0; }; +static inline int ras_store_cxl_poison_event(struct ras_events *ras, + struct ras_cxl_poison_event *ev) { return 0; }; +static inline int ras_store_cxl_aer_ue_event(struct ras_events *ras, + struct ras_cxl_aer_ue_event *ev) { return 0; }; +static inline int ras_store_cxl_aer_ce_event(struct ras_events *ras, + struct ras_cxl_aer_ce_event *ev) { return 0; }; +static inline int ras_store_cxl_overflow_event(struct ras_events *ras, + struct ras_cxl_overflow_event *ev) { return 0; }; +static inline int ras_store_cxl_generic_event(struct ras_events *ras, + struct ras_cxl_generic_event *ev) { return 0; }; +static inline int ras_store_cxl_general_media_event(struct ras_events *ras, + struct ras_cxl_general_media_event *ev) { return 0; }; +static inline int ras_store_cxl_dram_event(struct ras_events *ras, + struct ras_cxl_dram_event *ev) { return 0; }; +static inline int ras_store_cxl_memory_module_event(struct ras_events *ras, + struct ras_cxl_memory_module_event *ev) { return 0; }; #endif diff --git a/ras-report.c b/ras-report.c index 5cc55b6..cf841ec 100644 --- a/ras-report.c +++ b/ras-report.c @@ -28,9 +28,8 @@ static int setup_report_socket(void) struct sockaddr_un addr; sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd < 0) { + if (sockfd < 0) return -1; - } memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; @@ -52,44 +51,38 @@ static int commit_report_basic(int sockfd) struct utsname un; int rc = -1; - if (sockfd < 0) { + if (sockfd < 0) return rc; - } memset(buf, 0, INPUT_BUFFER_SIZE); memset(&un, 0, sizeof(struct utsname)); rc = uname(&un); - if (rc < 0) { + if (rc < 0) return rc; - } /* * ABRT server protocol */ sprintf(buf, "PUT / HTTP/1.1\r\n\r\n"); rc = write(sockfd, buf, strlen(buf)); - if (rc < strlen(buf)) { + if (rc < strlen(buf)) return -1; - } sprintf(buf, "PID=%d", (int)getpid()); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) return -1; - } sprintf(buf, "EXECUTABLE=/boot/vmlinuz-%s", un.release); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) return -1; - } sprintf(buf, "TYPE=%s", "ras"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) return -1; - } return 0; } @@ -101,33 +94,33 @@ static int set_mc_event_backtrace(char *buf, struct ras_mc_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "error_count=%d\n" \ - "error_type=%s\n" \ - "msg=%s\n" \ - "label=%s\n" \ - "mc_index=%c\n" \ - "top_layer=%c\n" \ - "middle_layer=%c\n" \ - "lower_layer=%c\n" \ - "address=%llu\n" \ - "grain=%llu\n" \ - "syndrome=%llu\n" \ - "driver_detail=%s\n", \ - ev->timestamp, \ - ev->error_count, \ - ev->error_type, \ - ev->msg, \ - ev->label, \ - ev->mc_index, \ - ev->top_layer, \ - ev->middle_layer, \ - ev->lower_layer, \ - ev->address, \ - ev->grain, \ - ev->syndrome, \ - ev->driver_detail); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "error_count=%d\n" + "error_type=%s\n" + "msg=%s\n" + "label=%s\n" + "mc_index=%c\n" + "top_layer=%c\n" + "middle_layer=%c\n" + "lower_layer=%c\n" + "address=%llu\n" + "grain=%llu\n" + "syndrome=%llu\n" + "driver_detail=%s\n", + ev->timestamp, + ev->error_count, + ev->error_type, + ev->msg, + ev->label, + ev->mc_index, + ev->top_layer, + ev->middle_layer, + ev->lower_layer, + ev->address, + ev->grain, + ev->syndrome, + ev->driver_detail); strcat(buf, bt_buf); @@ -141,53 +134,53 @@ static int set_mce_event_backtrace(char *buf, struct mce_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "bank_name=%s\n" \ - "error_msg=%s\n" \ - "mcgstatus_msg=%s\n" \ - "mcistatus_msg=%s\n" \ - "mcastatus_msg=%s\n" \ - "user_action=%s\n" \ - "mc_location=%s\n" \ - "mcgcap=%lu\n" \ - "mcgstatus=%lu\n" \ - "status=%lu\n" \ - "addr=%lu\n" \ - "misc=%lu\n" \ - "ip=%lu\n" \ - "tsc=%lu\n" \ - "walltime=%lu\n" \ - "cpu=%u\n" \ - "cpuid=%u\n" \ - "apicid=%u\n" \ - "socketid=%u\n" \ - "cs=%d\n" \ - "bank=%d\n" \ - "cpuvendor=%d\n", \ - ev->timestamp, \ - ev->bank_name, \ - ev->error_msg, \ - ev->mcgstatus_msg, \ - ev->mcistatus_msg, \ - ev->mcastatus_msg, \ - ev->user_action, \ - ev->mc_location, \ - ev->mcgcap, \ - ev->mcgstatus, \ - ev->status, \ - ev->addr, \ - ev->misc, \ - ev->ip, \ - ev->tsc, \ - ev->walltime, \ - ev->cpu, \ - ev->cpuid, \ - ev->apicid, \ - ev->socketid, \ - ev->cs, \ - ev->bank, \ - ev->cpuvendor); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "bank_name=%s\n" + "error_msg=%s\n" + "mcgstatus_msg=%s\n" + "mcistatus_msg=%s\n" + "mcastatus_msg=%s\n" + "user_action=%s\n" + "mc_location=%s\n" + "mcgcap=%lu\n" + "mcgstatus=%lu\n" + "status=%lu\n" + "addr=%lu\n" + "misc=%lu\n" + "ip=%lu\n" + "tsc=%lu\n" + "walltime=%lu\n" + "cpu=%u\n" + "cpuid=%u\n" + "apicid=%u\n" + "socketid=%u\n" + "cs=%d\n" + "bank=%d\n" + "cpuvendor=%d\n", + ev->timestamp, + ev->bank_name, + ev->error_msg, + ev->mcgstatus_msg, + ev->mcistatus_msg, + ev->mcastatus_msg, + ev->user_action, + ev->mc_location, + ev->mcgcap, + ev->mcgstatus, + ev->status, + ev->addr, + ev->misc, + ev->ip, + ev->tsc, + ev->walltime, + ev->cpu, + ev->cpuid, + ev->apicid, + ev->socketid, + ev->cs, + ev->bank, + ev->cpuvendor); strcat(buf, bt_buf); @@ -201,15 +194,15 @@ static int set_aer_event_backtrace(char *buf, struct ras_aer_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "error_type=%s\n" \ - "dev_name=%s\n" \ - "msg=%s\n", \ - ev->timestamp, \ - ev->error_type, \ - ev->dev_name, \ - ev->msg); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "error_type=%s\n" + "dev_name=%s\n" + "msg=%s\n", + ev->timestamp, + ev->error_type, + ev->dev_name, + ev->msg); strcat(buf, bt_buf); @@ -223,13 +216,13 @@ static int set_non_standard_event_backtrace(char *buf, struct ras_non_standard_e if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "severity=%s\n" \ - "length=%d\n", \ - ev->timestamp, \ - ev->severity, \ - ev->length); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "severity=%s\n" + "length=%d\n", + ev->timestamp, + ev->severity, + ev->length); strcat(buf, bt_buf); @@ -243,21 +236,21 @@ static int set_arm_event_backtrace(char *buf, struct ras_arm_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "error_count=%d\n" \ - "affinity=%d\n" \ - "mpidr=0x%lx\n" \ - "midr=0x%lx\n" \ - "running_state=%d\n" \ - "psci_state=%d\n", \ - ev->timestamp, \ - ev->error_count, \ - ev->affinity, \ - ev->mpidr, \ - ev->midr, \ - ev->running_state, \ - ev->psci_state); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "error_count=%d\n" + "affinity=%d\n" + "mpidr=0x%lx\n" + "midr=0x%lx\n" + "running_state=%d\n" + "psci_state=%d\n", + ev->timestamp, + ev->error_count, + ev->affinity, + ev->mpidr, + ev->midr, + ev->running_state, + ev->psci_state); strcat(buf, bt_buf); @@ -271,19 +264,19 @@ static int set_devlink_event_backtrace(char *buf, struct devlink_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "bus_name=%s\n" \ - "dev_name=%s\n" \ - "driver_name=%s\n" \ - "reporter_name=%s\n" \ - "msg=%s\n", \ - ev->timestamp, \ - ev->bus_name, \ - ev->dev_name, \ - ev->driver_name, \ - ev->reporter_name, \ - ev->msg); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "bus_name=%s\n" + "dev_name=%s\n" + "driver_name=%s\n" + "reporter_name=%s\n" + "msg=%s\n", + ev->timestamp, + ev->bus_name, + ev->dev_name, + ev->driver_name, + ev->reporter_name, + ev->msg); strcat(buf, bt_buf); @@ -297,21 +290,21 @@ static int set_diskerror_event_backtrace(char *buf, struct diskerror_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "dev=%s\n" \ - "sector=%llu\n" \ - "nr_sector=%u\n" \ - "error=%s\n" \ - "rwbs=%s\n" \ - "cmd=%s\n", \ - ev->timestamp, \ - ev->dev, \ - ev->sector, \ - ev->nr_sector, \ - ev->error, \ - ev->rwbs, \ - ev->cmd); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "dev=%s\n" + "sector=%llu\n" + "nr_sector=%u\n" + "error=%s\n" + "rwbs=%s\n" + "cmd=%s\n", + ev->timestamp, + ev->dev, + ev->sector, + ev->nr_sector, + ev->error, + ev->rwbs, + ev->cmd); strcat(buf, bt_buf); @@ -325,15 +318,15 @@ static int set_mf_event_backtrace(char *buf, struct ras_mf_event *ev) if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "pfn=%s\n" \ - "page_type=%s\n" \ - "action_result=%s\n", \ - ev->timestamp, \ - ev->pfn, \ - ev->page_type, \ - ev->action_result); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "pfn=%s\n" + "page_type=%s\n" + "action_result=%s\n", + ev->timestamp, + ev->pfn, + ev->page_type, + ev->action_result); strcat(buf, bt_buf); @@ -347,33 +340,33 @@ static int set_cxl_poison_event_backtrace(char *buf, struct ras_cxl_poison_event if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "trace_type=%s\n" \ - "region=%s\n" \ - "region_uuid=%s\n" \ - "hpa=0x%lx\n" \ - "dpa=0x%lx\n" \ - "dpa_length=0x%x\n" \ - "source=%s\n" \ - "flags=%u\n" \ - "overflow_timestamp=%s\n", \ - ev->timestamp, \ - ev->memdev, \ - ev->host, \ - ev->serial, \ - ev->trace_type, \ - ev->region, \ - ev->uuid, \ - ev->hpa, \ - ev->dpa, \ - ev->dpa_length, \ - ev->source, \ - ev->flags, \ - ev->overflow_ts); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "trace_type=%s\n" + "region=%s\n" + "region_uuid=%s\n" + "hpa=0x%lx\n" + "dpa=0x%lx\n" + "dpa_length=0x%x\n" + "source=%s\n" + "flags=%u\n" + "overflow_timestamp=%s\n", + ev->timestamp, + ev->memdev, + ev->host, + ev->serial, + ev->trace_type, + ev->region, + ev->uuid, + ev->hpa, + ev->dpa, + ev->dpa_length, + ev->source, + ev->flags, + ev->overflow_ts); strcat(buf, bt_buf); @@ -387,19 +380,19 @@ static int set_cxl_aer_ue_event_backtrace(char *buf, struct ras_cxl_aer_ue_event if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "error_status=%u\n" \ - "first_error=%u\n", \ - ev->timestamp, \ - ev->memdev, \ - ev->host, \ - ev->serial, \ - ev->error_status, \ - ev->first_error); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "error_status=%u\n" + "first_error=%u\n", + ev->timestamp, + ev->memdev, + ev->host, + ev->serial, + ev->error_status, + ev->first_error); strcat(buf, bt_buf); @@ -413,17 +406,17 @@ static int set_cxl_aer_ce_event_backtrace(char *buf, struct ras_cxl_aer_ce_event if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "error_status=%u\n", \ - ev->timestamp, \ - ev->memdev, \ - ev->host, \ - ev->serial, \ - ev->error_status); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "error_status=%u\n", + ev->timestamp, + ev->memdev, + ev->host, + ev->serial, + ev->error_status); strcat(buf, bt_buf); @@ -437,23 +430,23 @@ static int set_cxl_overflow_event_backtrace(char *buf, struct ras_cxl_overflow_e if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "log_type=%s\n" \ - "count=%u\n" \ - "first_ts=%s\n" \ - "last_ts=%s\n", \ - ev->timestamp, \ - ev->memdev, \ - ev->host, \ - ev->serial, \ - ev->log_type, \ - ev->count, \ - ev->first_ts, \ - ev->last_ts); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "log_type=%s\n" + "count=%u\n" + "first_ts=%s\n" + "last_ts=%s\n", + ev->timestamp, + ev->memdev, + ev->host, + ev->serial, + ev->log_type, + ev->count, + ev->first_ts, + ev->last_ts); strcat(buf, bt_buf); @@ -467,31 +460,31 @@ static int set_cxl_generic_event_backtrace(char *buf, struct ras_cxl_generic_eve if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "log_type=%s\n" \ - "hdr_uuid=%s\n" \ - "hdr_flags=0x%x\n" \ - "hdr_handle=0x%x\n" \ - "hdr_related_handle=0x%x\n" \ - "hdr_timestamp=%s\n" \ - "hdr_length=%u\n" \ - "hdr_maint_op_class=%u\n", \ - ev->hdr.timestamp, \ - ev->hdr.memdev, \ - ev->hdr.host, \ - ev->hdr.serial, \ - ev->hdr.log_type, \ - ev->hdr.hdr_uuid, \ - ev->hdr.hdr_flags, \ - ev->hdr.hdr_handle, \ - ev->hdr.hdr_related_handle, \ - ev->hdr.hdr_timestamp, \ - ev->hdr.hdr_length, \ - ev->hdr.hdr_maint_op_class); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "log_type=%s\n" + "hdr_uuid=%s\n" + "hdr_flags=0x%x\n" + "hdr_handle=0x%x\n" + "hdr_related_handle=0x%x\n" + "hdr_timestamp=%s\n" + "hdr_length=%u\n" + "hdr_maint_op_class=%u\n", + ev->hdr.timestamp, + ev->hdr.memdev, + ev->hdr.host, + ev->hdr.serial, + ev->hdr.log_type, + ev->hdr.hdr_uuid, + ev->hdr.hdr_flags, + ev->hdr.hdr_handle, + ev->hdr.hdr_related_handle, + ev->hdr.hdr_timestamp, + ev->hdr.hdr_length, + ev->hdr.hdr_maint_op_class); strcat(buf, bt_buf); @@ -505,47 +498,47 @@ static int set_cxl_general_media_event_backtrace(char *buf, struct ras_cxl_gener if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "log_type=%s\n" \ - "hdr_uuid=%s\n" \ - "hdr_flags=0x%x\n" \ - "hdr_handle=0x%x\n" \ - "hdr_related_handle=0x%x\n" \ - "hdr_timestamp=%s\n" \ - "hdr_length=%u\n" \ - "hdr_maint_op_class=%u\n" \ - "dpa=0x%lx\n" \ - "dpa_flags=%u\n" \ - "descriptor=%u\n" \ - "type=%u\n" \ - "transaction_type=%u\n" \ - "channel=%u\n" \ - "rank=%u\n" \ - "device=0x%x\n", \ - ev->hdr.timestamp, \ - ev->hdr.memdev, \ - ev->hdr.host, \ - ev->hdr.serial, \ - ev->hdr.log_type, \ - ev->hdr.hdr_uuid, \ - ev->hdr.hdr_flags, \ - ev->hdr.hdr_handle, \ - ev->hdr.hdr_related_handle, \ - ev->hdr.hdr_timestamp, \ - ev->hdr.hdr_length, \ - ev->hdr.hdr_maint_op_class, \ - ev->dpa, \ - ev->dpa_flags, \ - ev->descriptor, \ - ev->type, \ - ev->transaction_type, \ - ev->channel, \ - ev->rank, \ - ev->device); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "log_type=%s\n" + "hdr_uuid=%s\n" + "hdr_flags=0x%x\n" + "hdr_handle=0x%x\n" + "hdr_related_handle=0x%x\n" + "hdr_timestamp=%s\n" + "hdr_length=%u\n" + "hdr_maint_op_class=%u\n" + "dpa=0x%lx\n" + "dpa_flags=%u\n" + "descriptor=%u\n" + "type=%u\n" + "transaction_type=%u\n" + "channel=%u\n" + "rank=%u\n" + "device=0x%x\n", + ev->hdr.timestamp, + ev->hdr.memdev, + ev->hdr.host, + ev->hdr.serial, + ev->hdr.log_type, + ev->hdr.hdr_uuid, + ev->hdr.hdr_flags, + ev->hdr.hdr_handle, + ev->hdr.hdr_related_handle, + ev->hdr.hdr_timestamp, + ev->hdr.hdr_length, + ev->hdr.hdr_maint_op_class, + ev->dpa, + ev->dpa_flags, + ev->descriptor, + ev->type, + ev->transaction_type, + ev->channel, + ev->rank, + ev->device); strcat(buf, bt_buf); @@ -559,55 +552,55 @@ static int set_cxl_dram_event_backtrace(char *buf, struct ras_cxl_dram_event *ev if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "log_type=%s\n" \ - "hdr_uuid=%s\n" \ - "hdr_flags=0x%x\n" \ - "hdr_handle=0x%x\n" \ - "hdr_related_handle=0x%x\n" \ - "hdr_timestamp=%s\n" \ - "hdr_length=%u\n" \ - "hdr_maint_op_class=%u\n" \ - "dpa=0x%lx\n" \ - "dpa_flags=%u\n" \ - "descriptor=%u\n" \ - "type=%u\n" \ - "transaction_type=%u\n" \ - "channel=%u\n" \ - "rank=%u\n" \ - "nibble_mask=%u\n" \ - "bank_group=%u\n" \ - "bank=%u\n" \ - "row=%u\n" \ - "column=%u\n", \ - ev->hdr.timestamp, \ - ev->hdr.memdev, \ - ev->hdr.host, \ - ev->hdr.serial, \ - ev->hdr.log_type, \ - ev->hdr.hdr_uuid, \ - ev->hdr.hdr_flags, \ - ev->hdr.hdr_handle, \ - ev->hdr.hdr_related_handle, \ - ev->hdr.hdr_timestamp, \ - ev->hdr.hdr_length, \ - ev->hdr.hdr_maint_op_class, \ - ev->dpa, \ - ev->dpa_flags, \ - ev->descriptor, \ - ev->type, \ - ev->transaction_type, \ - ev->channel, \ - ev->rank, \ - ev->nibble_mask, \ - ev->bank_group, \ - ev->bank, \ - ev->row, \ - ev->column); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "log_type=%s\n" + "hdr_uuid=%s\n" + "hdr_flags=0x%x\n" + "hdr_handle=0x%x\n" + "hdr_related_handle=0x%x\n" + "hdr_timestamp=%s\n" + "hdr_length=%u\n" + "hdr_maint_op_class=%u\n" + "dpa=0x%lx\n" + "dpa_flags=%u\n" + "descriptor=%u\n" + "type=%u\n" + "transaction_type=%u\n" + "channel=%u\n" + "rank=%u\n" + "nibble_mask=%u\n" + "bank_group=%u\n" + "bank=%u\n" + "row=%u\n" + "column=%u\n", + ev->hdr.timestamp, + ev->hdr.memdev, + ev->hdr.host, + ev->hdr.serial, + ev->hdr.log_type, + ev->hdr.hdr_uuid, + ev->hdr.hdr_flags, + ev->hdr.hdr_handle, + ev->hdr.hdr_related_handle, + ev->hdr.hdr_timestamp, + ev->hdr.hdr_length, + ev->hdr.hdr_maint_op_class, + ev->dpa, + ev->dpa_flags, + ev->descriptor, + ev->type, + ev->transaction_type, + ev->channel, + ev->rank, + ev->nibble_mask, + ev->bank_group, + ev->bank, + ev->row, + ev->column); strcat(buf, bt_buf); @@ -621,49 +614,49 @@ static int set_cxl_memory_module_event_backtrace(char *buf, struct ras_cxl_memor if (!buf || !ev) return -1; - sprintf(bt_buf, "BACKTRACE=" \ - "timestamp=%s\n" \ - "memdev=%s\n" \ - "host=%s\n" \ - "serial=0x%lx\n" \ - "log_type=%s\n" \ - "hdr_uuid=%s\n" \ - "hdr_flags=0x%x\n" \ - "hdr_handle=0x%x\n" \ - "hdr_related_handle=0x%x\n" \ - "hdr_timestamp=%s\n" \ - "hdr_length=%u\n" \ - "hdr_maint_op_class=%u\n" \ - "event_type=%u\n" \ - "health_status=%u\n" \ - "media_status=%u\n" \ - "life_used=%u\n" \ - "dirty_shutdown_cnt=%u\n" \ - "cor_vol_err_cnt=%u\n" \ - "cor_per_err_cnt=%u\n" \ - "device_temp=%d\n" \ - "add_status=%u\n", \ - ev->hdr.timestamp, \ - ev->hdr.memdev, \ - ev->hdr.host, \ - ev->hdr.serial, \ - ev->hdr.log_type, \ - ev->hdr.hdr_uuid, \ - ev->hdr.hdr_flags, \ - ev->hdr.hdr_handle, \ - ev->hdr.hdr_related_handle, \ - ev->hdr.hdr_timestamp, \ - ev->hdr.hdr_length, \ - ev->hdr.hdr_maint_op_class, \ - ev->event_type, \ - ev->health_status, \ - ev->media_status, \ - ev->life_used, \ - ev->dirty_shutdown_cnt, \ - ev->cor_vol_err_cnt, \ - ev->cor_per_err_cnt, \ - ev->device_temp, \ - ev->add_status); + sprintf(bt_buf, "BACKTRACE=" + "timestamp=%s\n" + "memdev=%s\n" + "host=%s\n" + "serial=0x%lx\n" + "log_type=%s\n" + "hdr_uuid=%s\n" + "hdr_flags=0x%x\n" + "hdr_handle=0x%x\n" + "hdr_related_handle=0x%x\n" + "hdr_timestamp=%s\n" + "hdr_length=%u\n" + "hdr_maint_op_class=%u\n" + "event_type=%u\n" + "health_status=%u\n" + "media_status=%u\n" + "life_used=%u\n" + "dirty_shutdown_cnt=%u\n" + "cor_vol_err_cnt=%u\n" + "cor_per_err_cnt=%u\n" + "device_temp=%d\n" + "add_status=%u\n", + ev->hdr.timestamp, + ev->hdr.memdev, + ev->hdr.host, + ev->hdr.serial, + ev->hdr.log_type, + ev->hdr.hdr_uuid, + ev->hdr.hdr_flags, + ev->hdr.hdr_handle, + ev->hdr.hdr_related_handle, + ev->hdr.hdr_timestamp, + ev->hdr.hdr_length, + ev->hdr.hdr_maint_op_class, + ev->event_type, + ev->health_status, + ev->media_status, + ev->life_used, + ev->dirty_shutdown_cnt, + ev->cor_vol_err_cnt, + ev->cor_per_err_cnt, + ev->device_temp, + ev->add_status); strcat(buf, bt_buf); @@ -677,84 +670,96 @@ static int commit_report_backtrace(int sockfd, int type, void *ev) int rc = -1; int buf_len = 0; - if (sockfd < 0 || !ev) { + if (sockfd < 0 || !ev) return -1; - } memset(buf, 0, MAX_BACKTRACE_SIZE); switch (type) { case MC_EVENT: - rc = set_mc_event_backtrace(buf, (struct ras_mc_event *)ev); + rc = set_mc_event_backtrace(buf, + (struct ras_mc_event *)ev); break; case AER_EVENT: - rc = set_aer_event_backtrace(buf, (struct ras_aer_event *)ev); + rc = set_aer_event_backtrace(buf, + (struct ras_aer_event *)ev); break; case MCE_EVENT: - rc = set_mce_event_backtrace(buf, (struct mce_event *)ev); + rc = set_mce_event_backtrace(buf, + (struct mce_event *)ev); break; case NON_STANDARD_EVENT: - rc = set_non_standard_event_backtrace(buf, (struct ras_non_standard_event *)ev); + rc = set_non_standard_event_backtrace(buf, + (struct ras_non_standard_event *)ev); break; case ARM_EVENT: - rc = set_arm_event_backtrace(buf, (struct ras_arm_event *)ev); + rc = set_arm_event_backtrace(buf, + (struct ras_arm_event *)ev); break; case DEVLINK_EVENT: - rc = set_devlink_event_backtrace(buf, (struct devlink_event *)ev); + rc = set_devlink_event_backtrace(buf, + (struct devlink_event *)ev); break; case DISKERROR_EVENT: - rc = set_diskerror_event_backtrace(buf, (struct diskerror_event *)ev); + rc = set_diskerror_event_backtrace(buf, + (struct diskerror_event *)ev); break; case MF_EVENT: - rc = set_mf_event_backtrace(buf, (struct ras_mf_event *)ev); + rc = set_mf_event_backtrace(buf, + (struct ras_mf_event *)ev); break; case CXL_POISON_EVENT: - rc = set_cxl_poison_event_backtrace(buf, (struct ras_cxl_poison_event *)ev); + rc = set_cxl_poison_event_backtrace(buf, + (struct ras_cxl_poison_event *)ev); break; case CXL_AER_UE_EVENT: - rc = set_cxl_aer_ue_event_backtrace(buf, (struct ras_cxl_aer_ue_event *)ev); + rc = set_cxl_aer_ue_event_backtrace(buf, + (struct ras_cxl_aer_ue_event *)ev); break; case CXL_AER_CE_EVENT: - rc = set_cxl_aer_ce_event_backtrace(buf, (struct ras_cxl_aer_ce_event *)ev); + rc = set_cxl_aer_ce_event_backtrace(buf, + (struct ras_cxl_aer_ce_event *)ev); break; case CXL_OVERFLOW_EVENT: - rc = set_cxl_overflow_event_backtrace(buf, (struct ras_cxl_overflow_event *)ev); + rc = set_cxl_overflow_event_backtrace(buf, + (struct ras_cxl_overflow_event *)ev); break; case CXL_GENERIC_EVENT: - rc = set_cxl_generic_event_backtrace(buf, (struct ras_cxl_generic_event *)ev); + rc = set_cxl_generic_event_backtrace(buf, + (struct ras_cxl_generic_event *)ev); break; case CXL_GENERAL_MEDIA_EVENT: - rc = set_cxl_general_media_event_backtrace(buf, (struct ras_cxl_general_media_event *)ev); + rc = set_cxl_general_media_event_backtrace(buf, + (struct ras_cxl_general_media_event *)ev); break; case CXL_DRAM_EVENT: - rc = set_cxl_dram_event_backtrace(buf, (struct ras_cxl_dram_event *)ev); + rc = set_cxl_dram_event_backtrace(buf, + (struct ras_cxl_dram_event *)ev); break; case CXL_MEMORY_MODULE_EVENT: - rc = set_cxl_memory_module_event_backtrace(buf, (struct ras_cxl_memory_module_event *)ev); + rc = set_cxl_memory_module_event_backtrace(buf, + (struct ras_cxl_memory_module_event *)ev); break; default: return -1; } - if (rc < 0) { + if (rc < 0) return -1; - } buf_len = strlen(buf); for (; buf_len > INPUT_BUFFER_SIZE - 1; buf_len -= (INPUT_BUFFER_SIZE - 1)) { rc = write(sockfd, pbuf, INPUT_BUFFER_SIZE - 1); - if (rc < INPUT_BUFFER_SIZE - 1) { + if (rc < INPUT_BUFFER_SIZE - 1) return -1; - } pbuf = pbuf + INPUT_BUFFER_SIZE - 1; } rc = write(sockfd, pbuf, buf_len + 1); - if (rc < buf_len) { + if (rc < buf_len) return -1; - } return 0; } @@ -769,45 +774,37 @@ int ras_report_mc_event(struct ras_events *ras, struct ras_mc_event *ev) memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return -1; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto mc_fail; - } rc = commit_report_backtrace(sockfd, MC_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto mc_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-mc"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto mc_fail; - } sprintf(buf, "REASON=%s", "EDAC driver report problem"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto mc_fail; - } done = 1; mc_fail: - - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } - if (done) { + if (done) return 0; - } else { - return -1; - } + + return -1; } int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev) @@ -820,45 +817,38 @@ int ras_report_aer_event(struct ras_events *ras, struct ras_aer_event *ev) memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return -1; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto aer_fail; - } rc = commit_report_backtrace(sockfd, AER_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto aer_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-aer"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto aer_fail; - } sprintf(buf, "REASON=%s", "PCIe AER driver report problem"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto aer_fail; - } done = 1; aer_fail: - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } - if (done) { + if (done) return 0; - } else { - return -1; - } + + return -1; } int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standard_event *ev) @@ -870,39 +860,33 @@ int ras_report_non_standard_event(struct ras_events *ras, struct ras_non_standar memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return rc; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto non_standard_fail; - } rc = commit_report_backtrace(sockfd, NON_STANDARD_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto non_standard_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-non-standard"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto non_standard_fail; - } sprintf(buf, "REASON=%s", "Unknown CPER section problem"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto non_standard_fail; - } rc = 0; non_standard_fail: - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } return rc; } @@ -916,39 +900,33 @@ int ras_report_arm_event(struct ras_events *ras, struct ras_arm_event *ev) memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return rc; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto arm_fail; - } rc = commit_report_backtrace(sockfd, ARM_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto arm_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-arm"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto arm_fail; - } sprintf(buf, "REASON=%s", "ARM CPU report problem"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto arm_fail; - } rc = 0; arm_fail: - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } return rc; } @@ -963,45 +941,38 @@ int ras_report_mce_event(struct ras_events *ras, struct mce_event *ev) memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return -1; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto mce_fail; - } rc = commit_report_backtrace(sockfd, MCE_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto mce_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-mce"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto mce_fail; - } sprintf(buf, "REASON=%s", "Machine Check driver report problem"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto mce_fail; - } done = 1; mce_fail: - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } - if (done) { + if (done) return 0; - } else { - return -1; - } + + return -1; } int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev) @@ -1014,45 +985,38 @@ int ras_report_devlink_event(struct ras_events *ras, struct devlink_event *ev) memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return -1; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto devlink_fail; - } rc = commit_report_backtrace(sockfd, DEVLINK_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto devlink_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-devlink"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto devlink_fail; - } sprintf(buf, "REASON=%s", "devlink health report problem"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto devlink_fail; - } done = 1; devlink_fail: - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } - if (done) { + if (done) return 0; - } else { - return -1; - } + + return -1; } int ras_report_diskerror_event(struct ras_events *ras, struct diskerror_event *ev) @@ -1065,44 +1029,37 @@ int ras_report_diskerror_event(struct ras_events *ras, struct diskerror_event *e memset(buf, 0, sizeof(buf)); sockfd = setup_report_socket(); - if (sockfd < 0) { + if (sockfd < 0) return -1; - } rc = commit_report_basic(sockfd); - if (rc < 0) { + if (rc < 0) goto diskerror_fail; - } rc = commit_report_backtrace(sockfd, DISKERROR_EVENT, ev); - if (rc < 0) { + if (rc < 0) goto diskerror_fail; - } sprintf(buf, "ANALYZER=%s", "rasdaemon-diskerror"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto diskerror_fail; - } sprintf(buf, "REASON=%s", "disk I/O error"); rc = write(sockfd, buf, strlen(buf) + 1); - if (rc < strlen(buf) + 1) { + if (rc < strlen(buf) + 1) goto diskerror_fail; - } done = 1; diskerror_fail: - if (sockfd >= 0) { + if (sockfd >= 0) close(sockfd); - } - if (done) { + if (done) return 0; - } else { - return -1; - } + + return -1; } int ras_report_mf_event(struct ras_events *ras, struct ras_mf_event *ev) @@ -1188,8 +1145,8 @@ cxl_poison_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_aer_ue_event(struct ras_events *ras, struct ras_cxl_aer_ue_event *ev) @@ -1232,8 +1189,8 @@ cxl_aer_ue_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_aer_ce_event(struct ras_events *ras, struct ras_cxl_aer_ce_event *ev) @@ -1276,8 +1233,8 @@ cxl_aer_ce_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_overflow_event(struct ras_events *ras, struct ras_cxl_overflow_event *ev) @@ -1320,8 +1277,8 @@ cxl_overflow_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_generic_event(struct ras_events *ras, struct ras_cxl_generic_event *ev) @@ -1364,8 +1321,8 @@ cxl_generic_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_general_media_event(struct ras_events *ras, struct ras_cxl_general_media_event *ev) @@ -1408,8 +1365,8 @@ cxl_general_media_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_dram_event(struct ras_events *ras, struct ras_cxl_dram_event *ev) @@ -1452,8 +1409,8 @@ cxl_dram_fail: if (done) return 0; - else - return -1; + + return -1; } int ras_report_cxl_memory_module_event(struct ras_events *ras, struct ras_cxl_memory_module_event *ev) @@ -1496,6 +1453,6 @@ cxl_memory_module_fail: if (done) return 0; - else - return -1; + + return -1; } diff --git a/rbtree.c b/rbtree.c index 43da434..86d061c 100644 --- a/rbtree.c +++ b/rbtree.c @@ -1,25 +1,23 @@ /* - Red Black Trees - (C) 1999 Andrea Arcangeli - (C) 2002 David Woodhouse - Taken from the Linux 2.6.30 source with some minor modificatons. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - linux/lib/rbtree.c -*/ + * Red Black Trees + * (C) 1999 Andrea Arcangeli + * (C) 2002 David Woodhouse + * Taken from the Linux 2.6.30 source with some minor modificatons. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include "rbtree.h" @@ -35,14 +33,14 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) rb_set_parent(right, parent); - if (parent) - { + if (parent) { if (node == parent->rb_left) parent->rb_left = right; else parent->rb_right = right; - } else + } else { root->rb_node = right; + } rb_set_parent(node, right); } @@ -58,14 +56,14 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) rb_set_parent(left, parent); - if (parent) - { + if (parent) { if (node == parent->rb_right) parent->rb_right = left; else parent->rb_left = left; - } else + } else { root->rb_node = left; + } rb_set_parent(node, left); } @@ -73,27 +71,21 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) { struct rb_node *parent, *gparent; - while ((parent = rb_parent(node)) && rb_is_red(parent)) - { + while ((parent = rb_parent(node)) && rb_is_red(parent)) { gparent = rb_parent(parent); - if (parent == gparent->rb_left) - { - { - register struct rb_node *uncle = gparent->rb_right; - - if (uncle && rb_is_red(uncle)) - { - rb_set_black(uncle); - rb_set_black(parent); - rb_set_red(gparent); - node = gparent; - continue; - } + if (parent == gparent->rb_left) { + register struct rb_node *uncle = gparent->rb_right; + + if (uncle && rb_is_red(uncle)) { + rb_set_black(uncle); + rb_set_black(parent); + rb_set_red(gparent); + node = gparent; + continue; } - if (parent->rb_right == node) - { + if (parent->rb_right == node) { struct rb_node *tmp; __rb_rotate_left(parent, root); @@ -106,21 +98,17 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) rb_set_red(gparent); __rb_rotate_right(gparent, root); } else { - { - struct rb_node *uncle = gparent->rb_left; - - if (uncle && rb_is_red(uncle)) - { - rb_set_black(uncle); - rb_set_black(parent); - rb_set_red(gparent); - node = gparent; - continue; - } + struct rb_node *uncle = gparent->rb_left; + + if (uncle && rb_is_red(uncle)) { + rb_set_black(uncle); + rb_set_black(parent); + rb_set_red(gparent); + node = gparent; + continue; } - if (parent->rb_left == node) - { + if (parent->rb_left == node) { struct rb_node *tmp; __rb_rotate_right(parent, root); @@ -143,28 +131,22 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, { struct rb_node *other; - while ((!node || rb_is_black(node)) && node != root->rb_node) - { - if (parent->rb_left == node) - { + while ((!node || rb_is_black(node)) && node != root->rb_node) { + if (parent->rb_left == node) { other = parent->rb_right; - if (rb_is_red(other)) - { + if (rb_is_red(other)) { rb_set_black(other); rb_set_red(parent); __rb_rotate_left(parent, root); other = parent->rb_right; } if ((!other->rb_left || rb_is_black(other->rb_left)) && - (!other->rb_right || rb_is_black(other->rb_right))) - { + (!other->rb_right || rb_is_black(other->rb_right))) { rb_set_red(other); node = parent; parent = rb_parent(node); - } else - { - if (!other->rb_right || rb_is_black(other->rb_right)) - { + } else { + if (!other->rb_right || rb_is_black(other->rb_right)) { rb_set_black(other->rb_left); rb_set_red(other); __rb_rotate_right(other, root); @@ -177,26 +159,21 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, node = root->rb_node; break; } - } else - { + } else { other = parent->rb_left; - if (rb_is_red(other)) - { + if (rb_is_red(other)) { rb_set_black(other); rb_set_red(parent); __rb_rotate_right(parent, root); other = parent->rb_left; } if ((!other->rb_left || rb_is_black(other->rb_left)) && - (!other->rb_right || rb_is_black(other->rb_right))) - { + (!other->rb_right || rb_is_black(other->rb_right))) { rb_set_red(other); node = parent; parent = rb_parent(node); - } else - { - if (!other->rb_left || rb_is_black(other->rb_left)) - { + } else { + if (!other->rb_left || rb_is_black(other->rb_left)) { rb_set_black(other->rb_right); rb_set_red(other); __rb_rotate_left(other, root); @@ -220,12 +197,11 @@ void rb_erase(struct rb_node *node, struct rb_root *root) struct rb_node *child, *parent; int color; - if (!node->rb_left) + if (!node->rb_left) { child = node->rb_right; - else if (!node->rb_right) + } else if (!node->rb_right) { child = node->rb_left; - else - { + } else { struct rb_node *old = node, *left; node = node->rb_right; @@ -240,21 +216,22 @@ void rb_erase(struct rb_node *node, struct rb_root *root) if (parent == old) { parent->rb_right = child; parent = node; - } else + } else { parent->rb_left = child; + } node->rb_parent_color = old->rb_parent_color; node->rb_right = old->rb_right; node->rb_left = old->rb_left; - if (rb_parent(old)) - { + if (rb_parent(old)) { if (rb_parent(old)->rb_left == old) rb_parent(old)->rb_left = node; else rb_parent(old)->rb_right = node; - } else + } else { root->rb_node = node; + } rb_set_parent(old->rb_left, node); if (old->rb_right) @@ -267,14 +244,14 @@ void rb_erase(struct rb_node *node, struct rb_root *root) if (child) rb_set_parent(child, parent); - if (parent) - { + if (parent) { if (parent->rb_left == node) parent->rb_left = child; else parent->rb_right = child; - } else + } else { root->rb_node = child; + } color: if (color == RB_BLACK) @@ -315,8 +292,10 @@ struct rb_node *rb_next(const struct rb_node *node) if (rb_parent(node) == node) return NULL; - /* If we have a right-hand child, go down and then left as far - as we can. */ + /* + * If we have a right-hand child, go down and then left as far + * as we can. + */ if (node->rb_right) { node = node->rb_right; while (node->rb_left) @@ -324,12 +303,14 @@ struct rb_node *rb_next(const struct rb_node *node) return (struct rb_node *)node; } - /* No right-hand children. Everything down and left is - smaller than us, so any 'next' node must be in the general - direction of our parent. Go up the tree; any time the - ancestor is a right-hand child of its parent, keep going - up. First time it's a left-hand child of its parent, said - parent is our 'next' node. */ + /* + * No right-hand children. Everything down and left is + * smaller than us, so any 'next' node must be in the general + * direction of our parent. Go up the tree; any time the + * ancestor is a right-hand child of its parent, keep going + * up. First time it's a left-hand child of its parent, said + * parent is our 'next' node. + */ while ((parent = rb_parent(node)) && node == parent->rb_right) node = parent; @@ -343,8 +324,10 @@ struct rb_node *rb_prev(const struct rb_node *node) if (rb_parent(node) == node) return NULL; - /* If we have a left-hand child, go down and then right as far - as we can. */ + /* + * If we have a left-hand child, go down and then right as far + * as we can. + */ if (node->rb_left) { node = node->rb_left; while (node->rb_right) @@ -352,8 +335,10 @@ struct rb_node *rb_prev(const struct rb_node *node) return (struct rb_node *)node; } - /* No left-hand children. Go up till we find an ancestor which - is a right-hand child of its parent */ + /* + * No left-hand children. Go up till we find an ancestor which + * is a right-hand child of its parent + */ while ((parent = rb_parent(node)) && node == parent->rb_left) node = parent; diff --git a/rbtree.h b/rbtree.h index 555b3dc..bf861e5 100644 --- a/rbtree.h +++ b/rbtree.h @@ -1,96 +1,96 @@ /* - Red Black Trees - (C) 1999 Andrea Arcangeli - Taken from the Linux 2.6.30 source. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - linux/include/linux/rbtree.h - - To use rbtrees you'll have to implement your own insert and search cores. - This will avoid us to use callbacks and to drop drammatically performances. - I know it's not the cleaner way, but in C (not in C++) to get - performances and genericity... - - Some example of insert and search follows here. The search is a plain - normal search over an ordered tree. The insert instead must be implemented - int two steps: as first thing the code must insert the element in - order as a red leaf in the tree, then the support library function - rb_insert_color() must be called. Such function will do the - not trivial work to rebalance the rbtree if necessary. - ------------------------------------------------------------------------ -static inline struct page * rb_search_page_cache(struct inode * inode, - unsigned long offset) -{ - struct rb_node * n = inode->i_rb_page_cache.rb_node; - struct page * page; - - while (n) - { - page = rb_entry(n, struct page, rb_page_cache); - - if (offset < page->offset) - n = n->rb_left; - else if (offset > page->offset) - n = n->rb_right; - else - return page; - } - return NULL; -} - -static inline struct page * __rb_insert_page_cache(struct inode * inode, - unsigned long offset, - struct rb_node * node) -{ - struct rb_node ** p = &inode->i_rb_page_cache.rb_node; - struct rb_node * parent = NULL; - struct page * page; - - while (*p) - { - parent = *p; - page = rb_entry(parent, struct page, rb_page_cache); - - if (offset < page->offset) - p = &(*p)->rb_left; - else if (offset > page->offset) - p = &(*p)->rb_right; - else - return page; - } - - rb_link_node(node, parent, p); - - return NULL; -} + * Red Black Trees + * (C) 1999 Andrea Arcangeli + * Taken from the Linux 2.6.30 source. + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ -static inline struct page * rb_insert_page_cache(struct inode * inode, - unsigned long offset, - struct rb_node * node) -{ - struct page * ret; - if ((ret = __rb_insert_page_cache(inode, offset, node))) - goto out; - rb_insert_color(node, &inode->i_rb_page_cache); - out: - return ret; -} ------------------------------------------------------------------------ -*/ +/* + * To use rbtrees you'll have to implement your own insert and search cores. + * This will avoid us to use callbacks and to drop drammatically performances. + * I know it's not the cleaner way, but in C (not in C++) to get + * performances and genericity... + * + * Some example of insert and search follows here. The search is a plain + * normal search over an ordered tree. The insert instead must be implemented + * int two steps: as first thing the code must insert the element in + * order as a red leaf in the tree, then the support library function + * rb_insert_color() must be called. Such function will do the + * not trivial work to rebalance the rbtree if necessary. + * + * ----------------------------------------------------------------------- + * + * static inline struct page * rb_search_page_cache(struct inode * inode, + * unsigned long offset) + * { + * struct rb_node * n = inode->i_rb_page_cache.rb_node; + * struct page * page; + * + * while (n) + * { + * page = rb_entry(n, struct page, rb_page_cache); + * + * if (offset < page->offset) + * n = n->rb_left; + * else if (offset > page->offset) + * n = n->rb_right; + * else + * return page; + * } + * return NULL; + * } + * + * static inline struct page * __rb_insert_page_cache(struct inode * inode, + * unsigned long offset, + * struct rb_node * node) + * { + * struct rb_node ** p = &inode->i_rb_page_cache.rb_node; + * struct rb_node * parent = NULL; + * struct page * page; + * + * while (*p) + * { + * parent = *p; + * page = rb_entry(parent, struct page, rb_page_cache); + * + * if (offset < page->offset) + * p = &(*p)->rb_left; + * else if (offset > page->offset) + * p = &(*p)->rb_right; + * else + * return page; + * } + * + * rb_link_node(node, parent, p); + * + * return NULL; + * } + * + * static inline struct page * rb_insert_page_cache(struct inode * inode, + * unsigned long offset, + * struct rb_node * node) + * { + * struct page * ret; + * if ((ret = __rb_insert_page_cache(inode, offset, node))) + * goto out; + * rb_insert_color(node, &inode->i_rb_page_cache); + * out: + * return ret; + * } + */ #ifndef _LINUX_RBTREE_H #define _LINUX_RBTREE_H @@ -98,8 +98,9 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, #include #define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) + const typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); \ +}) struct rb_node { unsigned long rb_parent_color;