net: pse-pd: tps23881: Fix boolean evaluation for bitmask checks
Subsystems (3)
Kory Maincent
maintainerPATCH v2 1/1 net: pse-pd: tps23881: Fix boolean evaluation for bitmask checks
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.
---
Change in v2:
- Update commit message to describe the issue.
drivers/net/pse-pd/tps23881.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/pse-pd/tps23881.c +6 -6
@@ -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) {
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 2 lines · 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
maintainerQuoted 6 lines · On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:
Quoted 2 lines · 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
maintainerQuoted 5 lines · On Wed, 2 Oct 2024 05:27:32 -0700 Jakub Kicinski <[email protected]> wrote:
Quoted 4 lines · On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:
Quoted 2 lines · 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.
Quoted 7 lines
Quoted 2 lines
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,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Jakub Kicinski
maintainerQuoted 11 lines · On Wed, 2 Oct 2024 14:53:02 +0200 Kory Maincent wrote:
Quoted 8 lines · On Wed, 2 Oct 2024 05:27:32 -0700 Jakub Kicinski <[email protected]> wrote:
Quoted 6 lines · On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:
Quoted 2 lines · 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..
Quoted 6 lines
Quoted 4 lines
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?
Quoted 2 lines
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
maintainerQuoted 42 lines · On Wed, 2 Oct 2024 07:31:56 -0700 Jakub Kicinski <[email protected]> wrote:
Quoted 4 lines · On Wed, 2 Oct 2024 14:53:02 +0200 Kory Maincent wrote:
Quoted 1 line · On Wed, 2 Oct 2024 05:27:32 -0700 Jakub Kicinski <[email protected]> wrote:
On Wed, 2 Oct 2024 05:24:31 -0700 Jakub Kicinski wrote:
[...]
[...]
[...]Quoted 7 lines
Quoted 5 lines
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?
Quoted 2 lines
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);
Quoted 7 lines
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,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Jakub Kicinski
maintainerQuoted 1 line · 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.