Skip to content

Commit c46945c

Browse files
qzhuo2bp3tk0v
authored andcommitted
x86/mce: Make four functions return bool
Make those functions whose callers only care about success or failure return a boolean value for better readability. Also, update the call sites accordingly as the polarities of all the return values have been flipped. No functional changes. Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Qiuxu Zhuo <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Sohil Mehta <[email protected]> Reviewed-by: Yazen Ghannam <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 64a668f commit c46945c

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

arch/x86/kernel/cpu/mce/core.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ EXPORT_PER_CPU_SYMBOL_GPL(injectm);
151151

152152
void mce_log(struct mce_hw_err *err)
153153
{
154-
if (!mce_gen_pool_add(err))
154+
if (mce_gen_pool_add(err))
155155
irq_work_queue(&mce_irq_work);
156156
}
157157
EXPORT_SYMBOL_GPL(mce_log);
@@ -1911,14 +1911,14 @@ static void __mcheck_cpu_check_banks(void)
19111911
}
19121912

19131913
/* Add per CPU specific workarounds here */
1914-
static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
1914+
static bool __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
19151915
{
19161916
struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
19171917
struct mca_config *cfg = &mca_cfg;
19181918

19191919
if (c->x86_vendor == X86_VENDOR_UNKNOWN) {
19201920
pr_info("unknown CPU type - not enabling MCE support\n");
1921-
return -EOPNOTSUPP;
1921+
return false;
19221922
}
19231923

19241924
/* This should be disabled by the BIOS, but isn't always */
@@ -2012,7 +2012,7 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
20122012
if (cfg->bootlog != 0)
20132013
cfg->panic_timeout = 30;
20142014

2015-
return 0;
2015+
return true;
20162016
}
20172017

20182018
static bool __mcheck_cpu_ancient_init(struct cpuinfo_x86 *c)
@@ -2279,12 +2279,12 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22792279

22802280
__mcheck_cpu_cap_init();
22812281

2282-
if (__mcheck_cpu_apply_quirks(c) < 0) {
2282+
if (!__mcheck_cpu_apply_quirks(c)) {
22832283
mca_cfg.disabled = 1;
22842284
return;
22852285
}
22862286

2287-
if (mce_gen_pool_init()) {
2287+
if (!mce_gen_pool_init()) {
22882288
mca_cfg.disabled = 1;
22892289
pr_emerg("Couldn't allocate MCE records pool!\n");
22902290
return;

arch/x86/kernel/cpu/mce/genpool.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,64 +94,63 @@ bool mce_gen_pool_empty(void)
9494
return llist_empty(&mce_event_llist);
9595
}
9696

97-
int mce_gen_pool_add(struct mce_hw_err *err)
97+
bool mce_gen_pool_add(struct mce_hw_err *err)
9898
{
9999
struct mce_evt_llist *node;
100100

101101
if (filter_mce(&err->m))
102-
return -EINVAL;
102+
return false;
103103

104104
if (!mce_evt_pool)
105-
return -EINVAL;
105+
return false;
106106

107107
node = (void *)gen_pool_alloc(mce_evt_pool, sizeof(*node));
108108
if (!node) {
109109
pr_warn_ratelimited("MCE records pool full!\n");
110-
return -ENOMEM;
110+
return false;
111111
}
112112

113113
memcpy(&node->err, err, sizeof(*err));
114114
llist_add(&node->llnode, &mce_event_llist);
115115

116-
return 0;
116+
return true;
117117
}
118118

119-
static int mce_gen_pool_create(void)
119+
static bool mce_gen_pool_create(void)
120120
{
121121
int mce_numrecords, mce_poolsz, order;
122122
struct gen_pool *gpool;
123-
int ret = -ENOMEM;
124123
void *mce_pool;
125124

126125
order = order_base_2(sizeof(struct mce_evt_llist));
127126
gpool = gen_pool_create(order, -1);
128127
if (!gpool)
129-
return ret;
128+
return false;
130129

131130
mce_numrecords = max(MCE_MIN_ENTRIES, num_possible_cpus() * MCE_PER_CPU);
132131
mce_poolsz = mce_numrecords * (1 << order);
133132
mce_pool = kmalloc(mce_poolsz, GFP_KERNEL);
134133
if (!mce_pool) {
135134
gen_pool_destroy(gpool);
136-
return ret;
135+
return false;
137136
}
138-
ret = gen_pool_add(gpool, (unsigned long)mce_pool, mce_poolsz, -1);
139-
if (ret) {
137+
138+
if (gen_pool_add(gpool, (unsigned long)mce_pool, mce_poolsz, -1)) {
140139
gen_pool_destroy(gpool);
141140
kfree(mce_pool);
142-
return ret;
141+
return false;
143142
}
144143

145144
mce_evt_pool = gpool;
146145

147-
return ret;
146+
return true;
148147
}
149148

150-
int mce_gen_pool_init(void)
149+
bool mce_gen_pool_init(void)
151150
{
152151
/* Just init mce_gen_pool once. */
153152
if (mce_evt_pool)
154-
return 0;
153+
return true;
155154

156155
return mce_gen_pool_create();
157156
}

arch/x86/kernel/cpu/mce/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct mce_evt_llist {
3131

3232
void mce_gen_pool_process(struct work_struct *__unused);
3333
bool mce_gen_pool_empty(void);
34-
int mce_gen_pool_add(struct mce_hw_err *err);
35-
int mce_gen_pool_init(void);
34+
bool mce_gen_pool_add(struct mce_hw_err *err);
35+
bool mce_gen_pool_init(void);
3636
struct llist_node *mce_gen_pool_prepare_records(void);
3737

3838
int mce_severity(struct mce *a, struct pt_regs *regs, char **msg, bool is_excp);

0 commit comments

Comments
 (0)