diff mbox series

bonding: return -ENOMEM on rlb_initialize() allocation failure

Message ID 20220812032059.64572-1-jiapeng.chong@linux.alibaba.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series bonding: return -ENOMEM on rlb_initialize() allocation failure | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 85 this patch: 85
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 85 this patch: 85
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiapeng Chong Aug. 12, 2022, 3:20 a.m. UTC
drivers/net/bonding/bond_alb.c:861 rlb_initialize() warn: returning -1 instead of -ENOMEM is sloppy.

Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=1896
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 drivers/net/bonding/bond_alb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jay Vosburgh Aug. 12, 2022, 3:29 a.m. UTC | #1
Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:

>drivers/net/bonding/bond_alb.c:861 rlb_initialize() warn: returning -1 instead of -ENOMEM is sloppy.

	I'll disagree; the return value is only ever tested for being
non-zero.

	-J

>Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=1896
>Reported-by: Abaci Robot <abaci@linux.alibaba.com>
>Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
>---
> drivers/net/bonding/bond_alb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
>index 60cb9a0225aa..96cb4404b3c7 100644
>--- a/drivers/net/bonding/bond_alb.c
>+++ b/drivers/net/bonding/bond_alb.c
>@@ -858,7 +858,7 @@ static int rlb_initialize(struct bonding *bond)
> 
> 	new_hashtbl = kmalloc(size, GFP_KERNEL);
> 	if (!new_hashtbl)
>-		return -1;
>+		return -ENOMEM;
> 
> 	spin_lock_bh(&bond->mode_lock);
> 
>-- 
>2.20.1.7.g153144c
>

---
	-Jay Vosburgh, jay.vosburgh@canonical.com
Christophe JAILLET Aug. 12, 2022, 7:14 a.m. UTC | #2
Le 12/08/2022 à 05:20, Jiapeng Chong a écrit :
> drivers/net/bonding/bond_alb.c:861 rlb_initialize() warn: returning -1 instead of -ENOMEM is sloppy.
> 
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=1896
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>   drivers/net/bonding/bond_alb.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
> index 60cb9a0225aa..96cb4404b3c7 100644
> --- a/drivers/net/bonding/bond_alb.c
> +++ b/drivers/net/bonding/bond_alb.c
> @@ -858,7 +858,7 @@ static int rlb_initialize(struct bonding *bond)
>   
>   	new_hashtbl = kmalloc(size, GFP_KERNEL);
>   	if (!new_hashtbl)
> -		return -1;
> +		return -ENOMEM;
>   
>   	spin_lock_bh(&bond->mode_lock);
>   

Hi,

Nit: if of any use, the only call chain leads to [1]:
bond_open()
--> bond_alb_initialize()
   --> rlb_initialize()

So, the error in bond_open() could be changed to ret instead of a hard 
coded -ENOMEM.

Just my 2c,


Other than that, for what it worth,
Reviewed-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

CJ

[1]: 
https://elixir.bootlin.com/linux/v5.19/source/drivers/net/bonding/bond_main.c#L4163
diff mbox series

Patch

diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 60cb9a0225aa..96cb4404b3c7 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -858,7 +858,7 @@  static int rlb_initialize(struct bonding *bond)
 
 	new_hashtbl = kmalloc(size, GFP_KERNEL);
 	if (!new_hashtbl)
-		return -1;
+		return -ENOMEM;
 
 	spin_lock_bh(&bond->mode_lock);