diff mbox series

[net,v2] net: pse-pd: tps23881: Fix boolean evaluation for bitmask checks

Message ID 20241002102340.233424-1-kory.maincent@bootlin.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] net: pse-pd: tps23881: Fix boolean evaluation for bitmask checks | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-10-02--12-00 (tests: 773)

Commit Message

Kory Maincent Oct. 2, 2024, 10:23 a.m. UTC
Fix incorrect boolean evaluation when checking bitmask values.
The existing code directly assigned the result of bitwise operations
to boolean variables. In the case of 4-pair PoE, this led to incorrect
enabled and delivering status values.

This has been corrected by explicitly converting the bitmask results
to boolean using the !! operator, ensuring proper evaluation.

Fixes: 20e6d190ffe1 ("net: pse-pd: Add TI TPS23881 PSE controller driver")
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---

Change in v2:
- Update commit message to describe the issue.

 drivers/net/pse-pd/tps23881.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Jakub Kicinski Oct. 2, 2024, 12:24 p.m. UTC | #1
On Wed,  2 Oct 2024 12:23:40 +0200 Kory Maincent wrote:
> In the case of 4-pair PoE, this led to incorrect enabled and
> delivering status values.

Could you elaborate? The patch looks like a noop I must be missing some
key aspect..
Jakub Kicinski Oct. 2, 2024, 12:27 p.m. UTC | #2
On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:
> On Wed,  2 Oct 2024 12:23:40 +0200 Kory Maincent wrote:
> > In the case of 4-pair PoE, this led to incorrect enabled and
> > delivering status values.  
> 
> Could you elaborate? The patch looks like a noop I must be missing some
> key aspect..

Reading the discussion on v1 it seems you're doing this to be safe,
because there was a problem with x &= val & MASK; elsewhere.
If that's the case, please resend to net-next and make it clear it's
not a fix.
Kory Maincent Oct. 2, 2024, 12:53 p.m. UTC | #3
On Wed, 2 Oct 2024 05:27:32 -0700
Jakub Kicinski <kuba@kernel.org> wrote:

> On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:
> > On Wed,  2 Oct 2024 12:23:40 +0200 Kory Maincent wrote:  
> > > In the case of 4-pair PoE, this led to incorrect enabled and
> > > delivering status values.    
> > 
> > Could you elaborate? The patch looks like a noop I must be missing some
> > key aspect..  
> 
> Reading the discussion on v1 it seems you're doing this to be safe,
> because there was a problem with x &= val & MASK; elsewhere.
> If that's the case, please resend to net-next and make it clear it's
> not a fix.

Indeed it fixes this issue.
Why do you prefer to have it on net-next instead of a net? We agreed with
Oleksij that it's where it should land. Do we have missed something?

Regards,
Jakub Kicinski Oct. 2, 2024, 2:31 p.m. UTC | #4
On Wed, 2 Oct 2024 14:53:02 +0200 Kory Maincent wrote:
> On Wed, 2 Oct 2024 05:27:32 -0700
> Jakub Kicinski <kuba@kernel.org> wrote:
> 
> > On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:  
> > > On Wed,  2 Oct 2024 12:23:40 +0200 Kory Maincent wrote:    
> > > > In the case of 4-pair PoE, this led to incorrect enabled and
> > > > delivering status values.      
> > > 
> > > Could you elaborate? The patch looks like a noop I must be missing some
> > > key aspect..    
> > 
> > Reading the discussion on v1 it seems you're doing this to be safe,
> > because there was a problem with x &= val & MASK; elsewhere.
> > If that's the case, please resend to net-next and make it clear it's
> > not a fix.  
> 
> Indeed it fixes this issue.

Is "this" here the &= issue or the sentence from the commit message?

> Why do you prefer to have it on net-next instead of a net? We agreed with
> Oleksij that it's where it should land. Do we have missed something?

The patch is a noop, AFAICT. Are you saying it changes how the code
behaves? 

The patch only coverts cases which are 

	ena = val & MASK;

