From patchwork Mon Jul 21 18:26:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 372177 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.180.67]) by ozlabs.org (Postfix) with ESMTP id 2C2DE140143 for ; Tue, 22 Jul 2014 04:27:21 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933370AbaGUS1Q (ORCPT ); Mon, 21 Jul 2014 14:27:16 -0400 Received: from top.free-electrons.com ([176.31.233.9]:55874 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933219AbaGUS1O (ORCPT ); Mon, 21 Jul 2014 14:27:14 -0400 Received: by mail.free-electrons.com (Postfix, from userid 106) id 347C883E; Mon, 21 Jul 2014 20:27:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost.localdomain (unknown [190.2.108.81]) by mail.free-electrons.com (Postfix) with ESMTPSA id A56307B6; Mon, 21 Jul 2014 20:27:14 +0200 (CEST) From: Ezequiel Garcia To: Cc: David Miller , Florian Fainelli , Thomas Petazzoni , Gregory Clement , Ezequiel Garcia Subject: [RFC 2/2] net: mvneta: Ensure the MDIO bus module is held Date: Mon, 21 Jul 2014 15:26:10 -0300 Message-Id: <1405967170-19353-3-git-send-email-ezequiel.garcia@free-electrons.com> X-Mailer: git-send-email 2.0.1 In-Reply-To: <1405967170-19353-1-git-send-email-ezequiel.garcia@free-electrons.com> References: <1405967170-19353-1-git-send-email-ezequiel.garcia@free-electrons.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit adds proper module_{get,put} to prevent the MDIO bus module from being unloaded while the phydev is connected. By doing so, we fix a kernel panic produced when the mvmdio driver is removed, and one of the ethernet interfaces using it is "up". Signed-off-by: Ezequiel Garcia --- drivers/net/ethernet/marvell/mvneta.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index dadd9a5..98d0cd1 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -297,6 +297,7 @@ struct mvneta_port { struct mvneta_pcpu_stats *stats; struct mii_bus *mii_bus; + struct module *phy_module; struct phy_device *phy_dev; phy_interface_t phy_interface; struct device_node *phy_node; @@ -2575,6 +2576,15 @@ static int mvneta_mdio_probe(struct mvneta_port *pp) return -ENODEV; } + /* Get the MDIO driver so it can't be removed beneath our feet */ + pp->phy_module = phy_dev->bus->dev.driver ? + phy_dev->bus->dev.driver->owner : NULL; + if (!try_module_get(pp->phy_module)) { + netdev_err(pp->dev, "could not get the MDIO module\n"); + phy_disconnect(phy_dev); + return -EIO; + } + phy_dev->supported &= PHY_GBIT_FEATURES; phy_dev->advertising = phy_dev->supported; @@ -2590,6 +2600,8 @@ static void mvneta_mdio_remove(struct mvneta_port *pp) { phy_disconnect(pp->phy_dev); pp->phy_dev = NULL; + module_put(pp->phy_module); + pp->phy_module = NULL; } static int mvneta_open(struct net_device *dev)