diff mbox

[v3] stmmac: fix check for phydev being open

Message ID 1441701786-10789-1-git-send-email-abrodkin@synopsys.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Alexey Brodkin Sept. 8, 2015, 8:43 a.m. UTC
Current check of phydev with IS_ERR(phydev) may make not much sense
because of_phy_connect() returns NULL on failure instead of error value.

Still for checking result of phy_connect() IS_ERR() makes perfect sense.

So let's use combined check IS_ERR_OR_NULL() that covers both cases.

Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
---

Changes compared to v2:
 * Updated commit message with mention of of_phy_connect() instead of
   of_phy_attach().
 * Return ENODEV in case of of_phy_connect() failure

Changes compared to v1:
 * Use IS_ERR_OR_NULL() instead of discrete checks for null and err

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Sergei Shtylyov Sept. 8, 2015, 11:20 a.m. UTC | #1
Hello.

On 9/8/2015 11:43 AM, Alexey Brodkin wrote:

> Current check of phydev with IS_ERR(phydev) may make not much sense
> because of_phy_connect() returns NULL on failure instead of error value.
>
> Still for checking result of phy_connect() IS_ERR() makes perfect sense.
>
> So let's use combined check IS_ERR_OR_NULL() that covers both cases.
>
> Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: stable@vger.kernel.org
> Cc: David Miller <davem@davemloft.net>
> Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
> ---
>
> Changes compared to v2:
>   * Updated commit message with mention of of_phy_connect() instead of
>     of_phy_attach().
>   * Return ENODEV in case of of_phy_connect() failure
>
> Changes compared to v1:
>   * Use IS_ERR_OR_NULL() instead of discrete checks for null and err
>
>   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 864b476..e2c9c86 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -837,9 +837,12 @@ static int stmmac_init_phy(struct net_device *dev)
>   				     interface);
>   	}
>
> -	if (IS_ERR(phydev)) {
> +	if (IS_ERR_OR_NULL(phydev)) {
>   		pr_err("%s: Could not attach to PHY\n", dev->name);
> -		return PTR_ERR(phydev);
> +		if (!phydev)
> +			return -ENODEV;
> +		else
> +			return PTR_ERR(phydev);

    Don't need *else* after *return* and scripts/checkpatch.pl should have 
complained about that.

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexey Brodkin Sept. 8, 2015, 12:46 p.m. UTC | #2
Hi Sergei,

On Tue, 2015-09-08 at 14:20 +0300, Sergei Shtylyov wrote:
> Hello.
> 
> On 9/8/2015 11:43 AM, Alexey Brodkin wrote:
> 
> > Current check of phydev with IS_ERR(phydev) may make not much sense
> > because of_phy_connect() returns NULL on failure instead of error value.
> > 
> > Still for checking result of phy_connect() IS_ERR() makes perfect sense.
> > 
> > So let's use combined check IS_ERR_OR_NULL() that covers both cases.
> > 
> > Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> > Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> > Cc: linux-kernel@vger.kernel.org
> > Cc: stable@vger.kernel.org
> > Cc: David Miller <davem@davemloft.net>
> > Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
> > ---
> > 
> > Changes compared to v2:
> >   * Updated commit message with mention of of_phy_connect() instead of
> >     of_phy_attach().
> >   * Return ENODEV in case of of_phy_connect() failure
> > 
> > Changes compared to v1:
> >   * Use IS_ERR_OR_NULL() instead of discrete checks for null and err
> > 
> >   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
> >   1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 864b476..e2c9c86 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -837,9 +837,12 @@ static int stmmac_init_phy(struct net_device *dev)
> >   				     interface);
> >   	}
> > 
> > -	if (IS_ERR(phydev)) {
> > +	if (IS_ERR_OR_NULL(phydev)) {
> >   		pr_err("%s: Could not attach to PHY\n", dev->name);
> > -		return PTR_ERR(phydev);
> > +		if (!phydev)
> > +			return -ENODEV;
> > +		else
> > +			return PTR_ERR(phydev);
> 
>     Don't need *else* after *return* and scripts/checkpatch.pl should have 
> complained about that.

./scripts/checkpatch.pl 0001-stmmac-fix-check-for-phydev-being-open.patch 
total: 0 errors, 0 warnings, 0 checks, 14 lines checked

-Alexey--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sergei Shtylyov Sept. 8, 2015, 7:53 p.m. UTC | #3
Hello.

On 09/08/2015 03:46 PM, Alexey Brodkin wrote:

>>> Current check of phydev with IS_ERR(phydev) may make not much sense
>>> because of_phy_connect() returns NULL on failure instead of error value.
>>>
>>> Still for checking result of phy_connect() IS_ERR() makes perfect sense.
>>>
>>> So let's use combined check IS_ERR_OR_NULL() that covers both cases.
>>>
>>> Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>>> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
>>> Cc: linux-kernel@vger.kernel.org
>>> Cc: stable@vger.kernel.org
>>> Cc: David Miller <davem@davemloft.net>
>>> Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
>>> ---
>>>
>>> Changes compared to v2:
>>>    * Updated commit message with mention of of_phy_connect() instead of
>>>      of_phy_attach().
>>>    * Return ENODEV in case of of_phy_connect() failure
>>>
>>> Changes compared to v1:
>>>    * Use IS_ERR_OR_NULL() instead of discrete checks for null and err
>>>
>>>    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
>>>    1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>>> index 864b476..e2c9c86 100644
>>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>>> @@ -837,9 +837,12 @@ static int stmmac_init_phy(struct net_device *dev)
>>>    				     interface);
>>>    	}
>>>
>>> -	if (IS_ERR(phydev)) {
>>> +	if (IS_ERR_OR_NULL(phydev)) {
>>>    		pr_err("%s: Could not attach to PHY\n", dev->name);
>>> -		return PTR_ERR(phydev);
>>> +		if (!phydev)
>>> +			return -ENODEV;
>>> +		else
>>> +			return PTR_ERR(phydev);
>>
>>      Don't need *else* after *return* and scripts/checkpatch.pl should have
>> complained about that.
>
> ./scripts/checkpatch.pl 0001-stmmac-fix-check-for-phydev-being-open.patch
> total: 0 errors, 0 warnings, 0 checks, 14 lines checked

    Hm... I bet I saw such warning from checkpatch.pl recently (it was a false 
positive though, so maybe the check was removed recently, not sure). Your 
patch is clean indeed, however my comment is still valid.

> -Alexey

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexey Brodkin Sept. 9, 2015, 2:44 p.m. UTC | #4
Hi Sergei,

On Tue, 2015-09-08 at 22:53 +0300, Sergei Shtylyov wrote:
> Hello.
> 
> On 09/08/2015 03:46 PM, Alexey Brodkin wrote:
> 
> > > > Current check of phydev with IS_ERR(phydev) may make not much sense
> > > > because of_phy_connect() returns NULL on failure instead of error value.
> > > > 
> > > > Still for checking result of phy_connect() IS_ERR() makes perfect sense.
> > > > 
> > > > So let's use combined check IS_ERR_OR_NULL() that covers both cases.
> > > > 
> > > > Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> > > > Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> > > > Cc: linux-kernel@vger.kernel.org
> > > > Cc: stable@vger.kernel.org
> > > > Cc: David Miller <davem@davemloft.net>
> > > > Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
> > > > ---
> > > > 
> > > > Changes compared to v2:
> > > >    * Updated commit message with mention of of_phy_connect() instead of
> > > >      of_phy_attach().
> > > >    * Return ENODEV in case of of_phy_connect() failure
> > > > 
> > > > Changes compared to v1:
> > > >    * Use IS_ERR_OR_NULL() instead of discrete checks for null and err
> > > > 
> > > >    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
> > > >    1 file changed, 5 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > > > b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > > > index 864b476..e2c9c86 100644
> > > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > > > @@ -837,9 +837,12 @@ static int stmmac_init_phy(struct net_device *dev)
> > > >    				     interface);
> > > >    	}
> > > > 
> > > > -	if (IS_ERR(phydev)) {
> > > > +	if (IS_ERR_OR_NULL(phydev)) {
> > > >    		pr_err("%s: Could not attach to PHY\n", dev->name);
> > > > -		return PTR_ERR(phydev);
> > > > +		if (!phydev)
> > > > +			return -ENODEV;
> > > > +		else
> > > > +			return PTR_ERR(phydev);
> > > 
> > >      Don't need *else* after *return* and scripts/checkpatch.pl should have
> > > complained about that.
> > 
> > ./scripts/checkpatch.pl 0001-stmmac-fix-check-for-phydev-being-open.patch
> > total: 0 errors, 0 warnings, 0 checks, 14 lines checked
> 
>     Hm... I bet I saw such warning from checkpatch.pl recently (it was a false 
> positive though, so maybe the check was removed recently, not sure). Your 
> patch is clean indeed, however my comment is still valid.

Ok, let me send another respin then.

-Alexey--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 864b476..e2c9c86 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -837,9 +837,12 @@  static int stmmac_init_phy(struct net_device *dev)
 				     interface);
 	}
 
-	if (IS_ERR(phydev)) {
+	if (IS_ERR_OR_NULL(phydev)) {
 		pr_err("%s: Could not attach to PHY\n", dev->name);
-		return PTR_ERR(phydev);
+		if (!phydev)
+			return -ENODEV;
+		else
+			return PTR_ERR(phydev);
 	}
 
 	/* Stop Advertising 1000BASE Capability if interface is not GMII */