From: Andrew Lunn <andrew@lunn.ch>
To: Colin Ian King <colin.king@canonical.com>
Cc: Qing Zhang <zhangqing@loongson.cn>,
Jiaxun Yang <jiaxun.yang@flygoat.com>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: stmmac: pci: Add dwmac support for Loongson
Date: Mon, 21 Jun 2021 18:51:57 +0200 [thread overview]
Message-ID: <YNDDrQVuCjlWTEou@lunn.ch> (raw)
In-Reply-To: <37057fe8-f7d1-7ee0-01c7-916577526b5b@canonical.com>
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
next prev parent reply other threads:[~2021-06-21 16:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-21 15:51 Colin Ian King
2021-06-21 16:51 ` Andrew Lunn [this message]
2021-06-22 2:17 ` zhangqing
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YNDDrQVuCjlWTEou@lunn.ch \
--to=andrew@lunn.ch \
--cc=alexandre.torgue@foss.st.com \
--cc=colin.king@canonical.com \
--cc=davem@davemloft.net \
--cc=jiaxun.yang@flygoat.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=peppe.cavallaro@st.com \
--cc=zhangqing@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®