Skip to content

Commit

Permalink
rasdaemon: do some coding style cleanups
Browse files Browse the repository at this point in the history
Adjust coding style on some files to somewhat match the Kernel's
coding style, with the help of scripts/checkpatch.pl.

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
mchehab committed Jul 16, 2024
1 parent a4861c9 commit 7346f2d
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 86 deletions.
16 changes: 8 additions & 8 deletions bitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
/* Generic bitfield decoder */

struct field {
unsigned start_bit;
unsigned int start_bit;
char **str;
unsigned stringlen;
unsigned int stringlen;
};

struct numfield {
unsigned start, end;
unsigned int start, end;
char *name;
char *fmt;
int force;
Expand All @@ -51,7 +51,7 @@ void decode_numfield(struct mce_event *e, uint64_t status,
struct numfield *fields);

#define MASK(x) ((1ULL << (1 + (x))) - 1)
#define EXTRACT(v, a, b) (((v) >> (a)) & MASK((b)-(a)))
#define EXTRACT(v, a, b) (((v) >> (a)) & MASK((b) - (a)))

static inline int test_prefix(int nr, uint32_t value)
{
Expand All @@ -60,7 +60,7 @@ static inline int test_prefix(int nr, uint32_t value)

/* Ancillary routines */

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);
1 change: 0 additions & 1 deletion non-standard-ampere.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
*/


#ifndef __NON_STANDARD_AMPERE_H
#define __NON_STANDARD_AMPERE_H

Expand Down
3 changes: 0 additions & 3 deletions non-standard-jaguarmicro.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
*/


#ifndef __NON_STANDARD_JAGUAR_H
#define __NON_STANDARD_JAGUAR_H

Expand Down Expand Up @@ -129,7 +128,6 @@ struct jm_payload5_type_sec {
struct jm_common_sec_tail common_tail;
};


/*GIC IP */
struct jm_payload6_type_sec {
struct jm_common_sec_head common_head;
Expand Down Expand Up @@ -168,6 +166,5 @@ enum {
JM_PAYLOAD_FIELD_REGS_DUMP,
};


#define JM_SNPRINTF mce_snprintf
#endif
9 changes: 4 additions & 5 deletions non-standard-yitian.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
*/


#ifndef __NON_STANDARD_YITIAN_H
#define __NON_STANDARD_YITIAN_H

Expand Down Expand Up @@ -65,9 +64,9 @@ struct ras_yitian_ddr_payload_event {
};

int record_yitian_ddr_reg_dump_event(struct ras_ns_ev_decoder *ev_decoder,
struct ras_yitian_ddr_payload_event *ev);
struct ras_yitian_ddr_payload_event *ev);
void decode_yitian_ddr_payload_err_regs(struct ras_ns_ev_decoder *ev_decoder,
struct trace_seq *s,
const struct yitian_ddr_payload_type_sec *err,
struct ras_events *ras);
struct trace_seq *s,
const struct yitian_ddr_payload_type_sec *err,
struct ras_events *ras);
#endif
4 changes: 1 addition & 3 deletions ras-arm-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

