netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic()
@ 2024-12-30  1:42 Su Hui
  2024-12-30  8:00 ` Michal Swiatkowski
  0 siblings, 1 reply; 5+ messages in thread
From: Su Hui @ 2024-12-30  1:42 UTC (permalink / raw)
  To: alexanderduyck, kuba, kernel-team, andrew+netdev, davem, edumazet,
	pabeni
  Cc: Su Hui, horms, mohsin.bashr, sanmanpradhan,
	kalesh-anakkur.purayil, netdev, linux-kernel, kernel-janitors

'fw_cmpl' is uninitialized which makes 'sensor' and '*val' to be stored
garbage value. Remove the whole body of fbnic_mac_get_sensor_asic() and
return -EOPNOTSUPP to fix this problem.

Fixes: d85ebade02e8 ("eth: fbnic: Add hardware monitoring support via HWMON interface")
Signed-off-by: Su Hui <suhui@nfschina.com>
Suggested-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
index 80b82ff12c4d..dd28c0f4c4b0 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
@@ -688,23 +688,7 @@ fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset,
 
 static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, long *val)
 {
-	struct fbnic_fw_completion fw_cmpl;
-	s32 *sensor;
-
-	switch (id) {
-	case FBNIC_SENSOR_TEMP:
-		sensor = &fw_cmpl.tsene.millidegrees;
-		break;
-	case FBNIC_SENSOR_VOLTAGE:
-		sensor = &fw_cmpl.tsene.millivolts;
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	*val = *sensor;
-
-	return 0;
+	return -EOPNOTSUPP;
 }
 
 static const struct fbnic_mac fbnic_mac_asic = {
-- 
2.30.2


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

* Re: [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic()
  2024-12-30  1:42 [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic() Su Hui
@ 2024-12-30  8:00 ` Michal Swiatkowski
  2024-12-30 16:52   ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Swiatkowski @ 2024-12-30  8:00 UTC (permalink / raw)
  To: Su Hui
  Cc: alexanderduyck, kuba, kernel-team, andrew+netdev, davem, edumazet,
	pabeni, horms, mohsin.bashr, sanmanpradhan,
	kalesh-anakkur.purayil, netdev, linux-kernel, kernel-janitors

