diff mbox

[3.3.0,1/3] net:phy:bcm63xx: remove unnecessary code

Message ID 1333383895-23889-1-git-send-email-srinivas.kandagatla@st.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Srinivas KANDAGATLA April 2, 2012, 4:24 p.m. UTC
From: Srinivas Kandagatla <srinivas.kandagatla@st.com>

Compile tested.
remove unnecessary code that matches this coccinelle pattern

	ret = phy_write(x, y , z)
	if (ret < 0)
		return ret;
	return 0;

As phy_write returns error code, we dont need to do not need extra check
before returning.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
---
 drivers/net/phy/bcm63xx.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

Comments

Joe Perches April 2, 2012, 4:42 p.m. UTC | #1
On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
> 
> Compile tested.
> remove unnecessary code that matches this coccinelle pattern
> 
> 	ret = phy_write(x, y , z)
> 	if (ret < 0)
> 		return ret;
> 	return 0;
> 
> As phy_write returns error code, we dont need to do not need extra check
> before returning.

Do these really make any functional difference?
Doesn't the compiler generate the same output?

Many times, there's a code pattern that precedes these
calls has a similar pattern and changing the pattern
for the last call in a sequence can be jarring to a
reader and changing the pattern can sometimes introduce
errors as well.


--
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
Srinivas KANDAGATLA April 2, 2012, 4:51 p.m. UTC | #2
On 02/04/12 17:42, Joe Perches wrote:
> On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
>>
>> Compile tested.
>> remove unnecessary code that matches this coccinelle pattern
>>
>> 	ret = phy_write(x, y , z)
>> 	if (ret < 0)
>> 		return ret;
>> 	return 0;
>>
>> As phy_write returns error code, we dont need to do not need extra check
>> before returning.
>
> Do these really make any functional difference?
No it does not make any functional difference.
> Doesn't the compiler generate the same output?
>
I think it will not generate same output.
> Many times, there's a code pattern that precedes these
> calls has a similar pattern and changing the pattern
> for the last call in a sequence can be jarring to a
> reader and changing the pattern can sometimes introduce
> errors as well.
There is a purpose(error handling) of having similar pattern for the
code above last call, However there is no value for doing an additional
check before returning.
If we look at other phy files(ex:boardcom.c..), we can see they do
something similar to what the patch does in config_init.

>
>

--
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
Joe Perches April 2, 2012, 5:02 p.m. UTC | #3
On Mon, 2012-04-02 at 17:51 +0100, Srinivas KANDAGATLA wrote:
> On 02/04/12 17:42, Joe Perches wrote:
> > On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
> > Do these really make any functional difference?
> No it does not make any functional difference.
> > Doesn't the compiler generate the same output?
> I think it will not generate same output.

Yes, you are right.  The code currently returns 0 for
non-error cases and you've changed it to possibly
return a positive value.

Have you checked all the callers to make sure this
doesn't introduce a new defect?

--
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
Srinivas KANDAGATLA April 3, 2012, 9:49 a.m. UTC | #4
Yes, I have audited all the drivers. none of them return positive values.
In general, I think phy_write should return either 0 or an error code
and *NOT* positive values.
Any mdio bus driver returning positive values for phy_writes will break
the phylib too.

On 02/04/12 18:02, Joe Perches wrote:
> On Mon, 2012-04-02 at 17:51 +0100, Srinivas KANDAGATLA wrote:
>> On 02/04/12 17:42, Joe Perches wrote:
>>> On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
>>> Do these really make any functional difference?
>> No it does not make any functional difference.
>>> Doesn't the compiler generate the same output?
>> I think it will not generate same output.
> Yes, you are right.  The code currently returns 0 for
> non-error cases and you've changed it to possibly
> return a positive value.
>
> Have you checked all the callers to make sure this
> doesn't introduce a new defect?
>

--
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
David Miller April 3, 2012, 11:02 p.m. UTC | #5
From: Srinivas KANDAGATLA <srinivas.kandagatla@st.com>
Date: Tue, 03 Apr 2012 10:49:41 +0100

> Yes, I have audited all the drivers. none of them return positive values.
> In general, I think phy_write should return either 0 or an error code
> and *NOT* positive values.
> Any mdio bus driver returning positive values for phy_writes will break
> the phylib too.

I've applied all three patches to net-next, thanks.
--
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/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c
index e16f98c..cd802eb 100644
--- a/drivers/net/phy/bcm63xx.c
+++ b/drivers/net/phy/bcm63xx.c
@@ -39,10 +39,7 @@  static int bcm63xx_config_init(struct phy_device *phydev)
 		MII_BCM63XX_IR_SPEED |
 		MII_BCM63XX_IR_LINK) |
 		MII_BCM63XX_IR_EN;
-	err = phy_write(phydev, MII_BCM63XX_IR, reg);
-	if (err < 0)
-		return err;
-	return 0;
+	return phy_write(phydev, MII_BCM63XX_IR, reg);
 }
 
 static int bcm63xx_ack_interrupt(struct phy_device *phydev)