the automatic type conversion will turn this into:

	ena = bool(val & MASK);
which is the same as:
	ena = !!(val & MASK);

The problem you were seeing earlier was that:

	ena &= val & MASK;

will be converted to:

	ena = ena & (val & MASK);

and that is:

	ena = bool(int(ena) & (val & MASK));
                   ^^^

IOW ena gets promoted to int for the & operation.
This problem does not occur with simple assignment.
Kory Maincent Oct. 2, 2024, 3 p.m. UTC | #5
On Wed, 2 Oct 2024 07:31:56 -0700
Jakub Kicinski <kuba@kernel.org> wrote:

> On Wed, 2 Oct 2024 14:53:02 +0200 Kory Maincent wrote:
> > On Wed, 2 Oct 2024 05:27:32 -0700
> > Jakub Kicinski <kuba@kernel.org> wrote:
> >   
> > > On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:    
>  [...]  
>  [...]  
>  [...]  
> > > 
> > > Reading the discussion on v1 it seems you're doing this to be safe,
> > > because there was a problem with x &= val & MASK; elsewhere.
> > > If that's the case, please resend to net-next and make it clear it's
> > > not a fix.    
> > 
> > Indeed it fixes this issue.  
> 
> Is "this" here the &= issue or the sentence from the commit message?
> 
> > Why do you prefer to have it on net-next instead of a net? We agreed with
> > Oleksij that it's where it should land. Do we have missed something?  
> 
> The patch is a noop, AFAICT. Are you saying it changes how the code
> behaves? 
> 
> The patch only coverts cases which are 
> 
> 	ena = val & MASK;
> 
> the automatic type conversion will turn this into:
> 
> 	ena = bool(val & MASK);
> which is the same as:
> 	ena = !!(val & MASK);
> 
> The problem you were seeing earlier was that:
> 
> 	ena &= val & MASK;
> 
> will be converted to:
> 
> 	ena = ena & (val & MASK);
> 
> and that is:
> 
> 	ena = bool(int(ena) & (val & MASK));
>                    ^^^
> 
> IOW ena gets promoted to int for the & operation.
> This problem does not occur with simple assignment.

Indeed you are totally right! It is a noop! Thanks!
Should I drop it?

Regards,
Jakub Kicinski Oct. 2, 2024, 3:02 p.m. UTC | #6
On Wed, 2 Oct 2024 17:00:47 +0200 Kory Maincent wrote:
> Should I drop it?

Your call, if you want to change things for consistency that's fine.
But you'd need to repost against net-next and without the Fixes tag.
diff mbox series

Patch

diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c
index 5c4e88be46ee..1a57c55f8577 100644
--- a/drivers/net/pse-pd/tps23881.c
+++ b/drivers/net/pse-pd/tps23881.c
@@ -139,9 +139,9 @@  static int tps23881_pi_is_enabled(struct pse_controller_dev *pcdev, int id)
 
 	chan = priv->port[id].chan[0];
 	if (chan < 4)
-		enabled = ret & BIT(chan);
+		enabled = !!(ret & BIT(chan));
 	else
-		enabled = ret & BIT(chan + 4);
+		enabled = !!(ret & BIT(chan + 4));
 
 	if (priv->port[id].is_4p) {
 		chan = priv->port[id].chan[1];
@@ -172,11 +172,11 @@  static int tps23881_ethtool_get_status(struct pse_controller_dev *pcdev,
 
 	chan = priv->port[id].chan[0];
 	if (chan < 4) {
-		enabled = ret & BIT(chan);
-		delivering = ret & BIT(chan + 4);
+		enabled = !!(ret & BIT(chan));
+		delivering = !!(ret & BIT(chan + 4));
 	} else {
-		enabled = ret & BIT(chan + 4);
-		delivering = ret & BIT(chan + 8);
+		enabled = !!(ret & BIT(chan + 4));
+		delivering = !!(ret & BIT(chan + 8));
 	}
 
 	if (priv->port[id].is_4p) {