Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2081508lqz; Tue, 2 Apr 2024 06:53:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXDazwIh1synGmIwcjK0j5zdCH5RaPmMoLMUSpWwIVlLLgE6t7XXqHiVsLS8X4odCXs4JNY7gyQ8x6k2giB+ou+IZw/3IwjFHAWubYa2w== X-Google-Smtp-Source: AGHT+IE+vsThAMaRVafg8K0wr9cyE3E30pi0WipeNxSJPIM04g6ExeAf+GbdBEfJpQxOZLW+f/Yq X-Received: by 2002:a05:6a00:1481:b0:6e6:9c79:87e9 with SMTP id v1-20020a056a00148100b006e69c7987e9mr15322095pfu.34.1712066008138; Tue, 02 Apr 2024 06:53:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712066008; cv=pass; d=google.com; s=arc-20160816; b=wqtBn8FmRBc8deMK7v/lDjQk2xT4hEfhxKyHsqOdCQdCQ0flTB6Y3J8QvQI5tC4a9G GmfxUlcf1KknWCvTM7dMLhBNrxysxvGjEDVjQ17Bo/GZQ2W0sWECaQMOFCxtRrGrbQWy 6YDQqXnCx3JOxJzFiDh9aCn/HzmfbyVpK7l+4LeMOpOvyGXIew4eQjSfEzK+x+kLt9dt L3Cm7IOURoeUFfZV4nwLGXMQaQr1u7uQ7+HeAnc7ITzzKOfY4NXW3m2ZpVHuMId/GNKn eRErc3wO0FJuXIFbpWe2bxci+Mg72Gfnbvv80F2zaXMawSCZsxSrcMPMgyzHXZI7TLwt OrWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=wsVvEuz7omlsMS2gnwpQ8BReYuvIpxj0GN1NJmqrHM0=; fh=+wuPl0jVtcYGOKyQ4dCrYwpLO51Md4SLm1XlQV1l1VE=; b=QYuceAgFm/mn8S9xumfB1EF5xjkxmUEdPHpPmpOxn2x+UclsWgz3VlgJxs+jnaPq3h 9LWKNtSjLU1xJoaDQrKuEEDkAu3MuhYg67CQI8/an3N9PEHJbaA5o8uceNXDlAXqzZtG fy3/QV0Zxw/TV2rIU3NN/Qf/HkSVtau29TNXrTFaoMwEuRsnocoY+vEMVBy4WjBqTH2M rebCTJXZ3aEBSnBtj5HgBdM8r5GF8nSch7B0Hrb25z62hnzINdl89l3MCGe6xnnjtCdH 7guAOaaO+wXuiNjxqY6w5Aq6YSVN3cZZ6tMfsRdyJGEygAEflT0+IBUHnNw1QoHpcMog hqPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-128019-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128019-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i196-20020a636dcd000000b005dccf9afad5si11763287pgc.305.2024.04.02.06.53.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 06:53:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128019-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-128019-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128019-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D47EEB22778 for ; Tue, 2 Apr 2024 13:16:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95427131748; Tue, 2 Apr 2024 13:13:56 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 084DE83CAA for ; Tue, 2 Apr 2024 13:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712063635; cv=none; b=P0G/XmijSr8SgHD/lKFqgBQGuhL3TewcqJTrB8Zg60H2iTu3BhsFoN/L0ugEz8r1Tv19Ds0TOfqu9JJKibce+ilDf79cRT7voSeAWPnVtYD6kfuHdYulsuOM3zc1FPXvcTr0wkV8olZpOFjP/PWRviB9SxogrLuEw8+7eIGzPK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712063635; c=relaxed/simple; bh=t9QA8oYRz9Ov2cksud/TPgbQ22aTRdp92YkIsm9j238=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h2q7t8uKoTJR0y0uDWIIpR3U0i3Zw3nXo7mnWSkzTbUgkj+LCb1RTsSu2VVvFyABAqMyFMT+Uj03VLbNVsPLqbRJ+NTkxRidbI3Swt13wv7hskpuOvb4AiBz12XkiAmBp1t9foipEt8zUmOeyHC8oDCpR4U90zWLS3zc71afrf4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1rrdxN-0007Nk-MW; Tue, 02 Apr 2024 15:13:41 +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 1rrdxM-009zW5-Gq; Tue, 02 Apr 2024 15:13:40 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rrdxM-006OpN-1O; Tue, 02 Apr 2024 15:13:40 +0200 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [PATCH net-next v1 4/8] net: dsa: microchip: ksz8: Refactor ksz8_r_dyn_mac_table() for readability Date: Tue, 2 Apr 2024 15:13:35 +0200 Message-Id: <20240402131339.1525330-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240402131339.1525330-1-o.rempel@pengutronix.de> References: <20240402131339.1525330-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Move the code out of a long if statement scope in ksz8_r_dyn_mac_table() to improve code readability. Signed-off-by: Oleksij Rempel --- drivers/net/dsa/microchip/ksz8795.c | 60 +++++++++++++++-------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index b70aa2c0a85ec..1962195e16a6f 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -416,7 +416,9 @@ static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, const u32 *masks; const u16 *regs; u16 ctrl_addr; + u64 buf = 0; u8 data; + int cnt; int rc; shifts = dev->info->shifts; @@ -432,38 +434,38 @@ static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, if (rc == -EAGAIN) { if (addr == 0) *entries = 0; + goto unlock_alu; } else if (rc == -ENXIO) { *entries = 0; - /* At least one valid entry in the table. */ - } else { - u64 buf = 0; - int cnt; - - ksz_read64(dev, regs[REG_IND_DATA_HI], &buf); - data_hi = (u32)(buf >> 32); - data_lo = (u32)buf; - - /* Check out how many valid entry in the table. */ - cnt = data & masks[DYNAMIC_MAC_TABLE_ENTRIES_H]; - cnt <<= shifts[DYNAMIC_MAC_ENTRIES_H]; - cnt |= (data_hi & masks[DYNAMIC_MAC_TABLE_ENTRIES]) >> - shifts[DYNAMIC_MAC_ENTRIES]; - *entries = cnt + 1; - - *fid = (data_hi & masks[DYNAMIC_MAC_TABLE_FID]) >> - shifts[DYNAMIC_MAC_FID]; - *src_port = (data_hi & masks[DYNAMIC_MAC_TABLE_SRC_PORT]) >> - shifts[DYNAMIC_MAC_SRC_PORT]; - - mac_addr[5] = (u8)data_lo; - mac_addr[4] = (u8)(data_lo >> 8); - mac_addr[3] = (u8)(data_lo >> 16); - mac_addr[2] = (u8)(data_lo >> 24); - - mac_addr[1] = (u8)data_hi; - mac_addr[0] = (u8)(data_hi >> 8); - rc = 0; + goto unlock_alu; } + + ksz_read64(dev, regs[REG_IND_DATA_HI], &buf); + data_hi = (u32)(buf >> 32); + data_lo = (u32)buf; + + /* Check out how many valid entry in the table. */ + cnt = data & masks[DYNAMIC_MAC_TABLE_ENTRIES_H]; + cnt <<= shifts[DYNAMIC_MAC_ENTRIES_H]; + cnt |= (data_hi & masks[DYNAMIC_MAC_TABLE_ENTRIES]) >> + shifts[DYNAMIC_MAC_ENTRIES]; + *entries = cnt + 1; + + *fid = (data_hi & masks[DYNAMIC_MAC_TABLE_FID]) >> + shifts[DYNAMIC_MAC_FID]; + *src_port = (data_hi & masks[DYNAMIC_MAC_TABLE_SRC_PORT]) >> + shifts[DYNAMIC_MAC_SRC_PORT]; + + mac_addr[5] = (u8)data_lo; + mac_addr[4] = (u8)(data_lo >> 8); + mac_addr[3] = (u8)(data_lo >> 16); + mac_addr[2] = (u8)(data_lo >> 24); + + mac_addr[1] = (u8)data_hi; + mac_addr[0] = (u8)(data_hi >> 8); + rc = 0; + +unlock_alu: mutex_unlock(&dev->alu_mutex); return rc; -- 2.39.2