Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1127744pxj; Fri, 4 Jun 2021 06:45:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw14Uy4YHhK/YxUhXNv+HijR/CCigsEgHhIc5xRgxOZ9D35QVkkX94yIIQVNA8vYwGz0zlN X-Received: by 2002:a17:906:c1d3:: with SMTP id bw19mr4281035ejb.145.1622814303559; Fri, 04 Jun 2021 06:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622814303; cv=none; d=google.com; s=arc-20160816; b=LHgEYVJ4yctSo42v3+//vOaZwJvYLTMCs98Fas8UmZHBYSkLHq9nystuTwpBF8NPaY rDgI5D9Zjd5umnvoYfkWs7WQKJtOx6Hp+tj0qYaMveTaFpYicrXbylvEdSIlbTH6m8rE GnCAOmj4+FH1uunGpz44AyKjqH3xOP6CMgVutqZJOwCm7/a1fqlMX0ZKuj/3i7UN1OBW PoxnVnPx/qb9BZ52Zn5Zvey1usXGWcA3xA1sxWT1I43gNbZpAx5nFsPW6SRMu+m5hDL7 MIjSUHni7wiweNurmT6AU0O8J+knNPveTT4v2L+vRA94wRzRau6oPitgeR4vjeVAK1Yh y94A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pQyWeASFj4utk0V8W3avbQ76q4G3GwcR++1qnLCTlTo=; b=yu1czUDdgFM5nsWZ0Qiy/RRDtr+XKcQpImHZKwCut7d+kL5Y1AHDE73v0l9nyo5jg3 7D//Pz34xwHz2jSyqBDoOR371O1wiDr7xcyH2IqoSxo+3+Y0rLHjc85v2aicPV/ZkTUL vOudHqzj6FtEcqVO8wh6j0Z4xRxc1L/u14+mj+W7VfqQgWlq/tx4XSWm/a87n99vLIbp Z8rQbhMk8+VxMrCNQQTuPPWPSissXmSU+FkdJayF54NHOz6LYekhR5da7fEQx6FLjxxy mM+pYspXiG4XlQUSC01PvyWCK+18J32tYo8BVII9t1Q1m1VZ8vROXWwELbz2zplcn70h wQ0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si5867220edi.368.2021.06.04.06.44.37; Fri, 04 Jun 2021 06:45:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230342AbhFDNop (ORCPT + 99 others); Fri, 4 Jun 2021 09:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbhFDNol (ORCPT ); Fri, 4 Jun 2021 09:44:41 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CAC5C061767 for ; Fri, 4 Jun 2021 06:42:54 -0700 (PDT) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpA63-00072p-H1; Fri, 04 Jun 2021 15:42:47 +0200 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lpA61-0000fm-Kh; Fri, 04 Jun 2021 15:42:45 +0200 From: Oleksij Rempel To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Russell King Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v1 5/7] net: usb: asix: add error handling for asix_mdio_* functions Date: Fri, 4 Jun 2021 15:42:42 +0200 Message-Id: <20210604134244.2467-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210604134244.2467-1-o.rempel@pengutronix.de> References: <20210604134244.2467-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This usb devices can be removed at any time, so we need to forward correct error value if device was detached. Signed-off-by: Oleksij Rempel --- drivers/net/usb/asix_common.c | 38 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c index 6b94c27576b7..7cce8f7d79b6 100644 --- a/drivers/net/usb/asix_common.c +++ b/drivers/net/usb/asix_common.c @@ -484,18 +484,23 @@ int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) return ret; } - asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, - (__u16)loc, 2, &res, 0); - asix_set_hw_mii(dev, 0); + ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, + &res, 0); + if (ret < 0) + goto out; + + ret = asix_set_hw_mii(dev, 0); +out: mutex_unlock(&dev->phy_mutex); netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", phy_id, loc, le16_to_cpu(res)); - return le16_to_cpu(res); + return ret < 0 ? ret : le16_to_cpu(res); } -void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) +static int __asix_mdio_write(struct net_device *netdev, int phy_id, int loc, + int val) { struct usbnet *dev = netdev_priv(netdev); __le16 res = cpu_to_le16(val); @@ -517,13 +522,24 @@ void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); if (ret == -ENODEV) { mutex_unlock(&dev->phy_mutex); - return; + return ret; } - asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, - (__u16)loc, 2, &res, 0); - asix_set_hw_mii(dev, 0); + ret = asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, + &res, 0); + if (ret < 0) + goto out; + + ret = asix_set_hw_mii(dev, 0); +out: mutex_unlock(&dev->phy_mutex); + + return ret < 0 ? ret : 0; +} + +void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) +{ + __asix_mdio_write(netdev, phy_id, loc, val); } /* MDIO read and write wrappers for phylib */ @@ -535,8 +551,8 @@ int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum) int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val) { - asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, regnum, val); - return 0; + return __asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, + regnum, val); } int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc) -- 2.29.2