Skip to contentSkip to conversation

bonding/alb: return -ENOMEM when kmalloc failed

PATCH In review Yang Li 2 participants 2 messages Apr 26, 2021

Subsystems (3)
lore
Share & tools
lore

Yang Li

author
#0 lore raw

PATCH 1/1 bonding/alb: return -ENOMEM when kmalloc failed

The driver is using -1 instead of the -ENOMEM defined macro to specify that a buffer allocation failed. Using the correct error code is more intuitive.

Smatch tool warning:
drivers/net/bonding/bond_alb.c:850 rlb_initialize() warn: returning -1 instead of -ENOMEM is sloppy

No functional change, just more standardized.

---
 drivers/net/bonding/bond_alb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_alb.c +1 -1
index c3091e0..dad5383 100644
@@ -847,7 +847,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);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · Yang Li

The driver is using -1 instead of the -ENOMEM defined macro to specify that a buffer allocation failed. Using the correct error code is more intuitive.

Smatch tool warning:
drivers/net/bonding/bond_alb.c:850 rlb_initialize() warn: returning -1 instead of -ENOMEM is sloppy

No functional change, just more standardized.

[]

drivers/net/bonding/bond_alb.c

Quoted 1 line
drivers/net/bonding/bond_alb.c +0 -0

[]

Quoted 9 lines
drivers/net/bonding/bond_alb.c +0 -0
@@ -847,7 +847,7 @@ static int rlb_initialize(struct bonding *bond)

  new_hashtbl = kmalloc(size, GFP_KERNEL);
  if (!new_hashtbl)

drivers/net/bonding/bond_alb.c +1 -1
-		return -1;
+		return -ENOMEM;

Quoted 3 lines

  spin_lock_bh(&bond->mode_lock);

Perhaps the bond_alb_initialize call here which uses the return value from this function:

drivers/net/bonding/bond_main.c: if (bond_alb_initialize(bond, (BOND_MODE(bond) == BOND_MODE_ALB)))
drivers/net/bonding/bond_main.c- return -ENOMEM;

should use a store/test/return style instead of a fixed value return.

						res = bond_alb_initialize(bond, BOND_MODE(bond) == BOND_MODE_ALB);
						if (res < 0)
							return res;