Skip to content

Commit

Permalink
C files: cleanup coding style
Browse files Browse the repository at this point in the history
The rasdaemon conding style follows Linux Kernel where it makes sense.

Yet, changes made overtime ended with some coding style non-compliances.

Adjust rasdaemon coding style by using:

   scripts/checkpatch.pl --fix-inplace --strict *.c --ignore PREFER_KERNEL_TYPES

And doing some manual fixups where the script didn't work.
As a bonus, some typos were also fixed on some rasdaemon messages.

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
mchehab committed Jan 22, 2024
1 parent df5dcc7 commit 7b3de7f
Show file tree
Hide file tree
Showing 39 changed files with 637 additions and 628 deletions.
13 changes: 9 additions & 4 deletions bitfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include "ras-mce-handler.h"
#include "bitfield.h"

unsigned bitfield_msg(char *buf, size_t len, const char **bitarray,
unsigned array_len,
unsigned bit_offset, unsigned ignore_bits,
uint64_t status)
unsigned int bitfield_msg(char *buf, size_t len, const char **bitarray,
unsigned int array_len,
unsigned int bit_offset, unsigned int ignore_bits,
uint64_t status)
{
int i, n;
char *p = buf;
Expand Down Expand Up @@ -64,6 +64,7 @@ unsigned bitfield_msg(char *buf, size_t len, const char **bitarray,
static uint64_t bitmask(uint64_t i)
{
uint64_t mask = 1;

while (mask < i)
mask = (mask << 1) | 1;
return mask;
Expand All @@ -77,6 +78,7 @@ void decode_bitfield(struct mce_event *e, uint64_t status,
for (f = fields; f->str; f++) {
uint64_t v = (status >> f->start_bit) & bitmask(f->stringlen - 1);
char *s = NULL;

if (v < f->stringlen)
s = f->str[v];
if (!s) {
Expand All @@ -93,11 +95,14 @@ void decode_numfield(struct mce_event *e, uint64_t status,
struct numfield *fields)
{
struct numfield *f;

for (f = fields; f->name; f++) {
uint64_t mask = (1ULL << (f->end - f->start + 1)) - 1;
uint64_t v = (status >> f->start) & mask;

if (v > 0 || f->force) {
char fmt[32] = {0};

snprintf(fmt, 32, "%%s: %s\n", f->fmt ? f->fmt : "%Lu");
mce_snprintf(e->error_msg, fmt, f->name, v);
}
Expand Down
28 changes: 18 additions & 10 deletions mce-amd-k8.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const char *k8bank[] = {
};

static const char *k8threshold[] = {
[0 ... K8_MCELOG_THRESHOLD_DRAM_ECC - 1] = "Unknow threshold counter",
[0 ... K8_MCELOG_THRESHOLD_DRAM_ECC - 1] = "Unknown threshold counter",
[K8_MCELOG_THRESHOLD_DRAM_ECC] = "MC4_MISC0 DRAM threshold",
[K8_MCELOG_THRESHOLD_LINK] = "MC4_MISC1 Link threshold",
[K8_MCELOG_THRESHOLD_L3_CACHE] = "MC4_MISC2 L3 Cache threshold",
Expand All @@ -56,25 +56,31 @@ static const char *k8threshold[] = {
static const char *transaction[] = {
"instruction", "data", "generic", "reserved"
};

static const char *cachelevel[] = {
"0", "1", "2", "generic"
};

static const char *memtrans[] = {
"generic error", "generic read", "generic write", "data read",
"data write", "instruction fetch", "prefetch", "evict", "snoop",
"?", "?", "?", "?", "?", "?", "?"
};

static const char *partproc[] = {
"local node origin", "local node response",
"local node observed", "generic participation"
};

static const char *timeout[] = {
"request didn't time out",
"request timed out"
};

static const char *memoryio[] = {
"memory", "res.", "i/o", "generic"
};

static const char *nbextendederr[] = {
"RAM ECC error",
"CRC error",
Expand All @@ -96,6 +102,7 @@ static const char *nbextendederr[] = {
"L3 Cache Tag Error",
"L3 Cache LRU Error"
};

static const char *highbits[32] = {
[31] = "valid",
[30] = "error overflow (multiple errors)",
Expand Down Expand Up @@ -164,7 +171,7 @@ static void decode_k8_dc_mc(struct mce_event *e)
if (e->status & (3ULL << 45)) {
mce_snprintf(e->error_msg,
"Data cache ECC error (syndrome %x)",
(uint32_t) (e->status >> 47) & 0xff);
(uint32_t)(e->status >> 47) & 0xff);
if (e->status & (1ULL << 40))
mce_snprintf(e->error_msg, "found by scrubber");
}
Expand All @@ -185,7 +192,7 @@ static void decode_k8_ic_mc(struct mce_event *e)

if ((errcode & 0xfff0) == 0x0010)
mce_snprintf(e->error_msg, "TLB parity error in %s array",
(exterrcode == 0) ? "physical" : "virtual");
(exterrcode == 0) ? "physical" : "virtual");
}

static void decode_k8_bu_mc(struct mce_event *e)
Expand All @@ -196,10 +203,10 @@ static void decode_k8_bu_mc(struct mce_event *e)
mce_snprintf(e->error_msg, "L2 cache ECC error");

mce_snprintf(e->error_msg, "%s array error",
!exterrcode ? "Bus or cache" : "Cache tag");
!exterrcode ? "Bus or cache" : "Cache tag");
}

static void decode_k8_nb_mc(struct mce_event *e, unsigned *memerr)
static void decode_k8_nb_mc(struct mce_event *e, unsigned int *memerr)
{
unsigned short exterrcode = (e->status >> 16) & 0x0f;

Expand All @@ -209,21 +216,21 @@ static void decode_k8_nb_mc(struct mce_event *e, unsigned *memerr)
case 0:
*memerr = 1;
mce_snprintf(e->error_msg, "ECC syndrome = %x",
(uint32_t) (e->status >> 47) & 0xff);
(uint32_t)(e->status >> 47) & 0xff);
break;
case 8:
*memerr = 1;
mce_snprintf(e->error_msg, "Chipkill ECC syndrome = %x",
(uint32_t) ((((e->status >> 24) & 0xff) << 8)
| ((e->status >> 47) & 0xff)));
(uint32_t)((((e->status >> 24) & 0xff) << 8)
| ((e->status >> 47) & 0xff)));
break;
case 1:
case 2:
case 3:
case 4:
case 6:
mce_snprintf(e->error_msg, "link number = %x",
(uint32_t) (e->status >> 36) & 0xf);
(uint32_t)(e->status >> 36) & 0xf);
break;
}
}
Expand Down Expand Up @@ -251,11 +258,12 @@ static void bank_name(struct mce_event *e)

int parse_amd_k8_event(struct ras_events *ras, struct mce_event *e)
{
unsigned ismemerr = 0;
unsigned int ismemerr = 0;

/* Don't handle GART errors */
if (e->bank == 4) {
unsigned short exterrcode = (e->status >> 16) & 0x0f;

if (exterrcode == 5 && (e->status & (1ULL << 61))) {
return -1;
}
Expand Down
19 changes: 8 additions & 11 deletions mce-amd-smca.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ enum smca_bank_types {
SMCA_PCIE, /* PCI Express Unit */
SMCA_PCIE_V2,
SMCA_XGMI_PCS, /* xGMI PCS Unit */
SMCA_NBIF, /*NBIF Unit */
SMCA_SHUB, /* System Hub Unit */
SMCA_SATA, /* SATA Unit */
SMCA_USB, /* USB Unit */
SMCA_NBIF, /* NBIF Unit */
SMCA_SHUB, /* System Hub Unit */
SMCA_SATA, /* SATA Unit */
SMCA_USB, /* USB Unit */
SMCA_USR_DP, /* Ultra Short Reach Data Plane Controller */
SMCA_USR_CP, /* Ultra Short Reach Control Plane Controller */
SMCA_GMI_PCS, /* GMI PCS Unit */
Expand Down Expand Up @@ -799,7 +799,7 @@ static struct smca_bank_name smca_names[] = {
[SMCA_PSP ... SMCA_PSP_V2] = { "Platform Security Processor" },
[SMCA_SMU ... SMCA_SMU_V2] = { "System Management Unit" },
[SMCA_MP5] = { "Microprocessor 5 Unit" },
[SMCA_MPDMA] = { "MPDMA Unit" },
[SMCA_MPDMA] = { "MPDMA Unit" },
[SMCA_NBIO] = { "Northbridge IO Unit" },
[SMCA_PCIE ... SMCA_PCIE_V2] = { "PCI Express Unit" },
[SMCA_XGMI_PCS] = { "Ext Global Memory Interconnect PCS Unit" },
Expand All @@ -817,16 +817,15 @@ static struct smca_bank_name smca_names[] = {

void amd_decode_errcode(struct mce_event *e)
{

decode_amd_errcode(e);

if (e->status & MCI_STATUS_POISON)
mce_snprintf(e->mcistatus_msg, "Poison consumed");

if (e->status & MCI_STATUS_TCC)
mce_snprintf(e->mcistatus_msg, "Task_context_corrupt");

}

/*
* To find the UMC channel represented by this bank we need to match on its
* instance_id. The instance_id of a bank is held in the lower 32 bits of its
Expand Down Expand Up @@ -856,7 +855,7 @@ static int find_hbm_channel(struct mce_event *e)
return (umc % 2) ? tmp + 4 : tmp;
}

static inline void fixup_hwid(struct mce_priv* m, uint32_t *hwid_mcatype)
static inline void fixup_hwid(struct mce_priv *m, uint32_t *hwid_mcatype)
{
if (m->family == 0x19) {
switch (m->model) {
Expand Down Expand Up @@ -965,7 +964,6 @@ void decode_smca_error(struct mce_event *e, struct mce_priv *m)
channel, csrow);
}


if (e->vdata_len) {
uint64_t smca_config = e->vdata[2];

Expand All @@ -976,15 +974,14 @@ void decode_smca_error(struct mce_event *e, struct mce_priv *m)
if (smca_config & BIT(9))
memcpy(e->frutext, e->vdata, 16);
}

}

int parse_amd_smca_event(struct ras_events *ras, struct mce_event *e)
{
uint64_t mcgstatus = e->mcgstatus;

mce_snprintf(e->mcgstatus_msg, "mcgstatus=%lld",
(long long)e->mcgstatus);
(long long)e->mcgstatus);

if (mcgstatus & MCG_STATUS_RIPV)
mce_snprintf(e->mcgstatus_msg, "RIPV");
Expand Down
6 changes: 5 additions & 1 deletion mce-amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,31 @@
static char *transaction[] = {
"instruction", "data", "generic", "reserved"
};

/* Error codes: cache level (LL) */
static char *cachelevel[] = {
"reserved", "L1", "L2", "L3/generic"
};

/* Error codes: memory transaction type (RRRR) */
static char *memtrans[] = {
"generic", "generic read", "generic write", "data read",
"data write", "instruction fetch", "prefetch", "evict", "snoop",
"?", "?", "?", "?", "?", "?", "?"
};

/* Participation Processor */
static char *partproc[] = {
"local node origin", "local node response",
"local node observed", "generic participation"
};

/* Timeout */
static char *timeout[] = {
"request didn't time out",
"request timed out"
};

/* internal unclassified error code */
static char *internal[] = { "reserved",
"reserved",
Expand Down Expand Up @@ -118,5 +123,4 @@ void decode_amd_errcode(struct mce_event *e)
PP_MSG(ec), TO_MSG(ec),
R4_MSG(ec), LL_MSG(ec));
return;

}
6 changes: 3 additions & 3 deletions mce-intel-broadwell-de.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void broadwell_de_decode_model(struct ras_events *ras, struct mce_event *e)
{
uint64_t status = e->status;
uint32_t mca = status & 0xffff;
unsigned rank0 = -1, rank1 = -1, chan;
unsigned int rank0 = -1, rank1 = -1, chan;

switch (e->bank) {
case 4:
Expand Down Expand Up @@ -115,7 +115,7 @@ void broadwell_de_decode_model(struct ras_events *ras, struct mce_event *e)

/* Ignore unless this is an corrected extended error from an iMC bank */
if (e->bank < 9 || e->bank > 16 || (status & MCI_STATUS_UC) ||
!test_prefix(7, status & 0xefff))
!test_prefix(7, status & 0xefff))
return;

/*
Expand All @@ -140,7 +140,7 @@ void broadwell_de_decode_model(struct ras_events *ras, struct mce_event *e)
*/
if (rank0 != -1 && rank1 != -1)
mce_snprintf(e->mc_location, "ranks=%d and %d",
rank0, rank1);
rank0, rank1);
else if (rank0 != -1)
mce_snprintf(e->mc_location, "rank=%d", rank0);
}
8 changes: 4 additions & 4 deletions mce-intel-broadwell-epex.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static char *qpi[] = {
[0x22] = "Phy detected in-band reset (no width change)",
[0x23] = "Link failover clock failover",
[0x30] = "Rx detected CRC error - successful LLR after Phy re-init",
[0x31] = "Rx detected CRC error - successful LLR wihout Phy re-init",
[0x31] = "Rx detected CRC error - successful LLR without Phy re-init",
};

static struct field qpi_mc[] = {
Expand All @@ -118,7 +118,7 @@ void broadwell_epex_decode_model(struct ras_events *ras, struct mce_event *e)
{
uint64_t status = e->status;
uint32_t mca = status & 0xffff;
unsigned rank0 = -1, rank1 = -1, chan;
unsigned int rank0 = -1, rank1 = -1, chan;

switch (e->bank) {
case 4:
Expand Down Expand Up @@ -160,7 +160,7 @@ void broadwell_epex_decode_model(struct ras_events *ras, struct mce_event *e)

/* Ignore unless this is an corrected extended error from an iMC bank */
if (e->bank < 9 || e->bank > 16 || (status & MCI_STATUS_UC) ||
!test_prefix(7, status & 0xefff))
!test_prefix(7, status & 0xefff))
return;

/*
Expand All @@ -185,7 +185,7 @@ void broadwell_epex_decode_model(struct ras_events *ras, struct mce_event *e)
*/
if (rank0 != -1 && rank1 != -1)
mce_snprintf(e->mc_location, "ranks=%d and %d",
rank0, rank1);
rank0, rank1);
else if (rank0 != -1)
mce_snprintf(e->mc_location, "rank=%d", rank0);
}
2 changes: 2 additions & 0 deletions mce-intel-dunnington.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void dunnington_decode_bus(struct mce_event *e, uint64_t status)
static void dunnington_decode_internal(struct mce_event *e, uint64_t status)
{
uint32_t mca = (status >> 16) & 0xffff;

if ((mca & 0xfff0) == 0)
decode_bitfield(e, mca, dnt_front_status);
else if ((mca & 0xf0ff) == 0)
Expand All @@ -104,6 +105,7 @@ static void dunnington_decode_internal(struct mce_event *e, uint64_t status)
void dunnington_decode_model(struct mce_event *e)
{
uint64_t status = e->status;

if ((status & 0xffff) == 0xe0f)
dunnington_decode_bus(e, status);
else if ((status & 0xffff) == (1 << 10))
Expand Down
Loading

0 comments on commit 7b3de7f

Please sign in to comment.