All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: sparx5: fix return values to correctly use bool
@ 2022-09-02  8:45 Casper Andersson
  2022-09-02 16:41 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Casper Andersson @ 2022-09-02  8:45 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Casper Andersson, Lars Povlsen, Steen Hegelund, UNGLinuxDriver,
	netdev, Dan Carpenter

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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Casper Andersson <casper.casan@gmail.com>
---
 .../ethernet/microchip/sparx5/sparx5_mactable.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c
index a5837dbe0c7e..4bc80bc7475f 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c
@@ -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,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: sparx5: fix return values to correctly use bool
  2022-09-02  8:45 [PATCH net-next] net: sparx5: fix return values to correctly use bool Casper Andersson
@ 2022-09-02 16:41 ` Andrew Lunn
  2022-09-05 15:33   ` Casper Andersson
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2022-09-02 16:41 UTC (permalink / raw)
  To: Casper Andersson
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Lars Povlsen, Steen Hegelund, UNGLinuxDriver, netdev,
	Dan Carpenter

On Fri, Sep 02, 2022 at 10:45:21AM +0200, Casper Andersson wrote:
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: sparx5: fix return values to correctly use bool
  2022-09-02 16:41 ` Andrew Lunn
@ 2022-09-05 15:33   ` Casper Andersson
  2022-09-05 16:53     ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Casper Andersson @ 2022-09-05 15:33 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Lars Povlsen, Steen Hegelund, UNGLinuxDriver, netdev,
	Dan Carpenter

Hi,

On 2022-09-02 18:41, Andrew Lunn wrote:
> On Fri, Sep 02, 2022 at 10:45:21AM +0200, Casper Andersson wrote:
> > 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: sparx5: fix return values to correctly use bool
  2022-09-05 15:33   ` Casper Andersson
@ 2022-09-05 16:53     ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2022-09-05 16:53 UTC (permalink / raw)
  To: Casper Andersson
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Lars Povlsen, Steen Hegelund, UNGLinuxDriver, netdev,
	Dan Carpenter

On Mon, Sep 05, 2022 at 05:33:44PM +0200, Casper Andersson wrote:
> Hi,
> 
> On 2022-09-02 18:41, Andrew Lunn wrote:
> > On Fri, Sep 02, 2022 at 10:45:21AM +0200, Casper Andersson wrote:
> > > 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.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-05 16:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02  8:45 [PATCH net-next] net: sparx5: fix return values to correctly use bool Casper Andersson
2022-09-02 16:41 ` Andrew Lunn
2022-09-05 15:33   ` Casper Andersson
2022-09-05 16:53     ` Andrew Lunn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.