netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval
@ 2025-02-17 13:48 Kory Maincent
  2025-02-17 15:24 ` Andrew Lunn
  2025-02-19  2:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Kory Maincent @ 2025-02-17 13:48 UTC (permalink / raw)
  To: Jakub Kicinski, Oleksij Rempel, Kory Maincent (Dent Project),
	netdev, linux-kernel
  Cc: thomas.petazzoni, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni

Fix incorrect data offset read in the pd692x0_pi_get_pw_limit callback.
The issue was previously unnoticed as it was only used by the regulator
API and not thoroughly tested, since the PSE is mainly controlled via
ethtool.

The function became actively used by ethtool after commit 3e9dbfec4998
("net: pse-pd: Split ethtool_get_status into multiple callbacks"),
which led to the discovery of this issue.

Fix it by using the correct data offset.

Fixes: a87e699c9d33 ("net: pse-pd: pd692x0: Enhance with new current limit and voltage read callbacks")
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
 drivers/net/pse-pd/pd692x0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c
index fc9e23927b3b..7d60a714ca53 100644
--- a/drivers/net/pse-pd/pd692x0.c
+++ b/drivers/net/pse-pd/pd692x0.c
@@ -1047,7 +1047,7 @@ static int pd692x0_pi_get_pw_limit(struct pse_controller_dev *pcdev,
 	if (ret < 0)
 		return ret;
 
-	return pd692x0_pi_get_pw_from_table(buf.data[2], buf.data[3]);
+	return pd692x0_pi_get_pw_from_table(buf.data[0], buf.data[1]);
 }
 
 static int pd692x0_pi_set_pw_limit(struct pse_controller_dev *pcdev,
-- 
2.34.1


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

* Re: [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval
  2025-02-17 13:48 [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval Kory Maincent
@ 2025-02-17 15:24 ` Andrew Lunn
  2025-02-17 16:15   ` Kory Maincent
  2025-02-19  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2025-02-17 15:24 UTC (permalink / raw)
  To: Kory Maincent
  Cc: Jakub Kicinski, Oleksij Rempel, netdev, linux-kernel,
	thomas.petazzoni, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni

On Mon, Feb 17, 2025 at 02:48:11PM +0100, Kory Maincent wrote:
> Fix incorrect data offset read in the pd692x0_pi_get_pw_limit callback.
> The issue was previously unnoticed as it was only used by the regulator
> API and not thoroughly tested, since the PSE is mainly controlled via
> ethtool.
> 
> The function became actively used by ethtool after commit 3e9dbfec4998
> ("net: pse-pd: Split ethtool_get_status into multiple callbacks"),
> which led to the discovery of this issue.
> 
> Fix it by using the correct data offset.
> 
> Fixes: a87e699c9d33 ("net: pse-pd: pd692x0: Enhance with new current limit and voltage read callbacks")
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---
>  drivers/net/pse-pd/pd692x0.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c
> index fc9e23927b3b..7d60a714ca53 100644
> --- a/drivers/net/pse-pd/pd692x0.c
> +++ b/drivers/net/pse-pd/pd692x0.c
> @@ -1047,7 +1047,7 @@ static int pd692x0_pi_get_pw_limit(struct pse_controller_dev *pcdev,
>  	if (ret < 0)
>  		return ret;
>  
> -	return pd692x0_pi_get_pw_from_table(buf.data[2], buf.data[3]);
> +	return pd692x0_pi_get_pw_from_table(buf.data[0], buf.data[1]);

Would the issue of been more obvious if some #defines were used,
rather than magic numbers?

	Andrew

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

* Re: [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval
  2025-02-17 15:24 ` Andrew Lunn
