From patchwork Fri Dec 19 19:52:36 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Halasa X-Patchwork-Id: 14892 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id AC0A8DDF1E for ; Sat, 20 Dec 2008 06:52:50 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751797AbYLSTwk (ORCPT ); Fri, 19 Dec 2008 14:52:40 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751792AbYLSTwk (ORCPT ); Fri, 19 Dec 2008 14:52:40 -0500 Received: from khc.piap.pl ([195.187.100.11]:58922 "EHLO khc.piap.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751570AbYLSTwj (ORCPT ); Fri, 19 Dec 2008 14:52:39 -0500 Received: by khc.piap.pl (Postfix, from userid 500) id 7024770013; Fri, 19 Dec 2008 20:52:36 +0100 (CET) To: Lennert Buytenhek Cc: David Miller , Subject: [PATCH] PHYLIB mdio fixes #2 From: Krzysztof Halasa Date: Fri, 19 Dec 2008 20:52:36 +0100 Message-ID: MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The PHYLIB mdio code has more problems in error paths: - mdiobus_release can be called before bus->state is set to MDIOBUS_REGISTERED - mdiobus_scan allocates resources which need to be freed - the comment is wrong, the resistors used are actually pull-ups. Signed-off-by: Krzysztof Halasa --- 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 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -63,7 +63,9 @@ EXPORT_SYMBOL(mdiobus_alloc); static void mdiobus_release(struct device *d) { struct mii_bus *bus = to_mii_bus(d); - BUG_ON(bus->state != MDIOBUS_RELEASED); + BUG_ON(bus->state != MDIOBUS_RELEASED && + /* for compatibility with error handling in drivers */ + bus->state != MDIOBUS_ALLOCATED); kfree(bus); } @@ -83,8 +85,7 @@ static struct class mdio_bus_class = { */ int mdiobus_register(struct mii_bus *bus) { - int i; - int err = 0; + int i, err; if (NULL == bus || NULL == bus->name || NULL == bus->read || @@ -116,16 +117,23 @@ int mdiobus_register(struct mii_bus *bus) struct phy_device *phydev; phydev = mdiobus_scan(bus, i); - if (IS_ERR(phydev)) + if (IS_ERR(phydev)) { err = PTR_ERR(phydev); + goto error; + } } } - if (!err) - bus->state = MDIOBUS_REGISTERED; - + bus->state = MDIOBUS_REGISTERED; pr_info("%s: probed\n", bus->name); + return 0; +error: + while (--i >= 0) { + if (bus->phy_map[i]) + device_unregister(&bus->phy_map[i]->dev); + } + device_del(&bus->dev); return err; } EXPORT_SYMBOL(mdiobus_register); --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -232,7 +232,7 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr) return NULL; /* - * Broken hardware is sometimes missing the pull down resistor on the + * Broken hardware is sometimes missing the pull-up resistor on the * MDIO line, which results in reads to non-existent devices returning * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent * device as well.