[PATCH 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes

Qiuxu Zhuo posted 10 patches 1 year, 2 months ago
There is a newer version of this series
[PATCH 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes
Posted by Qiuxu Zhuo 1 year, 2 months ago
Make mce_gen_pool_create() return explicit error codes for better
readability.

No functional changes intended.

Signed-off-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
---
 arch/x86/kernel/cpu/mce/genpool.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/genpool.c b/arch/x86/kernel/cpu/mce/genpool.c
index 4284749ec803..ffa28769dea6 100644
--- a/arch/x86/kernel/cpu/mce/genpool.c
+++ b/arch/x86/kernel/cpu/mce/genpool.c
@@ -120,20 +120,20 @@ static int mce_gen_pool_create(void)
 {
 	int mce_numrecords, mce_poolsz, order;
 	struct gen_pool *gpool;
-	int ret = -ENOMEM;
 	void *mce_pool;
+	int ret;
 
 	order = order_base_2(sizeof(struct mce_evt_llist));
 	gpool = gen_pool_create(order, -1);
 	if (!gpool)
-		return ret;
+		return -ENOMEM;
 
 	mce_numrecords = max(MCE_MIN_ENTRIES, num_possible_cpus() * MCE_PER_CPU);
 	mce_poolsz = mce_numrecords * (1 << order);
 	mce_pool = kmalloc(mce_poolsz, GFP_KERNEL);
 	if (!mce_pool) {
 		gen_pool_destroy(gpool);
-		return ret;
+		return -ENOMEM;
 	}
 	ret = gen_pool_add(gpool, (unsigned long)mce_pool, mce_poolsz, -1);
 	if (ret) {
@@ -144,7 +144,7 @@ static int mce_gen_pool_create(void)
 
 	mce_evt_pool = gpool;
 
-	return ret;
+	return 0;
 }
 
 int mce_gen_pool_init(void)
-- 
2.17.1
Re: [PATCH 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes
Posted by Thomas Gleixner 1 year, 1 month ago
On Thu, Oct 10 2024 at 23:31, Qiuxu Zhuo wrote:

> Make mce_gen_pool_create() return explicit error codes for better
> readability.

What's the point?

All error paths including gen_pool_add() return -ENOMEM.

The call site just cares about success or fail.

So this can simply be converted to bool and return true on success and
false otherwise.

Thanks,

        tglx
RE: [PATCH 05/10] x86/mce/genpool: Make mce_gen_pool_create() return explicit error codes
Posted by Zhuo, Qiuxu 1 year, 1 month ago
> From: Thomas Gleixner <tglx@linutronix.de>
> [...]
> On Thu, Oct 10 2024 at 23:31, Qiuxu Zhuo wrote:
> 
> > Make mce_gen_pool_create() return explicit error codes for better
> > readability.
> 
> What's the point?
> 
> All error paths including gen_pool_add() return -ENOMEM.
> 
> The call site just cares about success or fail.
> 
> So this can simply be converted to bool and return true on success and false
> otherwise.

Yes, this way it's much cleaner. 
Thank you, Thomas, for your kind guidance.

> Thanks,
> 
>         tglx