@ 2025-02-17 16:15   ` Kory Maincent
  2025-02-19  2:33     ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Kory Maincent @ 2025-02-17 16:15 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Jakub Kicinski, Oleksij Rempel, netdev, linux-kernel,
	thomas.petazzoni, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni

On Mon, 17 Feb 2025 16:24:44 +0100
Andrew Lunn <andrew@lunn.ch> wrote:

> On Mon, Feb 17, 2025 at 02:48:11PM +0100, Kory Maincent wrote:
> > Fix incorrect data offset read in the pd692x0_pi_get_pw_limit callback.
> > The issue was previously unnoticed as it was only used by the regulator
> > API and not thoroughly tested, since the PSE is mainly controlled via
> > ethtool.
> > 
> > The function became actively used by ethtool after commit 3e9dbfec4998
> > ("net: pse-pd: Split ethtool_get_status into multiple callbacks"),
> > which led to the discovery of this issue.
> > 
> > Fix it by using the correct data offset.
> > 
> > Fixes: a87e699c9d33 ("net: pse-pd: pd692x0: Enhance with new current limit
> > and voltage read callbacks") Signed-off-by: Kory Maincent
> > <kory.maincent@bootlin.com> ---
> >  drivers/net/pse-pd/pd692x0.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c
> > index fc9e23927b3b..7d60a714ca53 100644
> > --- a/drivers/net/pse-pd/pd692x0.c
> > +++ b/drivers/net/pse-pd/pd692x0.c
> > @@ -1047,7 +1047,7 @@ static int pd692x0_pi_get_pw_limit(struct
> > pse_controller_dev *pcdev, if (ret < 0)
> >  		return ret;
> >  
> > -	return pd692x0_pi_get_pw_from_table(buf.data[2], buf.data[3]);
> > +	return pd692x0_pi_get_pw_from_table(buf.data[0], buf.data[1]);  
> 
> Would the issue of been more obvious if some #defines were used,
> rather than magic numbers?

We would need lots of defines as the offset of the useful data can
change between each command. Don't know if it would have been better. 

On my current patch priority series.
git grep "buf\." drivers/net/pse-pd/pd692x0.c | wc -l
29

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

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

* Re: [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval
  2025-02-17 16:15   ` Kory Maincent
@ 2025-02-19  2:33     ` Jakub Kicinski
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2025-02-19  2:33 UTC (permalink / raw)
  To: Kory Maincent
  Cc: Andrew Lunn, Oleksij Rempel, netdev, linux-kernel,
	thomas.petazzoni, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni

On Mon, 17 Feb 2025 17:15:00 +0100 Kory Maincent wrote:
> > > -	return pd692x0_pi_get_pw_from_table(buf.data[2], buf.data[3]);
> > > +	return pd692x0_pi_get_pw_from_table(buf.data[0], buf.data[1]);    
> > 
> > Would the issue of been more obvious if some #defines were used,
> > rather than magic numbers?  
> 
> We would need lots of defines as the offset of the useful data can
> change between each command. Don't know if it would have been better. 
> 
> On my current patch priority series.
> git grep "buf\." drivers/net/pse-pd/pd692x0.c | wc -l
> 29

I guess it'd take a bigger rewrite, so I'll apply.
But I fully agree with Andrew that the current coding is very error
prone :( If you ever need to add more message you should start from
refactoring this code..

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

* Re: [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval
  2025-02-17 13:48 [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval Kory Maincent
  2025-02-17 15:24 ` Andrew Lunn
@ 2025-02-19  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-02-19  2:40 UTC (permalink / raw)
  To: Kory Maincent
  Cc: kuba, o.rempel, netdev, linux-kernel, thomas.petazzoni,
	andrew+netdev, davem, edumazet, pabeni

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 17 Feb 2025 14:48:11 +0100 you wrote:
> Fix incorrect data offset read in the pd692x0_pi_get_pw_limit callback.
> The issue was previously unnoticed as it was only used by the regulator
> API and not thoroughly tested, since the PSE is mainly controlled via
> ethtool.
> 
> The function became actively used by ethtool after commit 3e9dbfec4998
> ("net: pse-pd: Split ethtool_get_status into multiple callbacks"),
> which led to the discovery of this issue.
> 
> [...]

Here is the summary with links:
  - [net] net: pse-pd: pd692x0: Fix power limit retrieval
    https://git.kernel.org/netdev/net/c/f6093c5ec74d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-02-19  2:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-17 13:48 [PATCH net] net: pse-pd: pd692x0: Fix power limit retrieval Kory Maincent
2025-02-17 15:24 ` Andrew Lunn
2025-02-17 16:15   ` Kory Maincent
2025-02-19  2:33     ` Jakub Kicinski
2025-02-19  2:40 ` patchwork-bot+netdevbpf

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