netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: pse-pd: tps23881: Fix boolean evaluation for bitmask checks
@ 2024-10-02 10:23 Kory Maincent
  2024-10-02 12:24 ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Kory Maincent @ 2024-10-02 10:23 UTC (permalink / raw)
  To: Kory Maincent (Dent Project), Jakub Kicinski, netdev,
	linux-kernel
  Cc: Kyle Swenson, Simon Horman, Oleksij Rempel, thomas.petazzoni,
	David S. Miller, Eric Dumazet, Paolo Abeni

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(-)

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) {
-- 
2.34.1


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

end of thread, other threads:[~2024-10-02 15:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 10:23 [PATCH net v2] net: pse-pd: tps23881: Fix boolean evaluation for bitmask checks Kory Maincent
2024-10-02 12:24 ` Jakub Kicinski
2024-10-02 12:27   ` Jakub Kicinski
2024-10-02 12:53     ` Kory Maincent
2024-10-02 14:31       ` Jakub Kicinski
2024-10-02 15:00         ` Kory Maincent
2024-10-02 15:02           ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).