void display_raw_data(struct trace_seq *s,
const uint8_t *buf,
uint32_t datalen)
uint32_t datalen)
{
int i = 0, line_count = 0;

Expand Down Expand Up @@ -209,7 +209,6 @@ int ras_arm_event_handler(struct trace_seq *s,

// Upstream kKernels up to version 6.10 don't decode UEFI 2.6+ N.17 table
if (tep_get_field_val(s, event, "pei_len", record, &val, 1) >= 0) {

ev.pei_len = val;
trace_seq_printf(s, " ARM Processor Err Info data len: %d\n",
ev.pei_len);
Expand Down Expand Up @@ -251,7 +250,6 @@ int ras_arm_event_handler(struct trace_seq *s,
if (ras_handle_cpu_error(s, record, event, &ev, now) < 0)
printf("Can't do CPU fault isolation!\n");
#endif

}

/* Insert data into the SGBD */
Expand Down
1 change: 1 addition & 0 deletions ras-arm-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct ras_arm_err_info {
uint64_t virt_fault_addr;
uint64_t physical_fault_addr;
};

#pragma pack()

int ras_arm_event_handler(struct trace_seq *s,
Expand Down
1 change: 0 additions & 1 deletion ras-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ struct pthread_data {
int cpu;
};


/* Should match the code at Kernel's include/linux/edac.c */
enum hw_event_mc_err_type {
HW_EVENT_ERR_CORRECTED,
Expand Down
9 changes: 4 additions & 5 deletions ras-extlog-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
#include "ras-events.h"
#include <traceevent/event-parse.h>

extern int ras_extlog_mem_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event,
void *context);

int ras_extlog_mem_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event,
void *context);
#endif
6 changes: 4 additions & 2 deletions ras-logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <syslog.h>

#include "ras-record.h"

/*
* Logging macros
*/
Expand All @@ -28,8 +30,8 @@
#define TOOL_NAME "rasdaemon"
#endif

#define SYSLOG (1 << 0)
#define TERM (1 << 1)
#define SYSLOG BIT(0)
#define TERM BIT(1)
#define ALL (SYSLOG | TERM)
/* TODO: global logging limit mask */

Expand Down
46 changes: 23 additions & 23 deletions ras-mce-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct mce_event {
uint8_t cpuvendor;
uint64_t synd; /* MCA_SYND MSR: only valid on SMCA systems */
uint64_t ipid; /* MCA_IPID MSR: only valid on SMCA systems */
uint64_t ppin;
uint64_t ppin;
uint32_t microcode;
int32_t vdata_len;
const uint64_t *vdata;
Expand Down Expand Up @@ -103,8 +103,8 @@ struct mce_priv {
};

#define mce_snprintf(buf, fmt, arg...) do { \
unsigned __n = strlen(buf); \
unsigned __len = sizeof(buf) - __n; \
unsigned int __n = strlen(buf); \
unsigned int __len = sizeof(buf) - __n; \
if (!__len) \
break; \
if (__n) { \
Expand All @@ -116,13 +116,13 @@ struct mce_priv {
} while (0)

/* register and handling routines */
int register_mce_handler(struct ras_events *ras, unsigned ncpus);
int register_mce_handler(struct ras_events *ras, unsigned int ncpus);
int ras_mce_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context);

/* enables intel iMC logs */
int set_intel_imc_log(enum cputype cputype, unsigned ncpus);
int set_intel_imc_log(enum cputype cputype, unsigned int ncpus);

/* Undertake AMD SMCA Error Decoding */
void decode_smca_error(struct mce_event *e, struct mce_priv *m);
Expand Down Expand Up @@ -151,29 +151,29 @@ void decode_amd_errcode(struct mce_event *e);
/* Software defined banks */
#define MCE_EXTENDED_BANK 128

#define MCI_THRESHOLD_OVER (1ULL<<48) /* threshold error count overflow */
#define MCI_THRESHOLD_OVER BIT_ULL(48) /* threshold error count overflow */

#define MCI_STATUS_VAL (1ULL<<63) /* valid error */
#define MCI_STATUS_OVER (1ULL<<62) /* previous errors lost */
#define MCI_STATUS_UC (1ULL<<61) /* uncorrected error */
#define MCI_STATUS_EN (1ULL<<60) /* error enabled */
#define MCI_STATUS_MISCV (1ULL<<59) /* misc error reg. valid */
#define MCI_STATUS_ADDRV (1ULL<<58) /* addr reg. valid */
#define MCI_STATUS_PCC (1ULL<<57) /* processor context corrupt */
#define MCI_STATUS_S (1ULL<<56) /* signalled */
#define MCI_STATUS_AR (1ULL<<55) /* action-required */
#define MCI_STATUS_VAL BIT_ULL(63) /* valid error */
#define MCI_STATUS_OVER BIT_ULL(62) /* previous errors lost */
#define MCI_STATUS_UC BIT_ULL(61) /* uncorrected error */
#define MCI_STATUS_EN BIT_ULL(60) /* error enabled */
#define MCI_STATUS_MISCV BIT_ULL(59) /* misc error reg. valid */
#define MCI_STATUS_ADDRV BIT_ULL(58) /* addr reg. valid */
#define MCI_STATUS_PCC BIT_ULL(57) /* processor context corrupt */
#define MCI_STATUS_S BIT_ULL(56) /* signalled */
#define MCI_STATUS_AR BIT_ULL(55) /* action-required */

/* AMD-specific bits */
#define MCI_STATUS_TCC (1ULL<<55) /* Task context corrupt */
#define MCI_STATUS_SYNDV (1ULL<<53) /* synd reg. valid */
#define MCI_STATUS_TCC BIT_ULL(55) /* Task context corrupt */
#define MCI_STATUS_SYNDV BIT_ULL(53) /* synd reg. valid */
/* uncorrected error,deferred exception */
#define MCI_STATUS_DEFERRED (1ULL<<44)
#define MCI_STATUS_POISON (1ULL<<43) /* access poisonous data */
#define MCI_STATUS_DEFERRED BIT_ULL(44)
#define MCI_STATUS_POISON BIT_ULL(43) /* access poisonous data */

#define MCG_STATUS_RIPV (1ULL<<0) /* restart ip valid */
#define MCG_STATUS_EIPV (1ULL<<1) /* eip points to correct instruction */
#define MCG_STATUS_MCIP (1ULL<<2) /* machine check in progress */
#define MCG_STATUS_LMCE (1ULL<<3) /* local machine check signaled */
#define MCG_STATUS_RIPV BIT_ULL(0) /* restart ip valid */
#define MCG_STATUS_EIPV BIT_ULL(1) /* eip points to correct instruction */
#define MCG_STATUS_MCIP BIT_ULL(2) /* machine check in progress */
#define MCG_STATUS_LMCE BIT_ULL(3) /* local machine check signaled */

/* Those functions are defined on per-cpu vendor C files */
int parse_intel_event(struct ras_events *ras, struct mce_event *e);
Expand Down
11 changes: 7 additions & 4 deletions ras-page-isolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#ifndef __RAS_PAGE_ISOLATION_H
#define __RAS_PAGE_ISOLATION_H

#include <time.h>
#include <stdbool.h>
#include <time.h>

#include "ras-record.h"
#include "rbtree.h"

#define PAGE_SHIFT 12
#define PAGE_SIZE (1 << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
#define PAGE_SIZE BIT(PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE - 1))

struct config {
char *name;
Expand Down Expand Up @@ -61,6 +63,7 @@ struct isolation {
};

void ras_page_account_init(void);
void ras_record_page_error(unsigned long long addr, unsigned count, time_t time);
void ras_record_page_error(unsigned long long addr,
unsigned int count, time_t time);

#endif
6 changes: 3 additions & 3 deletions ras-record.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdbool.h>
#include "config.h"

#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*(x)))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))

#define BIT(nr) (1UL << (nr))
#define BIT_ULL(nr) (1ULL << (nr))
Expand Down Expand Up @@ -313,7 +313,7 @@ struct db_table_descriptor {
size_t num_fields;
};

int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras);
int ras_mc_event_opendb(unsigned int cpu, struct ras_events *ras);
int ras_mc_event_closedb(unsigned int cpu, struct ras_events *ras);
int ras_mc_add_vendor_table(struct ras_events *ras, sqlite3_stmt **stmt,
const struct db_table_descriptor *db_tab);
Expand All @@ -337,7 +337,7 @@ int ras_store_cxl_dram_event(struct ras_events *ras, struct ras_cxl_dram_event *
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 cpu, struct ras_events *ras) { 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; };
Expand Down
6 changes: 3 additions & 3 deletions ras-report.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include "ras-aer-handler.h"

/* Maximal length of backtrace. */
#define MAX_BACKTRACE_SIZE (1024*1024)
#define MAX_BACKTRACE_SIZE (1024 * 1024)
/* Amount of data received from one client for a message before reporting error. */
#define MAX_MESSAGE_SIZE (4*MAX_BACKTRACE_SIZE)
#define MAX_MESSAGE_SIZE (4 * MAX_BACKTRACE_SIZE)
/* Maximal number of characters read from socket at once. */
#define INPUT_BUFFER_SIZE (8*1024)
#define INPUT_BUFFER_SIZE (8 * 1024)
/* ABRT socket file */
#define ABRT_SOCKET "/var/run/abrt/abrt.socket"

Expand Down
35 changes: 17 additions & 18 deletions rbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

struct rb_node
{
struct rb_node {
unsigned long rb_parent_color;
#define RB_RED 0
#define RB_BLACK 1
Expand All @@ -111,12 +110,10 @@ struct rb_node
} __attribute__((aligned(sizeof(long))));
/* The alignment might seem pointless, but allegedly CRIS needs it */

struct rb_root
{
struct rb_root {
struct rb_node *rb_node;
};


#define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3))
#define rb_color(r) ((r)->rb_parent_color & 1)
#define rb_is_red(r) (!rb_color(r))
Expand All @@ -128,6 +125,7 @@ static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
{
rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p;
}

static inline void rb_set_color(struct rb_node *rb, int color)
{
rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
Expand All @@ -136,28 +134,29 @@ static inline void rb_set_color(struct rb_node *rb, int color)
#define RB_ROOT (struct rb_root) { NULL, }
#define rb_entry(ptr, type, member) container_of(ptr, type, member)

#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
#define RB_EMPTY_ROOT(root) ((root)->!rb_node)
#define RB_EMPTY_NODE(node) (rb_parent(node) == node)
#define RB_CLEAR_NODE(node) (rb_set_parent(node, node))

extern void rb_insert_color(struct rb_node *, struct rb_root *);
extern void rb_erase(struct rb_node *, struct rb_root *);
void rb_insert_color(struct rb_node *node, struct rb_root *rb_root);
void rb_erase(struct rb_node *node, struct rb_root *rb_root);

/* Find logical next and previous nodes in a tree */
extern struct rb_node *rb_next(const struct rb_node *);
extern struct rb_node *rb_prev(const struct rb_node *);
extern struct rb_node *rb_first(const struct rb_root *);
extern struct rb_node *rb_last(const struct rb_root *);
struct rb_node *rb_next(const struct rb_node *node);
struct rb_node *rb_prev(const struct rb_node *node);
struct rb_node *rb_first(const struct rb_root *rb_root);
struct rb_node *rb_last(const struct rb_root *rb_root);

/* Fast replacement of a single node without remove/rebalance/add/rebalance */
extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
struct rb_root *root);
void rb_replace_node(struct rb_node *victim, struct rb_node *new,
struct rb_root *root);

static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
struct rb_node ** rb_link)
static inline void rb_link_node(struct rb_node *node, struct rb_node *parent,
struct rb_node **rb_link)
{
node->rb_parent_color = (unsigned long )parent;
node->rb_left = node->rb_right = NULL;
node->rb_parent_color = (unsigned long)parent;
node->rb_left = NULL;
node->rb_right = NULL;

*rb_link = node;
}
Expand Down
Loading

0 comments on commit 7346f2d

Please sign in to comment.