[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdVfhq-d0CExnH+Y37k6pUz6OvOtScf6RbgFQ-Mx4dy4DA@mail.gmail.com>
Date: Mon, 11 Mar 2019 11:59:23 +0100
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Kangjie Lu <kjlu@....edu>
Cc: pakki001@....edu,
Sergei Shtylyov <sergei.shtylyov@...entembedded.com>,
"David S. Miller" <davem@...emloft.net>,
Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>,
Geert Uytterhoeven <geert+renesas@...der.be>,
Simon Horman <horms+renesas@...ge.net.au>,
Chris Brandt <chris.brandt@...esas.com>,
netdev <netdev@...r.kernel.org>,
Linux-Renesas <linux-renesas-soc@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] net: renesas: fix a missing check of of_get_phy_mode
Hi Kangjie,
On Mon, Mar 11, 2019 at 8:50 AM Kangjie Lu <kjlu@....edu> wrote:
> of_get_phy_mode may fail and return a negative error code;
> the fix checks the return value of of_get_phy_mode and
> returns NULL of it fails.
>
> Signed-off-by: Kangjie Lu <kjlu@....edu>
> --- a/drivers/net/ethernet/renesas/sh_eth.c
> +++ b/drivers/net/ethernet/renesas/sh_eth.c
> @@ -3187,6 +3187,8 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
> return NULL;
>
> pdata->phy_interface = of_get_phy_mode(np);
> + if (pdata->phy_interface < 0)
> + return NULL;
sh_eth_plat_data.phy_interface has type phy_interface_t.
This is an enum containing only positive values, hence it is unsigned.
So the condition can never be true.
of_get_phy_mode() returns int, as it has to indicate errors by returning
negative error codes. Hence please use an intermediate of type int:
int ret;
...
ret = of_get_phy_mode(np);
if (ret < 0)
return NULL;
pdata->phy_interface = ret;
>
> mac_addr = of_get_mac_address(np);
> if (mac_addr)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Powered by blists - more mailing lists