Skip to contentSkip to conversation

net: renesas: fix a missing check of of_get_phy_mode

PATCH Superseded Kangjie Lu 4 participants 12 messages Mar 11, 2019 – Mar 12, 2019

Subsystems (3)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH v2 1/1 net: renesas: fix a missing check of of_get_phy_mode

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.

---
 drivers/net/ethernet/renesas/sh_eth.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/renesas/sh_eth.c +2 -0
index 339b2eae2100..239eeafe1b2d 100644
@@ -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;
 
 	mac_addr = of_get_mac_address(np);
 	if (mac_addr)
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw

Hello!

Quoted 3 lines · Kangjie Lu

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.

Sorry, I overlooked this issue.

Quoted 1 line
Fixes b356e978e92f ("sh_eth: add device tree support")
Quoted 3 lines
---
 drivers/net/ethernet/renesas/sh_eth.c | 2 ++
 1 file changed, 2 insertions(+)

Why are you not fixing ravb_main.c as well? Especially as you have "renesas:"
in your subject, not "sh_eth:"? :-/

[...]

MBR, Sergei

maintainer
#2 lore raw

From: Sergei Shtylyov <[email protected]>
Date: Mon, 11 Mar 2019 13:29:10 +0300

Quoted 15 lines

Hello!

Quoted 3 lines · Kangjie Lu

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.

Sorry, I overlooked this issue.

Quoted 1 line
Fixes b356e978e92f ("sh_eth: add device tree support")
Quoted 6 lines
Quoted 3 lines
---
 drivers/net/ethernet/renesas/sh_eth.c | 2 ++
 1 file changed, 2 insertions(+)

Why are you not fixing ravb_main.c as well? Especially as you have "renesas:"
in your subject, not "sh_eth:"? :-/

Kangjie please fix the subject line and incorporate Sergei's Fixes and Reviewed-by tags.

Thanks.

#3 lore raw
Quoted 15 lines · David Miller
Quoted 15 lines
Quoted 3 lines

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.

Sorry, I overlooked this issue.

Quoted 1 line
Fixes b356e978e92f ("sh_eth: add device tree support")
Quoted 3 lines
---
 drivers/net/ethernet/renesas/sh_eth.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 5 lines
Quoted 2 lines

Why are you not fixing ravb_main.c as well? Especially as you have "renesas:"
in your subject, not "sh_eth:"? :-/

Kangjie please fix the subject line and incorporate Sergei's Fixes and Reviewed-by tags.

For the record, this patch was a nop, I have to NAK it. Kangjie, please address
Geert's feedback, thanks.

Quoted 1 line

Thanks.

MBR, Sergei

author
#4 lore raw

PATCH v2 1/1 net: sh_eth: fix a missing check of of_get_phy_mode

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.

---
 drivers/net/ethernet/renesas/sh_eth.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/renesas/sh_eth.c +4 -2
index 239eeafe1b2d..e33af371b169 100644
@@ -3181,14 +3181,16 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
 	struct device_node *np = dev->of_node;
 	struct sh_eth_plat_data *pdata;
 	const char *mac_addr;
+	int ret;
 
 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return NULL;
 
-	pdata->phy_interface = of_get_phy_mode(np);
-	if (pdata->phy_interface < 0)
+	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)
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH v2] net: sh_eth: fix a missing check of of_get_phy_mode

Hello!

Quoted 15 lines · Kangjie Lu

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.

---
  drivers/net/ethernet/renesas/sh_eth.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/renesas/sh_eth.c +0 -0
index 239eeafe1b2d..e33af371b169 100644
@@ -3181,14 +3181,16 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
  	struct device_node *np = dev->of_node;

drivers/net/ethernet/renesas/sh_eth.c static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) · line 3190

Quoted 10 lines
drivers/net/ethernet/renesas/sh_eth.c +1 -2
  	struct sh_eth_plat_data *pdata;
  	const char *mac_addr;
+	int ret;
 
  	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  	if (!pdata)
  		return NULL;
 
-	pdata->phy_interface = of_get_phy_mode(np);
-	if (pdata->phy_interface < 0)

Please generate your patch against the pristine net.git, not atop
of your previous version.

drivers/net/ethernet/renesas/sh_eth.c static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) · line 3196

Quoted 8 lines
drivers/net/ethernet/renesas/sh_eth.c +3 -0
+	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)

MBR, Sergei

author
#6 lore raw

PATCH v3 1/1 net: sh_eth: fix a missing check of of_get_phy_mode

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.

---
 drivers/net/ethernet/renesas/sh_eth.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/renesas/sh_eth.c +5 -1
index 339b2eae2100..e33af371b169 100644
@@ -3181,12 +3181,16 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
 	struct device_node *np = dev->of_node;
 	struct sh_eth_plat_data *pdata;
 	const char *mac_addr;
+	int ret;
 
 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return NULL;
 
-	pdata->phy_interface = of_get_phy_mode(np);
+	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)
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#7 lore raw

Re: [PATCH v3] net: sh_eth: fix a missing check of of_get_phy_mode

Quoted 5 lines · Kangjie Lu

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.

Fixes b356e978e92f ("sh_eth: add device tree support")
Quoted 1 line

---

It's a good practice to describe the changes between the patch versions here.

[...]

MBR, Sergei

Reviewed-by Tested-by on v3 1/1
#8 lore raw

Re: [PATCH v3] net: sh_eth: fix a missing check of of_get_phy_mode

In reply to Kangjie Lu

Hi Kangjie,

Quoted 5 lines · Kangjie Lu

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.

Thanks for the update!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#10 lore raw
In reply to Kangjie Lu

Hi Kangjie,

Quoted 9 lines · Kangjie Lu

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.

drivers/net/ethernet/renesas/sh_eth.c static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) · line 3191

Quoted 5 lines
drivers/net/ethernet/renesas/sh_eth.c +2 -0
@@ -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;

drivers/net/ethernet/renesas/sh_eth.c static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) · line 3194

Quoted 3 lines
drivers/net/ethernet/renesas/sh_eth.c +0 -0
        mac_addr = of_get_mac_address(np);
        if (mac_addr)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#11 lore raw
Quoted 11 lines · Geert Uytterhoeven
Quoted 11 lines

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.

drivers/net/ethernet/renesas/sh_eth.c +0 -0
@@ -3187,6 +3187,8 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
                return NULL;
 
Quoted 7 lines

drivers/net/ethernet/renesas/sh_eth.c static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) · line 3191

Quoted 3 lines
drivers/net/ethernet/renesas/sh_eth.c +2 -0
        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.

Good catch, thank you!
My gcc doesn't warn but doesn't generate the code for the branch either...

[...]

Quoted 3 lines

Gr{oetje,eeting}s,

Geert

MBR, Sergei