diff mbox series

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

Message ID 20241016123036.21366-6-qiuxu.zhuo@intel.com (mailing list archive)
State New
Headers show
Series x86/mce: Clean up some x86/mce code | expand

Commit Message

Zhuo, Qiuxu Oct. 16, 2024, 12:30 p.m. UTC
Make mce_gen_pool_create() return explicit error codes for better
readability.

No functional changes intended.

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

Comments

Sohil Mehta Oct. 18, 2024, 7:20 p.m. UTC | #1
> 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;
>  

Nit: Maybe move the uninitialized ret along with the other ints in the
first line?

I had suggested something very similar but Boris felt that the current
code as-is reads better. But that was in a slightly different context.
https://lore.kernel.org/lkml/20240307170901.GBZen0re6AvpscLaTM@fat_crate.local/


>  	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)
Zhuo, Qiuxu Oct. 19, 2024, 3:29 a.m. UTC | #2
> From: Mehta, Sohil <sohil.mehta@intel.com>
> [...]
> > 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;
> >
> 
> Nit: Maybe move the uninitialized ret along with the other ints in the first
> line?

OK, that will save one line of code.  
I'll update this in the next version.

> I had suggested something very similar but Boris felt that the current code as-
> is reads better. But that was in a slightly different context.
> https://lore.kernel.org/lkml/20240307170901.GBZen0re6AvpscLaTM@fat_crat
> e.local/

Thanks for sharing this ... 
diff mbox series

Patch

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)