* [PATCH net] net: axienet: fix a signedness bug in probe
@ 2019-09-25 10:59 Dan Carpenter
2019-09-25 11:05 ` Alvaro G. M
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Dan Carpenter @ 2019-09-25 10:59 UTC (permalink / raw)
To: Radhey Shyam Pandey, Alvaro G. M
Cc: David S. Miller, Michal Simek, Russell King, netdev,
kernel-janitors
The "lp->phy_mode" is an enum but in this context GCC treats it as an
unsigned int so the error handling is never triggered.
Fixes: ee06b1728b95 ("net: axienet: add support for standard phy-mode binding")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index 4fc627fb4d11..676006f32f91 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -1762,7 +1762,7 @@ static int axienet_probe(struct platform_device *pdev)
}
} else {
lp->phy_mode = of_get_phy_mode(pdev->dev.of_node);
- if (lp->phy_mode < 0) {
+ if ((int)lp->phy_mode < 0) {
ret = -EINVAL;
goto free_netdev;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-25 10:59 [PATCH net] net: axienet: fix a signedness bug in probe Dan Carpenter
@ 2019-09-25 11:05 ` Alvaro G. M
2019-09-25 11:35 ` David Miller
2019-09-26 13:18 ` Dan Carpenter
2019-09-25 12:01 ` Radhey Shyam Pandey
2019-09-27 8:17 ` David Miller
2 siblings, 2 replies; 8+ messages in thread
From: Alvaro G. M @ 2019-09-25 11:05 UTC (permalink / raw)
To: Dan Carpenter
Cc: Radhey Shyam Pandey, David S. Miller, Michal Simek, Russell King,
netdev, kernel-janitors
Hi, Dan
On Wed, Sep 25, 2019 at 01:59:11PM +0300, Dan Carpenter wrote:
> The "lp->phy_mode" is an enum but in this context GCC treats it as an
> unsigned int so the error handling is never triggered.
>
> lp->phy_mode = of_get_phy_mode(pdev->dev.of_node);
> - if (lp->phy_mode < 0) {
> + if ((int)lp->phy_mode < 0) {
This (almost) exact code appears in a lot of different drivers too,
so maybe it'd be nice to review them all and apply the same cast if needed?
Best regards
--
Alvaro G. M.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-25 11:05 ` Alvaro G. M
@ 2019-09-25 11:35 ` David Miller
2019-09-25 12:14 ` Andrew Lunn
2019-09-26 13:18 ` Dan Carpenter
1 sibling, 1 reply; 8+ messages in thread
From: David Miller @ 2019-09-25 11:35 UTC (permalink / raw)
To: alvaro.gamez
Cc: dan.carpenter, radhey.shyam.pandey, michal.simek, linux, netdev,
kernel-janitors
From: "Alvaro G. M" <alvaro.gamez@hazent.com>
Date: Wed, 25 Sep 2019 13:05:43 +0200
> Hi, Dan
>
> On Wed, Sep 25, 2019 at 01:59:11PM +0300, Dan Carpenter wrote:
>> The "lp->phy_mode" is an enum but in this context GCC treats it as an
>> unsigned int so the error handling is never triggered.
>>
>> lp->phy_mode = of_get_phy_mode(pdev->dev.of_node);
>> - if (lp->phy_mode < 0) {
>> + if ((int)lp->phy_mode < 0) {
>
> This (almost) exact code appears in a lot of different drivers too,
> so maybe it'd be nice to review them all and apply the same cast if needed?
Or make the thing an int if negative values are never valid 32-bit phy_mode
values anyways.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-25 10:59 [PATCH net] net: axienet: fix a signedness bug in probe Dan Carpenter
2019-09-25 11:05 ` Alvaro G. M
@ 2019-09-25 12:01 ` Radhey Shyam Pandey
2019-09-27 8:17 ` David Miller
2 siblings, 0 replies; 8+ messages in thread
From: Radhey Shyam Pandey @ 2019-09-25 12:01 UTC (permalink / raw)
To: Dan Carpenter, Alvaro G. M
Cc: David S. Miller, Michal Simek, Russell King,
netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
> -----Original Message-----
> From: Dan Carpenter <dan.carpenter@oracle.com>
> Sent: Wednesday, September 25, 2019 4:29 PM
> To: Radhey Shyam Pandey <radheys@xilinx.com>; Alvaro G. M
> <alvaro.gamez@hazent.com>
> Cc: David S. Miller <davem@davemloft.net>; Michal Simek
> <michals@xilinx.com>; Russell King <linux@armlinux.org.uk>;
> netdev@vger.kernel.org; kernel-janitors@vger.kernel.org
> Subject: [PATCH net] net: axienet: fix a signedness bug in probe
>
> The "lp->phy_mode" is an enum but in this context GCC treats it as an
> unsigned int so the error handling is never triggered.
>
> Fixes: ee06b1728b95 ("net: axienet: add support for standard phy-mode
> binding")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
> ---
> drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> index 4fc627fb4d11..676006f32f91 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> @@ -1762,7 +1762,7 @@ static int axienet_probe(struct platform_device
> *pdev)
> }
> } else {
> lp->phy_mode = of_get_phy_mode(pdev->dev.of_node);
> - if (lp->phy_mode < 0) {
> + if ((int)lp->phy_mode < 0) {
> ret = -EINVAL;
> goto free_netdev;
> }
> --
> 2.20.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-25 11:35 ` David Miller
@ 2019-09-25 12:14 ` Andrew Lunn
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Lunn @ 2019-09-25 12:14 UTC (permalink / raw)
To: David Miller
Cc: alvaro.gamez, dan.carpenter, radhey.shyam.pandey, michal.simek,
linux, netdev, kernel-janitors
On Wed, Sep 25, 2019 at 01:35:07PM +0200, David Miller wrote:
> From: "Alvaro G. M" <alvaro.gamez@hazent.com>
> Date: Wed, 25 Sep 2019 13:05:43 +0200
>
> > Hi, Dan
> >
> > On Wed, Sep 25, 2019 at 01:59:11PM +0300, Dan Carpenter wrote:
> >> The "lp->phy_mode" is an enum but in this context GCC treats it as an
> >> unsigned int so the error handling is never triggered.
> >>
> >> lp->phy_mode = of_get_phy_mode(pdev->dev.of_node);
> >> - if (lp->phy_mode < 0) {
> >> + if ((int)lp->phy_mode < 0) {
> >
> > This (almost) exact code appears in a lot of different drivers too,
> > so maybe it'd be nice to review them all and apply the same cast if needed?
>
> Or make the thing an int if negative values are never valid 32-bit phy_mode
> values anyways.
Maybe we should change the API
int of_get_phy_mode(struct device_node *np, phy_interface_t *phy_mode);
Separate the error from the value we are getting.
Andrew
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-25 11:05 ` Alvaro G. M
2019-09-25 11:35 ` David Miller
@ 2019-09-26 13:18 ` Dan Carpenter
2019-09-26 13:24 ` Andrew Lunn
1 sibling, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2019-09-26 13:18 UTC (permalink / raw)
To: Alvaro G. M
Cc: Radhey Shyam Pandey, David S. Miller, Michal Simek, Russell King,
netdev, kernel-janitors, Andrew Lunn
On Wed, Sep 25, 2019 at 01:05:43PM +0200, Alvaro G. M wrote:
> Hi, Dan
>
> On Wed, Sep 25, 2019 at 01:59:11PM +0300, Dan Carpenter wrote:
> > The "lp->phy_mode" is an enum but in this context GCC treats it as an
> > unsigned int so the error handling is never triggered.
> >
> > lp->phy_mode = of_get_phy_mode(pdev->dev.of_node);
> > - if (lp->phy_mode < 0) {
> > + if ((int)lp->phy_mode < 0) {
>
> This (almost) exact code appears in a lot of different drivers too,
> so maybe it'd be nice to review them all and apply the same cast if needed?
>
This is a new warning in Smatch. I did send patches for the whole
kernel. We won't get these bugs in the future because people run Smatch
on the kernel and will find the bugs. All the bugs were from 2017 or
later which suggests that someone cleared these out two years ago but
soon the 0-day bot will warn about issues so they will get fixed
quicker.
I'm sort of out of it today...
The get_phy_mode() function seem like they lend themselves to creating
these bugs. The ->phy_mode variables tend to be declared in the driver
so it would require quite a few patches to make them all int and I'm not
sure that's more beautiful. Andrew Lunn's idea to update the API would
probably be a good idea.
I'm going back to bed for now and I'll think about this some more.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-26 13:18 ` Dan Carpenter
@ 2019-09-26 13:24 ` Andrew Lunn
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Lunn @ 2019-09-26 13:24 UTC (permalink / raw)
To: Dan Carpenter
Cc: Alvaro G. M, Radhey Shyam Pandey, David S. Miller, Michal Simek,
Russell King, netdev, kernel-janitors
> The get_phy_mode() function seem like they lend themselves to creating
> these bugs. The ->phy_mode variables tend to be declared in the driver
> so it would require quite a few patches to make them all int and I'm not
> sure that's more beautiful. Andrew Lunn's idea to update the API would
> probably be a good idea.
Hi Dan
I started on it. Once net-next has opened, and 0-day has compile
tested my changes, i will post the code for review.
Andrew
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: axienet: fix a signedness bug in probe
2019-09-25 10:59 [PATCH net] net: axienet: fix a signedness bug in probe Dan Carpenter
2019-09-25 11:05 ` Alvaro G. M
2019-09-25 12:01 ` Radhey Shyam Pandey
@ 2019-09-27 8:17 ` David Miller
2 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2019-09-27 8:17 UTC (permalink / raw)
To: dan.carpenter
Cc: radhey.shyam.pandey, alvaro.gamez, michal.simek, linux, netdev,
kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 25 Sep 2019 13:59:11 +0300
> The "lp->phy_mode" is an enum but in this context GCC treats it as an
> unsigned int so the error handling is never triggered.
>
> Fixes: ee06b1728b95 ("net: axienet: add support for standard phy-mode binding")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-09-27 8:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-25 10:59 [PATCH net] net: axienet: fix a signedness bug in probe Dan Carpenter
2019-09-25 11:05 ` Alvaro G. M
2019-09-25 11:35 ` David Miller
2019-09-25 12:14 ` Andrew Lunn
2019-09-26 13:18 ` Dan Carpenter
2019-09-26 13:24 ` Andrew Lunn
2019-09-25 12:01 ` Radhey Shyam Pandey
2019-09-27 8:17 ` David Miller
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).