[PATCH] [V3] net: emaclite: adding MDIO and phy lib support
John Linn
John.Linn at xilinx.com
Wed Feb 10 10:00:04 EST 2010
> -----Original Message-----
> From: John Williams [mailto:john.williams at petalogix.com]
> Sent: Tuesday, February 09, 2010 3:30 PM
> To: John Linn
> Cc: netdev at vger.kernel.org; linuxppc-dev at ozlabs.org; jgarzik at pobox.com; grant.likely at secretlab.ca;
> jwboyer at linux.vnet.ibm.com; Sadanand Mutyala
> Subject: Re: [PATCH] [V3] net: emaclite: adding MDIO and phy lib support
>
> Hi John,
>
> Sorry If I'm painting bike-sheds here, just one tiny tweak might be in
> order to standardise your mutex_unlock exit path:
>
> > +static int xemaclite_mdio_read(struct mii_bus *bus, int phy_id, int reg)
> > +{
> > + struct net_local *lp = bus->priv;
> > + u32 ctrl_reg;
> > + u32 rc;
> > +
> > + mutex_lock(&lp->mdio_mutex);
> > +
> > + if (xemaclite_mdio_wait(lp)) {
> > + mutex_unlock(&lp->mdio_mutex);
> > + return -ETIMEDOUT;
> > + }
>
> [snip]
>
>
> > + if (xemaclite_mdio_wait(lp)) {
> > + mutex_unlock(&lp->mdio_mutex);
> > + return -ETIMEDOUT;
> > + }
>
> [snip]
>
>
> > + dev_dbg(&lp->ndev->dev,
> > + "xemaclite_mdio_read(phy_id=%i, reg=%x) == %x\n",
> > + phy_id, reg, rc);
> > +
> > + return rc;
>
> Can this be better expressed like this:
>
> my_func() {
> mutex_lock()
> ..
>
> if(some error) {
> rc=-ETIMEDOUT;
> goto out_unlock;
> }
> ...
>
> /* success path */
> rc=0;
> ..
> out_unlock:
> mutex_unlock()
> return rc;
> }
>
>
> Is this style still favoured in driver exit paths?
It looks to me like the mutex is not needed in the driver mdio functions as there's a mutex in the mdiobus functions already.
Am I wrong about that?
Thanks,
John
>From phy/mdio_bus.c
int mdiobus_read(struct mii_bus *bus, int addr, u16 regnum)
{
int retval;
BUG_ON(in_interrupt());
mutex_lock(&bus->mdio_lock);
retval = bus->read(bus, addr, regnum);
mutex_unlock(&bus->mdio_lock);
return retval;
}
EXPORT_SYMBOL(mdiobus_read);
int mdiobus_write(struct mii_bus *bus, int addr, u16 regnum, u16 val)
{
int err;
BUG_ON(in_interrupt());
mutex_lock(&bus->mdio_lock);
err = bus->write(bus, addr, regnum, val);
mutex_unlock(&bus->mdio_lock);
return err;
}
EXPORT_SYMBOL(mdiobus_write);
>
> Thanks,
>
> John
> --
> John Williams, PhD, B.Eng, B.IT
> PetaLogix - Linux Solutions for a Reconfigurable World
> w: www.petalogix.com p: +61-7-30090663 f: +61-7-30090663
This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
More information about the Linuxppc-dev
mailing list