Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp189976rdh; Wed, 25 Oct 2023 22:12:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF34qFDhwmR1YJ4mmiKP61k71CkvphOyGEJ9CYuyX9HEzi7xX75qvUBZ8uNNbgC7R9WRAG5 X-Received: by 2002:a0d:fd06:0:b0:59f:21c1:30b6 with SMTP id n6-20020a0dfd06000000b0059f21c130b6mr17853249ywf.51.1698297134534; Wed, 25 Oct 2023 22:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698297134; cv=none; d=google.com; s=arc-20160816; b=bTLKBMxm2NA76+H+LT5rcuuBcC7kl2+ulQndCL41UxBXx8e8KpTod89jNDi+WghbTX 5L6J2maQ5E/FUXP8iuxjDYT3Z6gzsLGph48CG3xirz2j1BCvBij8oj1bFAi8cTOtJUZu ZLlPdsD0vLC7qvZYGnWk7GGxU9jk7FyUzbMUFdTcwZCaPn592YrgVt/kcKEtTO3GfDyW 5XmxCP1g96+snJtTZnwYM/9dheS/q8wE6W5QlBlCCliKmJg87pYQvLyqFpc9Y7mIGh6h DBsljPJFTbpQLlLizwdHsmy899SE2X+o802wcgeGjpi64WP27yadqToBFFAsGwSWnPB5 D8lw== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f129-20020a0ddc87000000b0059f65cfba95si13658364ywe.209.2023.10.25.22.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 22:12:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 3E2B0810F0CE; Wed, 25 Oct 2023 22:11:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343638AbjJZFLY (ORCPT + 99 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 ); 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 ; 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 ) 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 ) 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 ) id 1qvsdw-009ikx-26; Thu, 26 Oct 2023 07:10:52 +0200 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss , Conor Dooley , Krzysztof Kozlowski , Rob Herring Cc: Oleksij Rempel , Florian Fainelli , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, "Russell King (Oracle)" , 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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 22:11:34 -0700 (PDT) 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 Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli --- 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); + kfree(switch_macaddr); + + return ret; } void ksz_switch_macaddr_put(struct dsa_switch *ds) -- 2.39.2