From patchwork Tue May 10 14:22:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiabing Wan X-Patchwork-Id: 12845098 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C92B7C4332F for ; Tue, 10 May 2022 14:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344327AbiEJPBg (ORCPT ); Tue, 10 May 2022 11:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345205AbiEJPAj (ORCPT ); Tue, 10 May 2022 11:00:39 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2093.outbound.protection.outlook.com [40.107.255.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B86173356; Tue, 10 May 2022 07:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iSVFot9fbyVk2kxB4Qsx2rcKLTSg5mxpuj4xnp7AybjA7RONFRO9LrpdcHyH+VPXNzw6+Z1pDIFc26wGKD3qck+OsU6cllQBFHDVh+2KK+RXVwXDiHhzz0T33yBUfoWylsxSqlPPvFeJqWahN4tQeUqPRCitALwjIwvHITW8VGjGgBdHafNGR9lb6jBTYN/2I03aL2Vo+4Xrb11MI11AzCgU9fG1sxVIxhQUQq1kIJEVWmdyouA+nZ5Grt2gnlxaxSdEv01ilVPVu24BXU9Gu9pNVx9Jm5UnnuXyM0Uy1G+G2k3ol/9iVZDsVov/rRAQAS32YZ7E7WDl5eXEdQkCgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZHP0ObP+ohnHA57G2i5wBjCghCtWVCrzKqv/Q6fMWvA=; b=W2zoJxmMBOv8/3wND83i+47LM3eXPNcf+AVmAzG4N0iXJwqcmwLWT9u/340LGXdK5hkDnBCYmzJ76I7Y9YuSDaFD3Ret/U4vT5Iw00oIVdNNRi48m3Z0ftFYAIVdFWy59m7BO76bEUXqAGsQgLuJ/BZJFhnX/bp9ktbhvuIm25BZ4xkefsbW3vHUVDu4u9QZOnyIbXZWNqq8YDzgnMTljwSyoyQSzJVbEtxvhGjamsKuhCb14ecavd4QNe0GonRRtYnSuqU0w40ZMyjjAQqavVUroQ6Xr8h1wyH0fxz4ZfBMZ0uoj2p+wjwqGWgPFxXgK3vsPYPwimfO2DX7XsFhdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo0.onmicrosoft.com; s=selector2-vivo0-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZHP0ObP+ohnHA57G2i5wBjCghCtWVCrzKqv/Q6fMWvA=; b=PqKelzSK0B74uZrH5JwcqiaG71m9wRvcUI9+0D3OkCvuMI7b+BdnYco37LV8ICHQmK/n81NoGqT0LMlthDPY34h5u7QoioUP4QBgQS6L+VkK3bytpQxoRbuXgU5EBT4aF1+ubblalZR8q5RtZlFZfpIg322QrEfKDzrOI4wn9GM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) by PSAPR06MB4056.apcprd06.prod.outlook.com (2603:1096:301:3f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Tue, 10 May 2022 14:22:59 +0000 Received: from SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c]) by SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c%7]) with mapi id 15.20.5227.022; Tue, 10 May 2022 14:22:59 +0000 From: Wan Jiabing To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wan Jiabing , Antoine Tenart , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 net] net: phy: mscc: Add error check when __phy_read() failed Date: Tue, 10 May 2022 22:22:45 +0800 Message-Id: <20220510142247.16071-1-wanjiabing@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: HK2PR02CA0196.apcprd02.prod.outlook.com (2603:1096:201:21::32) To SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6cf24ce-7b85-43dd-22f3-08da329094cd X-MS-TrafficTypeDiagnostic: PSAPR06MB4056:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xqy8EW+BnxBB+zz48MAtFjIPidHUyeT7W//gxBtyKb8CLcCJZRWfvFRIlRmDEBvg28QrXPmXmj5obUJjyhCE5Ek8TJ5BR6gY9JZ4kY6iuzmTnmYWaVAvb2t/HbqzchHePnBSuN14vP9TaYPdrJgmZCKYOyKT3glxk1xSsesYRH4oXeo1PqnBI+ZZuTSrKXfh0X6gPwu63VRk5xidLcMScPDLsIcnHzb94RFGQEmlFnahcs8KdClfw9TSakCu1hPPNsGXmkpaGkzFbu6y4wmH9btr9sPrlQ5+CjTf8noDQNXFScKLbQePOjEykKOA7lX5kB6Tn0kG8Cesa+XPSLOlN6wQRLqReXuuDcx8un4/blDDWWc/uk4/+qUAB+ztO3Cw9vaUSBk/UGi8xJjT8oYg+ADiwmAP3bBiUunNfUO2Syy3SOlwgvxQ71LtjMZXk0TlPTpUA9OpQOHpUT8+KAMzsMQyzR6uprJrNnxC96FbKTAhTRbuqMeM77usxVG7EQUXV6NcWMFrwjI9tQtjZyW0Yp7K3MyRm/0DQZfAVVJeBJ8ROc/49VtrYEUMuiFdhEvExBctLnlxtjyIByP5BajGBWFzkgDRWlqdKi4zSgSU4Z8oS8qyl9Lqn1nLwBHENY1a89hWqUd0syOsmu788MPbzS9DxzzL/t2iPO7J7fhcB+758Ss8RRtiS/QluNY/MbETZ7jluwXZ8+L05k3Smn57nPSyPmcgVkz6m5HOAJ0GvqE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SG2PR06MB3367.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(186003)(2616005)(66946007)(66476007)(66556008)(8676002)(83380400001)(1076003)(508600001)(86362001)(6666004)(6512007)(26005)(6486002)(6506007)(316002)(110136005)(52116002)(7416002)(921005)(2906002)(36756003)(5660300002)(38100700002)(38350700002)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: olXXya/mmu0N9W7hkE4P+KrRFeb3OM1BV12vsiGcYk90sR/uKj6wRjZz8sLkm0GubB0digv7u/TrG/CAclLgM4LuZ1DyC8nxwDgNxpV4lFVUUmh35C10kLQhPT1lcjhUzC5ZafowaaUtqeb2yNqIuLVqkXHuM7gfJwiwcJkQtqOzfKSAirMxJwlioF/QdrhaN1vQ43vxSWql+jVdb7HDstwQ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ImE9lzw22kRXdpx6wdVNA+/cIkQZxd2llk7BxODJqyXR/RYxCfzlME0oOXxPTgPDXb11dTz7Xtf9HYkktvltL1lLIz5lr/3UZ/9t3Lt3DX6ot/W2KfrEA03p+NPIpT/FNCu+4CXYUCofNcsEevHGOe0QXDfBMolaNQL+zLxKimRN7YSjfNb/40Ej+hBd6/4OIgfaG6KUo1LdC+a0eL71by3aXKVrAIZM4Gm2zk1utf9MNbncdIzSpLVYvVmzosMgT1wEPzCfZf8snyUysm1Mqj48//fy7fFqcQkwR6R9a3j7VQZH1X5m2ahSmBG8iCz8OmGebNmYrRyaemJpo7PUOqhbyoER46pdauVezdphmeDZZEZYtV7dpNlbtwoK2tp2YmmCs8u6L8HAtQxFJah61hJ7kzWyfiv6L8gyZFTzVySsCVkgVmTb7t+aU6g== X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6cf24ce-7b85-43dd-22f3-08da329094cd X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3367.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2022 14:22:58.1528 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dVCVCNx/oVLEXQ+6TmhZvKh64I4n4VkFRpGLucDpnPpdYLZwGFibGEDiOWsFNccajzWulhWdKkD5TPMudJwi1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR06MB4056 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Calling __phy_read() might return a negative error code. Use 'int' to declare variables which call __phy_read() and also add error check for them. The numerous callers of vsc8584_macsec_phy_read() don't expect it to fail. So don't return the error code from __phy_read(), but also don't return random values if it does fail. Fixes: fa164e40c53b ("net: phy: mscc: split the driver into separate files") Signed-off-by: Wan Jiabing --- Changelog: v2: - Sort variable declaration and add a detailed comment. --- drivers/net/phy/mscc/mscc_macsec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/mscc/mscc_macsec.c b/drivers/net/phy/mscc/mscc_macsec.c index b7b2521c73fb..58ad11a697b6 100644 --- a/drivers/net/phy/mscc/mscc_macsec.c +++ b/drivers/net/phy/mscc/mscc_macsec.c @@ -22,9 +22,9 @@ static u32 vsc8584_macsec_phy_read(struct phy_device *phydev, enum macsec_bank bank, u32 reg) { - u32 val, val_l = 0, val_h = 0; + int rc, val, val_l, val_h; unsigned long deadline; - int rc; + u32 ret = 0; rc = phy_select_page(phydev, MSCC_PHY_PAGE_MACSEC); if (rc < 0) @@ -47,15 +47,20 @@ static u32 vsc8584_macsec_phy_read(struct phy_device *phydev, deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS); do { val = __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_19); + if (val < 0) + goto failed; } while (time_before(jiffies, deadline) && !(val & MSCC_PHY_MACSEC_19_CMD)); val_l = __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_17); val_h = __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_18); + if (val_l > 0 && val_h > 0) + ret = (val_h << 16) | val_l; + failed: phy_restore_page(phydev, rc, rc); - return (val_h << 16) | val_l; + return ret; } static void vsc8584_macsec_phy_write(struct phy_device *phydev,