Skip to contentSkip to conversation

net: sparx5: fix return values to correctly use bool

PATCH In review Casper Andersson 2 participants 4 messages Sep 2, 2022 – Sep 5, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sparx5: fix return values to correctly use bool

Function was declared to return bool, but used error return strategy (0 for success, else error). Now correctly uses bool to indicate whether the entry was found or not.

Does not have any impact on functionality.

---
 .../ethernet/microchip/sparx5/sparx5_mactable.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +9 -8
index a5837dbe0c7e..4bc80bc7475f 100644
@@ -189,7 +189,8 @@ bool sparx5_mact_getnext(struct sparx5 *sparx5,
 bool sparx5_mact_find(struct sparx5 *sparx5,
 		      const unsigned char mac[ETH_ALEN], u16 vid, u32 *pcfg2)
 {
-	int ret;
+	bool found = false;
+	int err;
 	u32 cfg2;
 
 	mutex_lock(&sparx5->lock);
@@ -201,18 +202,18 @@ bool sparx5_mact_find(struct sparx5 *sparx5,
 		LRN_COMMON_ACCESS_CTRL_MAC_TABLE_ACCESS_SHOT_SET(1),
 		sparx5, LRN_COMMON_ACCESS_CTRL);
 
-	ret = sparx5_mact_wait_for_completion(sparx5);
-	if (ret == 0) {
+	err = sparx5_mact_wait_for_completion(sparx5);
+	if (!err) {
 		cfg2 = spx5_rd(sparx5, LRN_MAC_ACCESS_CFG_2);
-		if (LRN_MAC_ACCESS_CFG_2_MAC_ENTRY_VLD_GET(cfg2))
+		if (LRN_MAC_ACCESS_CFG_2_MAC_ENTRY_VLD_GET(cfg2)) {
 			*pcfg2 = cfg2;
-		else
-			ret = -ENOENT;
+			found = true;
+		}
 	}
 
 	mutex_unlock(&sparx5->lock);
 
-	return ret;
+	return found;
 }
 
 int sparx5_mact_forget(struct sparx5 *sparx5,
@@ -296,7 +297,7 @@ int sparx5_add_mact_entry(struct sparx5 *sparx5,
 	u32 cfg2;
 
 	ret = sparx5_mact_find(sparx5, addr, vid, &cfg2);
-	if (!ret)
+	if (ret)
 		return 0;
 
 	/* In case the entry already exists, don't add it again to SW,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · Casper Andersson

Function was declared to return bool, but used error return strategy (0 for success, else error). Now correctly uses bool to indicate whether the entry was found or not.

I think it would be better to actually return an int. < 0 error, 0 = not foumd > 1 found. You can then return ETIMEDOUT etc.

Andrew

#2 lore raw

Hi,

Quoted 9 lines · Andrew Lunn
Quoted 3 lines · Casper Andersson

Function was declared to return bool, but used error return strategy (0 for success, else error). Now correctly uses bool to indicate whether the entry was found or not.

I think it would be better to actually return an int. < 0 error, 0 = not foumd > 1 found. You can then return ETIMEDOUT etc.

Andrew

I can submit a new version with this. But since the commit title will be different I assume I should make it a new patch and not a v2.

Best Regards,
Casper

#3 lore raw
Quoted 8 lines · Casper Andersson

Hi,

Quoted 5 lines · Andrew Lunn
Quoted 3 lines · Casper Andersson

Function was declared to return bool, but used error return strategy (0 for success, else error). Now correctly uses bool to indicate whether the entry was found or not.

Quoted 7 lines
Quoted 4 lines

I think it would be better to actually return an int. < 0 error, 0 = not foumd > 1 found. You can then return ETIMEDOUT etc.

Andrew

I can submit a new version with this. But since the commit title will be different I assume I should make it a new patch and not a v2.

I don't think it matters if it is a new patch, or a v2. There is some attempts to track patches through their revisions, but subjects do change as patches get revised, so it is never a precise things.

Andrew