[net-next,v8,3/5] net: dsa: microchip: Add error handling for ksz_switch_macaddr_get()
Message ID | 20231026051051.2316937-4-o.rempel@pengutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp434420vqb; Wed, 25 Oct 2023 22:11:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNFN3+y9lZZuHhRxZcjFAKi01qXLhOv//6xKLP85j4zKgtTkCjnueHRl9mxGzj5KHM3zRZ X-Received: by 2002:a05:620a:284b:b0:777:5b4e:e52e with SMTP id h11-20020a05620a284b00b007775b4ee52emr18427192qkp.66.1698297091669; Wed, 25 Oct 2023 22:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698297091; cv=none; d=google.com; s=arc-20160816; b=CWTuAJDsxgrgKXzj7oMLBuTzjbqfG/1utUYSQe/Qy/ete50KSkmOIU0ZCEAVm4iD5c 6IOiFpgktbD3it9rKSqStvY09gdMClNpwjZipB/OSYcJsDN4gT64J6Qe7vxHe+DTE0jJ 3WvZefJd0vmPWES2NWCvcvG0TSNiSjQ8U082JTbIwanv0P10wqG/C/91P3ubkEJnysxc IORoxWfN/jhY7qGarHQOkNHD6Sqrg4SWmZkhaT+zVj6mxDP0otoWCPHONwvY/p2w4dY6 YCSORg47Pq6gZ564ym5mBmKu7IOU990SC6feSMy9mHtvrlPr1XTomTUspVQP/XIUlyQE yRNQ== 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=djU4TucW7nyHJzsh6q/TBwmR1xQ3i6FtXDJ2Q5bXh7g=; fh=oL5u1qxwpthPG0onT/4SNMwjdlMbLicDue2DPzZvioY=; b=ZxVjWVJGnoatfwjNaIFLhvPMy06PfyeQpsuAa0oMlcJGhOovAI2+5R5GL/UiK0V0ME 5gyaBVnbSEr7/KQQLMamR6pBB90QUBMzQHjbfVGMz0ssvP2XEH80u7mLT8CBpOYDP9zy nonN/Me4oxTVSu5rtHTyddPuuMtIPt+i3hlfS7yvyuUR4p4O2TWAU94HUJS03Eyhc7Ov xafxq/g2s50nT9VJsFAsfedKYd2hVb+FIyt9pVaZz0jQMzWCI8tvZYZ+oGqnP1bkQDBA 5Q074AqDwpw/apwzzibCJThhk1nzOJKj90Q6zS56Vc4wTJt2RnI5ThJ2LMGKMno/1WiU 8/1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b144-20020a0dd996000000b0058405ac8ab8si13004414ywe.239.2023.10.25.22.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 22:11:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9603781BDF0A; Wed, 25 Oct 2023 22:11:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343659AbjJZFLY (ORCPT <rfc822;aposhian.dev@gmail.com> + 26 others); Thu, 26 Oct 2023 01:11:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjJZFLW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 26 Oct 2023 01:11:22 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CCB1D6 for <linux-kernel@vger.kernel.org>; Wed, 25 Oct 2023 22:11:17 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <ore@pengutronix.de>) id 1qvsdy-0004YB-4B; Thu, 26 Oct 2023 07:10:54 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from <ore@pengutronix.de>) id 1qvsdw-004L1T-Oc; Thu, 26 Oct 2023 07:10:52 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from <ore@pengutronix.de>) id 1qvsdw-009ikx-26; Thu, 26 Oct 2023 07:10:52 +0200 From: Oleksij Rempel <o.rempel@pengutronix.de> To: "David S. Miller" <davem@davemloft.net>, Andrew Lunn <andrew@lunn.ch>, Eric Dumazet <edumazet@google.com>, Florian Fainelli <f.fainelli@gmail.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Vladimir Oltean <olteanv@gmail.com>, Woojung Huh <woojung.huh@microchip.com>, Arun Ramadoss <arun.ramadoss@microchip.com>, Conor Dooley <conor+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Rob Herring <robh+dt@kernel.org> Cc: Oleksij Rempel <o.rempel@pengutronix.de>, Florian Fainelli <florian.fainelli@broadcom.com>, kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, "Russell King (Oracle)" <linux@armlinux.org.uk>, devicetree@vger.kernel.org Subject: [PATCH net-next v8 3/5] net: dsa: microchip: Add error handling for ksz_switch_macaddr_get() Date: Thu, 26 Oct 2023 07:10:49 +0200 Message-Id: <20231026051051.2316937-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231026051051.2316937-1-o.rempel@pengutronix.de> References: <20231026051051.2316937-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 25 Oct 2023 22:11:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780793571599238262 X-GMAIL-MSGID: 1780793571599238262 |
Series |
net: dsa: microchip: provide Wake on LAN support (part 2)
|
|
Commit Message
Oleksij Rempel
Oct. 26, 2023, 5:10 a.m. UTC
Enhance the ksz_switch_macaddr_get() function to handle errors that may occur during the call to ksz_write8(). Specifically, this update checks the return value of ksz_write8(), which may fail if regmap ranges validation is not passed and returns the error code. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> --- drivers/net/dsa/microchip/ksz_common.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
Comments
On Thu, Oct 26, 2023 at 07:10:49AM +0200, Oleksij Rempel wrote: > Enhance the ksz_switch_macaddr_get() function to handle errors that may > occur during the call to ksz_write8(). Specifically, this update checks > the return value of ksz_write8(), which may fail if regmap ranges > validation is not passed and returns the error code. > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> > Reviewed-by: Andrew Lunn <andrew@lunn.ch> > Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> > --- Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> > drivers/net/dsa/microchip/ksz_common.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c > index 0c3adc389d0b..00be812bef40 100644 > --- a/drivers/net/dsa/microchip/ksz_common.c > +++ b/drivers/net/dsa/microchip/ksz_common.c > @@ -3640,7 +3640,7 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, > struct ksz_switch_macaddr *switch_macaddr; > struct ksz_device *dev = ds->priv; > const u16 *regs = dev->info->regs; > - int i; > + int i, ret; > > /* Make sure concurrent MAC address changes are blocked */ > ASSERT_RTNL(); > @@ -3667,10 +3667,20 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, > dev->switch_macaddr = switch_macaddr; > > /* Program the switch MAC address to hardware */ > - for (i = 0; i < ETH_ALEN; i++) > - ksz_write8(dev, regs[REG_SW_MAC_ADDR] + i, addr[i]); > + for (i = 0; i < ETH_ALEN; i++) { > + ret = ksz_write8(dev, regs[REG_SW_MAC_ADDR] + i, addr[i]); > + if (ret) > + goto macaddr_drop; > + } > > return 0; > + > +macaddr_drop: > + dev->switch_macaddr = NULL; > + refcount_set(&switch_macaddr->refcount, 0); Nitpick: this line doesn't do any harm, but it doesn't do any good, either. It can be removed in a follow-up patch. > + kfree(switch_macaddr); > + > + return ret; > } > > void ksz_switch_macaddr_put(struct dsa_switch *ds) > -- > 2.39.2 >
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 0c3adc389d0b..00be812bef40 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3640,7 +3640,7 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, struct ksz_switch_macaddr *switch_macaddr; struct ksz_device *dev = ds->priv; const u16 *regs = dev->info->regs; - int i; + int i, ret; /* Make sure concurrent MAC address changes are blocked */ ASSERT_RTNL(); @@ -3667,10 +3667,20 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, dev->switch_macaddr = switch_macaddr; /* Program the switch MAC address to hardware */ - for (i = 0; i < ETH_ALEN; i++) - ksz_write8(dev, regs[REG_SW_MAC_ADDR] + i, addr[i]); + for (i = 0; i < ETH_ALEN; i++) { + ret = ksz_write8(dev, regs[REG_SW_MAC_ADDR] + i, addr[i]); + if (ret) + goto macaddr_drop; + } return 0; + +macaddr_drop: + dev->switch_macaddr = NULL; + refcount_set(&switch_macaddr->refcount, 0); + kfree(switch_macaddr); + + return ret; } void ksz_switch_macaddr_put(struct dsa_switch *ds)