diff mbox series

net: ravb_main: fix a missing check of of_get_phy_mode

Message ID 20190312063827.16046-1-kjlu@umn.edu (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show
Series net: ravb_main: fix a missing check of of_get_phy_mode | expand

Commit Message

Kangjie Lu March 12, 2019, 6:38 a.m. UTC
of_get_phy_mode may fail and return a negative error code;
the fix checks the return value of of_get_phy_mode and
goes to out_release if it fails.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/net/ethernet/renesas/ravb_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Sergei Shtylyov March 12, 2019, 7:38 a.m. UTC | #1
On 12.03.2019 9:38, Kangjie Lu 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
> goes to out_release if it fails.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>   drivers/net/ethernet/renesas/ravb_main.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index d28c8f9ca55b..791b6842eb12 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -1996,6 +1996,7 @@ static int ravb_probe(struct platform_device *pdev)
>   	int error, irq, q;
>   	struct resource *res;
>   	int i;
> +	int ret;

    There's the 'error' variable already for such things, use it.

>   
>   	if (!np) {
>   		dev_err(&pdev->dev,
> @@ -2054,7 +2055,12 @@ static int ravb_probe(struct platform_device *pdev)
>   	spin_lock_init(&priv->lock);
>   	INIT_WORK(&priv->work, ravb_tx_timeout_work);
>   
> -	priv->phy_interface = of_get_phy_mode(np);
> +	ret = of_get_phy_mode(np);
> +	if (ret < 0) {
> +		error = -EINVAL;

    We typically propagate the errors upstream...

[...]

MBR, Sergei
Sergei Shtylyov March 12, 2019, 7:42 a.m. UTC | #2
On 12.03.2019 10:38, Sergei Shtylyov 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
>> goes to out_release if it fails.
>>
>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>> ---
>>   drivers/net/ethernet/renesas/ravb_main.c | 8 +++++++-
>>   1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c 
>> b/drivers/net/ethernet/renesas/ravb_main.c
>> index d28c8f9ca55b..791b6842eb12 100644
>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>> @@ -1996,6 +1996,7 @@ static int ravb_probe(struct platform_device *pdev)
>>       int error, irq, q;
>>       struct resource *res;
>>       int i;
>> +    int ret;
> 
>     There's the 'error' variable already for such things, use it.

    Please ignore that. But the variable could be named 'interface' or 
somesuch. :-)

[...]

MBR, Sergei
diff mbox series

Patch

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index d28c8f9ca55b..791b6842eb12 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1996,6 +1996,7 @@  static int ravb_probe(struct platform_device *pdev)
 	int error, irq, q;
 	struct resource *res;
 	int i;
+	int ret;
 
 	if (!np) {
 		dev_err(&pdev->dev,
@@ -2054,7 +2055,12 @@  static int ravb_probe(struct platform_device *pdev)
 	spin_lock_init(&priv->lock);
 	INIT_WORK(&priv->work, ravb_tx_timeout_work);
 
-	priv->phy_interface = of_get_phy_mode(np);
+	ret = of_get_phy_mode(np);
+	if (ret < 0) {
+		error = -EINVAL;
+		goto out_release;
+	}
+	priv->phy_interface = ret;
 
 	priv->no_avb_link = of_property_read_bool(np, "renesas,no-ether-link");
 	priv->avb_link_active_low =