From patchwork Fri Aug 19 12:48:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Appana Durga Kedareswara rao X-Patchwork-Id: 9290231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25C1D607FF for ; Fri, 19 Aug 2016 12:54:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16572293D7 for ; Fri, 19 Aug 2016 12:54:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B20A29404; Fri, 19 Aug 2016 12:54:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 12857293D7 for ; Fri, 19 Aug 2016 12:54:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bajHp-0003Ai-E7; Fri, 19 Aug 2016 12:52:37 +0000 Received: from mail-dm3nam03on0052.outbound.protection.outlook.com ([104.47.41.52] helo=NAM03-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bajEA-0007A2-K0 for linux-arm-kernel@lists.infradead.org; Fri, 19 Aug 2016 12:48:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XUZC8s+Re2SxtPNLtneJP4Jf4zvh37kxF3No38VfnMw=; b=D4wGIAfWO+Cxu0dWc0tfE3luGi18vAyN+NsghyqKSfwKMEAwgBwbfYp+CgKEa92QUAdOtuQX2XY219lkq9REtH5rEGiEfU0E+Aos5TeK63LWt9q+hjx6zGtOx3l1YkSMsIZlOTOJw3yDIum9719aH8f2cnIto6NxH4TecQgt2ek= Received: from BN1PR02CA0030.namprd02.prod.outlook.com (10.141.56.30) by BLUPR02MB1713.namprd02.prod.outlook.com (10.162.213.139) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21; Fri, 19 Aug 2016 12:48:26 +0000 Received: from SN1NAM02FT053.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e44::203) by BN1PR02CA0030.outlook.office365.com (2a01:111:e400:2a::30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21 via Frontend Transport; Fri, 19 Aug 2016 12:48:27 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by SN1NAM02FT053.mail.protection.outlook.com (10.152.72.102) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.577.8 via Frontend Transport; Fri, 19 Aug 2016 12:48:27 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:33449 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1bajDo-0003Se-28; Fri, 19 Aug 2016 05:48:28 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1bajDm-0003q1-UB; Fri, 19 Aug 2016 05:48:26 -0700 Received: from xsj-pvapsmtp01 (maildrop.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u7JCmGPL021162; Fri, 19 Aug 2016 05:48:17 -0700 Received: from [172.23.64.208] (helo=xhdrdevl6.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1bajDc-0003oq-FE; Fri, 19 Aug 2016 05:48:16 -0700 Received: by xhdrdevl6.xilinx.com (Postfix, from userid 13614) id 75E4EF2000E; Fri, 19 Aug 2016 18:18:15 +0530 (IST) From: Kedareswara rao Appana To: , , , , Subject: [PATCH 2/2] net: phy: Fix race conditions in the driver Date: Fri, 19 Aug 2016 18:18:11 +0530 Message-ID: <1471610891-13353-2-git-send-email-appanad@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1471610891-13353-1-git-send-email-appanad@xilinx.com> References: <1471610891-13353-1-git-send-email-appanad@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-22522.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(199003)(189002)(42186005)(106466001)(2950100001)(229853001)(356003)(48376002)(5001770100001)(305945005)(7846002)(92566002)(50466002)(8676002)(81156014)(81166006)(36756003)(8936002)(50226002)(36386004)(2906002)(90966002)(76176999)(50986999)(103686003)(33646002)(46386002)(11100500001)(45336002)(626004)(19580405001)(63266004)(87936001)(2201001)(586003)(5003940100001)(4326007)(47776003)(19580395003)(189998001)(52956003)(107986001)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR02MB1713; H:xsj-pvapsmtpgw02; FPR:; SPF:Pass; PTR:xapps1.xilinx.com,unknown-60-100.xilinx.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02FT053; 1:cMQJT9M6F3CAR/3uhTAMvs3/cETeFQMpBntTI1Zlf0BIMKFg8cGN2vC5LCWbFT8AW9WTCguyh4z0v+A8F16K6UU1PFj91Hxa1zvjK+t9EiCT/sXhLdk4opx1MPkdrSx7PnQZMdTVLINDZ6WD2avFilgaxwEhY0H0konh5pMdWpa1ljM/Zt1WX3sZV7xu6g2Bgv0nG34S8alQMqAg3i/hE+tX8EPAVgT8m7i+WuDSwn9CWOE5guLW6JGVFH7vcnu3TR3TqaprGKRSwqUa3URVsCyL+PLpN8OswU8VSeyLYziASXMu/6nqq/DgmDvMvQshAvYtlG2VHG0DpsZxZ1zw8nBAgwHa57fYVwAX/LAWp7vX1Qm4MZoQIP24PiGsf7Vx66oZ/KrnHf2YZEOGrWEjfTdd/7O77idK/sqeijdsZEvIpKelBR2qvGuDwPR59L6IwcIVdHivHDrUxlk0jaVBtYTu+f+3dd0dnz6lRdJfRJmcnSmkLUaLS4tqZplVDq7kU+rNem4WnJrlveQDDDi7wFlbfFCusT+EMjrZ57c45VcfRQqiAp9CV13/6AOs/qvRYPVb0GKcObzkTrWvAXdA14jSyefJkGBrqsZ9L3qvmWk= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b81b8007-1a78-4955-cc15-08d3c82f1db7 X-Microsoft-Exchange-Diagnostics: 1; BLUPR02MB1713; 2:wLJ5WU5U/QSWAr1/SLzmidyLxB09humX94ZELbpTAWrlT8XoUtbIAp3yoalcgFnZxnajFs3Lm+gXVsxprolj93Ub7AUtdZATSOO7CX/hqd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/Vm5DjaxKjoijDRSufmKaCNZapAIvHcdX/OKONVHyM7tEJVYicwMO2nlk=; 20:PDjx34LRr0h6skykGsmBUwj0Ti/FIQ8E0PFEZuyprFY5vklG9rTWs4ulDeGEQrbu+2jtFlW4dDGf4Ecc41xvMi6uqma2B0fNhHx3lp6ok56D9u7BM1UBaP/UuUoWmhSwSzkyLzFVE1jbXJLQzcivw9Ulx8c9NJO+0n+V4yccrjtWZKlG7RNa9bgeLmGCNyVoeGCRa14noTh5jtNGesca7nmvpv+NVBs6CEj+bSvkU+PbKZ4L1FpUdIQLldTtXRZvO/Qvb4/CjSh8f4wBEZr6DnICjA05clcTHSvlL2JhnL6vTfXW+fIFMK+kX0LA0vEqbo/j4tp0ZSfabnXDY8MLoBAJAAe7MyEOUzZszzBNIlemACXCXa0Xml1+MHMiYiS4WyA1u3g25dZd6mbHK8ZV1TVU6Zi9RBil+JB13HwMaGuo+LDbI3wX7tgo2eVtdhNcqlOkBP+IE/mxROS6O4DfM0io1aqDGuiaMYE1lok4m9VGUJcL3Pce3WStAn8m+qVq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13018025)(13023025)(13024025)(13017025)(13015025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BLUPR02MB1713; BCL:0; PCL:0; RULEID:; SRVR:BLUPR02MB1713; X-Microsoft-Exchange-Diagnostics: 1; BLUPR02MB1713; 4:HrL20WeFrbCu42Kp5eKyNMjyUjQ8Eo084eArYWpNThPJ5gyBzPMEqotExhBkbOLwI+t67bP8M5YZKgRpNWQngDxY0NkJxy3XzFx5lJuzjQ2FQQepZYTzxA95QZ3H0NwzybMvTdP4yArzlf6GZURyCW2hOI2NdBapHzCgXv3UR2J6rIaaEm4S7R4wLQZ4Dt0C6XDpf/gFm2PfV2kEsmMwlwF6nTypE87AjM2mIIJbXpdPk8RX6sbC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fy8qYdxb30/cV1AOTUogmaqR2sJOkWOMvfCs3PoOKQ==; 5:A0c8zYEWXbNaAtW2X7HZPLDkBWS7NIXDW2xZeI30zK8WryKq0iih/Wj8l0Mg11TS8rQLp7emRkKu7S75apn7xDOsUIKhVpmXqszFDhy6npVng20VLwGEE4cLWwtytovrQAp6xbyWCZzPdeRYdxLmTw==; 24:NTYdXiCgX682ep6BAusFKpyAEX38RhkLqb9VqESG1+qN2yQQ24bj9Ri5ctiLxJd6h7/ChWE6iqKBQI3tdb5mmrOzueZRon+rJjZDKZrJziQ=; 7:7Np8xtdBlJuBvSUMZtiq6t4VYJVghjw0FzvJXlI8Lagz/WwrAPnl1PFDhku4LnhMLeITcOV4d8nE59dypPok/I4qdzHh2fhDrDLWlHx8xkmg4emSoXTSkp5E0FG03Tf0wIvPdldWECAhm9ibnX3H2CKKEndmnwnapfV8uMKRKyJ93VBDumMvHEgejuZENsanOJB4SofKoA81vaEhPtNvCkFTqEaLxuQY20kHqp9UgoE/s4yK3hjtVS9H+t/7jZju SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2016 12:48:27.4474 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.100]; Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR02MB1713 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160819_054851_214838_0A7BF29C X-CRM114-Status: GOOD ( 12.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes the below race conditions in the driver. ---> Fix Opps after unload the driver as a module ---> Use spin locks where relevant. ---> Take reference on the external phy to prevent issues when phy driver is unloaded. Reported-by: Andrew Lunn Signed-off-by: Kedareswara rao Appana --- drivers/net/phy/xilinx_gmii2rgmii.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 7336fd0..cdd9d95 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -34,6 +34,7 @@ struct gmii2rgmii { struct phy_driver *phy_drv; struct phy_driver conv_phy_drv; int addr; + spinlock_t phy_lock; }; static int xgmiitorgmii_read_status(struct phy_device *phydev) @@ -55,7 +56,7 @@ static int xgmiitorgmii_read_status(struct phy_device *phydev) val |= BMCR_SPEED1000; else if (phydev->speed == SPEED_100) val |= BMCR_SPEED100; - else + else if (phydev->speed == SPEED_10) val |= BMCR_SPEED10; err = mdiobus_write(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG, @@ -71,6 +72,8 @@ int xgmiitorgmii_probe(struct mdio_device *mdiodev) struct device *dev = &mdiodev->dev; struct device_node *np = dev->of_node, *phy_node; struct gmii2rgmii *priv; + struct mii_bus *bus; + unsigned long flags; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -88,17 +91,43 @@ int xgmiitorgmii_probe(struct mdio_device *mdiodev) return -EPROBE_DEFER; } + spin_lock_init(&priv->phy_lock); + + bus = priv->phy_dev->mdio.bus; + if (!try_module_get(bus->owner)) { + dev_err(dev, "failed to get the bus module\n"); + return -EIO; + } + + get_device(&priv->phy_dev->mdio.dev); + priv->addr = mdiodev->addr; priv->phy_drv = priv->phy_dev->drv; memcpy(&priv->conv_phy_drv, priv->phy_dev->drv, sizeof(struct phy_driver)); priv->conv_phy_drv.read_status = xgmiitorgmii_read_status; priv->phy_dev->priv = priv; + spin_lock_irqsave(&priv->phy_lock, flags); priv->phy_dev->drv = &priv->conv_phy_drv; + spin_unlock_irqrestore(&priv->phy_lock, flags); + + dev_set_drvdata(dev, priv); return 0; } +static void xgmiitorgmii_remove(struct mdio_device *mdiodev) +{ + struct gmii2rgmii *priv = dev_get_drvdata(&mdiodev->dev); + struct mii_bus *bus; + + bus = priv->phy_dev->mdio.bus; + + put_device(&priv->phy_dev->mdio.dev); + module_put(bus->owner); + phy_disconnect(priv->phy_dev); +} + static const struct of_device_id xgmiitorgmii_of_match[] = { { .compatible = "xlnx,gmii-to-rgmii-1.0" }, {}, @@ -107,6 +136,7 @@ MODULE_DEVICE_TABLE(of, xgmiitorgmii_of_match); static struct mdio_driver xgmiitorgmii_driver = { .probe = xgmiitorgmii_probe, + .remove = xgmiitorgmii_remove, .mdiodrv.driver = { .name = "xgmiitorgmii", .of_match_table = xgmiitorgmii_of_match,