All of lore.kernel.org
 help / color / mirror / Atom feed
* re: stmmac: pci: Add dwmac support for Loongson
@ 2021-06-21 15:51 Colin Ian King
  2021-06-21 16:51 ` Andrew Lunn
  2021-06-22  2:17 ` zhangqing
  0 siblings, 2 replies; 3+ messages in thread
From: Colin Ian King @ 2021-06-21 15:51 UTC (permalink / raw)
  To: Qing Zhang, Jiaxun Yang
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Coquelin, netdev,
	linux-kernel

Hi,

Static analysis by Coverity on today's linux-next has found an issue in
function loongson_dwmac_probe with the following commit:

commit 30bba69d7db40e732d6c0aa6d4890c60d717e314
Author: Qing Zhang <zhangqing@loongson.cn>
Date:   Fri Jun 18 10:53:34 2021 +0800

    stmmac: pci: Add dwmac support for Loongson

The analysis is as follows:

110        plat->phy_interface = device_get_phy_mode(&pdev->dev);

Enum compared against 0
(NO_EFFECT)
unsigned_compare: This less-than-zero comparison of an
unsigned value is never true. plat->phy_interface < 0U.

111        if (plat->phy_interface < 0)
112                dev_err(&pdev->dev, "phy_mode not found\n");

Enum plat->phy_interface is unsigned, so can't be negative and so the
comparison will always be false.

A possible fix is to use int variable ret for the assignment and check:


        ret = device_get_phy_mode(&pdev->dev);
        if (ret < 0)
                dev_err(&pdev->dev, "phy_mode not found\n");
        plat->phy_interface = ret;

..however, I think the dev_err may need handling too, e.g.

        ret = device_get_phy_mode(&pdev->dev);
        if (ret < 0) {
                dev_err(&pdev->dev, "phy_mode not found\n");
		ret = -ENODEV;
		goto cleanup;		/* needs to be written */
	}
        plat->phy_interface = ret;

Colin

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

* Re: stmmac: pci: Add dwmac support for Loongson
  2021-06-21 15:51 stmmac: pci: Add dwmac support for Loongson Colin Ian King
@ 2021-06-21 16:51 ` Andrew Lunn
  2021-06-22  2:17 ` zhangqing
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2021-06-21 16:51 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Qing Zhang, Jiaxun Yang, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, David S. Miller, Jakub Kicinski, Maxime Coquelin,
	netdev, linux-kernel

On Mon, Jun 21, 2021 at 04:51:28PM +0100, Colin Ian King wrote:
> Hi,
> 
> Static analysis by Coverity on today's linux-next has found an issue in
> function loongson_dwmac_probe with the following commit:
> 
> commit 30bba69d7db40e732d6c0aa6d4890c60d717e314
> Author: Qing Zhang <zhangqing@loongson.cn>
> Date:   Fri Jun 18 10:53:34 2021 +0800
> 
>     stmmac: pci: Add dwmac support for Loongson
> 
> The analysis is as follows:
> 
> 110        plat->phy_interface = device_get_phy_mode(&pdev->dev);
> 
> Enum compared against 0
> (NO_EFFECT)
> unsigned_compare: This less-than-zero comparison of an
> unsigned value is never true. plat->phy_interface < 0U.
> 
> 111        if (plat->phy_interface < 0)
> 112                dev_err(&pdev->dev, "phy_mode not found\n");
> 
> Enum plat->phy_interface is unsigned, so can't be negative and so the
> comparison will always be false.
> 
> A possible fix is to use int variable ret for the assignment and check:
> 
> 
>         ret = device_get_phy_mode(&pdev->dev);
>         if (ret < 0)
>                 dev_err(&pdev->dev, "phy_mode not found\n");
>         plat->phy_interface = ret;
> 
> ..however, I think the dev_err may need handling too, e.g.
> 
>         ret = device_get_phy_mode(&pdev->dev);
>         if (ret < 0) {
>                 dev_err(&pdev->dev, "phy_mode not found\n");
> 		ret = -ENODEV;
> 		goto cleanup;		/* needs to be written */
> 	}
>         plat->phy_interface = ret;

Potentially a cleaner fix is to use of_get_phy_mode(), which separates
the success/error value from the phy_interface_t.

    Andrew

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

* Re: stmmac: pci: Add dwmac support for Loongson
  2021-06-21 15:51 stmmac: pci: Add dwmac support for Loongson Colin Ian King
  2021-06-21 16:51 ` Andrew Lunn
@ 2021-06-22  2:17 ` zhangqing
  1 sibling, 0 replies; 3+ messages in thread
From: zhangqing @ 2021-06-22  2:17 UTC (permalink / raw)
  To: Colin Ian King, Jiaxun Yang
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Coquelin, netdev,
	linux-kernel



On 06/21/2021 11:51 PM, Colin Ian King wrote:
> Hi,
>
> Static analysis by Coverity on today's linux-next has found an issue in
> function loongson_dwmac_probe with the following commit:
>
> commit 30bba69d7db40e732d6c0aa6d4890c60d717e314
> Author: Qing Zhang <zhangqing@loongson.cn>
> Date:   Fri Jun 18 10:53:34 2021 +0800
>
>      stmmac: pci: Add dwmac support for Loongson
>
> The analysis is as follows:
>
> 110        plat->phy_interface = device_get_phy_mode(&pdev->dev);
>
> Enum compared against 0
> (NO_EFFECT)
> unsigned_compare: This less-than-zero comparison of an
> unsigned value is never true. plat->phy_interface < 0U.
>
> 111        if (plat->phy_interface < 0)
> 112                dev_err(&pdev->dev, "phy_mode not found\n");
>
> Enum plat->phy_interface is unsigned, so can't be negative and so the
> comparison will always be false.

Hi,Colin

Thanks for your advice,

I see this judgment in stmmac_platform.c:

plat->phy_interface = device_get_phy_mode(&pdev->dev);
if (plat->phy_interface < 0)
return ERR_PTR(plat->phy_interface);

plat->interface = stmmac_of_get_mac_mode(np);
if (plat->interface < 0)

>
> A possible fix is to use int variable ret for the assignment and check:
>
>
>          ret = device_get_phy_mode(&pdev->dev);
>          if (ret < 0)
>                  dev_err(&pdev->dev, "phy_mode not found\n");
>          plat->phy_interface = ret;
>
> ..however, I think the dev_err may need handling too, e.g.
>
>          ret = device_get_phy_mode(&pdev->dev);
>          if (ret < 0) {
>                  dev_err(&pdev->dev, "phy_mode not found\n");
> 		ret = -ENODEV;
> 		goto cleanup;		/* needs to be written */
> 	}
>          plat->phy_interface = ret;
>
> Colin
looks ok, but can be written to use of_get_phy_mode() , like this:

phy_interface_t interface;
ret = of_get_phy_mode(pdev->dev->of_node, &interface);
if (ret)
        return -EINVAL;


plat_dat->interface = interface;
if(!plat->interface)
dev_err(&pdev->dev, "Unsupported interface mode: %s",
         phy_modes(plat->interface));

Thanks

-Qing


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

end of thread, other threads:[~2021-06-22  2:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 15:51 stmmac: pci: Add dwmac support for Loongson Colin Ian King
2021-06-21 16:51 ` Andrew Lunn
2021-06-22  2:17 ` zhangqing

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.