On Mon, Dec 30, 2024 at 09:42:43AM +0800, Su Hui wrote:
> 'fw_cmpl' is uninitialized which makes 'sensor' and '*val' to be stored
> garbage value. Remove the whole body of fbnic_mac_get_sensor_asic() and
> return -EOPNOTSUPP to fix this problem.
> 
> Fixes: d85ebade02e8 ("eth: fbnic: Add hardware monitoring support via HWMON interface")
> Signed-off-by: Su Hui <suhui@nfschina.com>
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 18 +-----------------
>  1 file changed, 1 insertion(+), 17 deletions(-)
> 
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> index 80b82ff12c4d..dd28c0f4c4b0 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> @@ -688,23 +688,7 @@ fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset,
>  
>  static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, long *val)
>  {
> -	struct fbnic_fw_completion fw_cmpl;
Probably it should be:
*fw_cmpl = fbd->cmpl_data
but it is also never initialized.

> -	s32 *sensor;
> -
> -	switch (id) {
> -	case FBNIC_SENSOR_TEMP:
> -		sensor = &fw_cmpl.tsene.millidegrees;
> -		break;
> -	case FBNIC_SENSOR_VOLTAGE:
> -		sensor = &fw_cmpl.tsene.millivolts;
> -		break;
> -	default:
> -		return -EINVAL;
> -	}
> -
> -	*val = *sensor;
> -
> -	return 0;
> +	return -EOPNOTSUPP;

It is more like removing broken functionality than fixing (maybe whole
commit should be reverted). Anyway returning not support is also fine.

Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

>  }
>  
>  static const struct fbnic_mac fbnic_mac_asic = {
> -- 
> 2.30.2

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

* Re: [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic()
  2024-12-30  8:00 ` Michal Swiatkowski
@ 2024-12-30 16:52   ` Jakub Kicinski
  2025-01-03 18:07     ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2024-12-30 16:52 UTC (permalink / raw)
  To: Michal Swiatkowski
  Cc: Su Hui, alexanderduyck, kernel-team, andrew+netdev, davem,
	edumazet, pabeni, horms, mohsin.bashr, sanmanpradhan,
	kalesh-anakkur.purayil, netdev, linux-kernel, kernel-janitors

On Mon, 30 Dec 2024 09:00:20 +0100 Michal Swiatkowski wrote:
> > @@ -688,23 +688,7 @@ fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset,
> >  
> >  static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, long *val)
> >  {
> > -	struct fbnic_fw_completion fw_cmpl;  
> Probably it should be:
> *fw_cmpl = fbd->cmpl_data
> but it is also never initialized.

The other way around, the completion declared on the stack should be
the thing that gets assigned to the pointer in fbd :S

> > -	s32 *sensor;
> > -
> > -	switch (id) {
> > -	case FBNIC_SENSOR_TEMP:
> > -		sensor = &fw_cmpl.tsene.millidegrees;
> > -		break;
> > -	case FBNIC_SENSOR_VOLTAGE:
> > -		sensor = &fw_cmpl.tsene.millivolts;
> > -		break;
> > -	default:
> > -		return -EINVAL;
> > -	}
> > -
> > -	*val = *sensor;
> > -
> > -	return 0;
> > +	return -EOPNOTSUPP;  
> 
> It is more like removing broken functionality than fixing (maybe whole
> commit should be reverted). Anyway returning not support is also fine.

I defer to other maintainers. The gaps are trivial to fill in, we'll 
do so as soon as this patch makes it to net-next (this patch needs to
target net).

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

* Re: [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic()
  2024-12-30 16:52   ` Jakub Kicinski
@ 2025-01-03 18:07     ` Jakub Kicinski
  2025-01-06  1:08       ` Su Hui
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-01-03 18:07 UTC (permalink / raw)
  To: Michal Swiatkowski, Su Hui
  Cc: alexanderduyck, kernel-team, andrew+netdev, davem, edumazet,
	pabeni, horms, mohsin.bashr, sanmanpradhan,
	kalesh-anakkur.purayil, netdev, linux-kernel, kernel-janitors

On Mon, 30 Dec 2024 08:52:49 -0800 Jakub Kicinski wrote:
> > It is more like removing broken functionality than fixing (maybe whole
> > commit should be reverted). Anyway returning not support is also fine.  
> 
> I defer to other maintainers. The gaps are trivial to fill in, we'll 
> do so as soon as this patch makes it to net-next (this patch needs to
> target net).

Having slept on it, I think you're right.

Su Hui, could you send a revert of d85ebade02e8 instead?
It's around 126 LoC, not too bad.

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

* Re: [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic()
  2025-01-03 18:07     ` Jakub Kicinski
@ 2025-01-06  1:08       ` Su Hui
  0 siblings, 0 replies; 5+ messages in thread
From: Su Hui @ 2025-01-06  1:08 UTC (permalink / raw)
  To: Jakub Kicinski, Michal Swiatkowski, Su Hui
  Cc: alexanderduyck, kernel-team, andrew+netdev, davem, edumazet,
	pabeni, horms, mohsin.bashr, sanmanpradhan,
	kalesh-anakkur.purayil, netdev, linux-kernel, kernel-janitors

On 2025/1/4 02:07, Jakub Kicinski wrote:
> On Mon, 30 Dec 2024 08:52:49 -0800 Jakub Kicinski wrote:
>>> It is more like removing broken functionality than fixing (maybe whole
>>> commit should be reverted). Anyway returning not support is also fine.
>> I defer to other maintainers. The gaps are trivial to fill in, we'll
>> do so as soon as this patch makes it to net-next (this patch needs to
>> target net).
> Having slept on it, I think you're right.
>
> Su Hui, could you send a revert of d85ebade02e8 instead?
> It's around 126 LoC, not too bad.

OK, I will send v3 to revert d85ebade02e8 soon.

Su Hui


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

end of thread, other threads:[~2025-01-06  1:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-30  1:42 [PATCH v2] eth: fbnic: Avoid garbage value in fbnic_mac_get_sensor_asic() Su Hui
2024-12-30  8:00 ` Michal Swiatkowski
2024-12-30 16:52   ` Jakub Kicinski
2025-01-03 18:07     ` Jakub Kicinski
2025-01-06  1:08       ` Su Hui

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