Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6102488iob; Tue, 10 May 2022 10:20:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRRmrfIkWISueN0U2m+0ysJQ6Nzp9fK6kFF9YmyJL7BGkBKV5SMWjbk0ZBJ606Xa0rNRic X-Received: by 2002:a05:6871:721:b0:ed:a9f8:f50c with SMTP id f33-20020a056871072100b000eda9f8f50cmr656740oap.8.1652203246238; Tue, 10 May 2022 10:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652203246; cv=none; d=google.com; s=arc-20160816; b=g+aq49lxr352VNh6YJAjabOt56O+8ychpriotkwM8FEdTsV6MKibMg2PO0WQfXkx73 WDwf6xQ4smEPSrg7Z1hw+dx2sZgccE4il4MlAl89b6ok5fLTcVKrXmel9P17vXCQMVPD MamW+dzLHe9aM4XUUy4u3V4wzwfKyr5w4ccXYkA3ccf6z9SAyDtf9bGyDqGrhOYDKIw2 ZA/PCtbG6OyCPeOv2N9hPpz1tJ0EVXd8l4lGjvYrX0CS5F/Cc6a8XX6WpnYwqItZ7AuJ AwkkbBkFZlpDrUu3N/0UY1TLb34IdlzAj5LJK1vyXVuCP1meAP1ZM1Ze3kznQme+vAQz T0yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:message-id:subject:to:from:references :in-reply-to:content-transfer-encoding:mime-version:dkim-signature; bh=vOEj9yJo1smqudo4BOp2KjTlXQUF3OE/Z+y5aJ69TJs=; b=lWc0PHWY51udMNuTT2wkPToJIDHBWdnYvsAcJrpAOGZpHETXPhlTmbG3nsdFLJmtE4 xKlJ2kQXR9ZkNyyDd6yJhA/vFwotoQp9igY5j3evy4L4Gjt0fbOOlo96uCYhknNSKvKI PPMWcEvhHGXWq8lPjU+YANIzTyNACzglv2BHdLh9rXwCV6xqRhGS5L2XOuW0zCzCi9S4 4AyfVP2KUw57YE3vDScGZMPBxGQKdRBh9M4K3slEogaG6/kQrEdMTUVmN9sSrGCHS7Qn 2kUiwlTTpxFau8L4P2X0X6AScEHJg7dFE7oTTWj6Uoc9C3vd7vlNuo1z1B7iwTdUhHAG pNRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b12edvEC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a9d4b09000000b00605f739ae98si12767280otf.101.2022.05.10.10.20.31; Tue, 10 May 2022 10:20:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b12edvEC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239174AbiEJPOB (ORCPT + 99 others); Tue, 10 May 2022 11:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345358AbiEJPNr (ORCPT ); Tue, 10 May 2022 11:13:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 250F7E15DA; Tue, 10 May 2022 07:48:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CB8AFB81DC2; Tue, 10 May 2022 14:48:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 469F0C385C2; Tue, 10 May 2022 14:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652194116; bh=c72iSkrAht/54lLLKTIxiRoey/GUJUzE+v+TIYu3Wck=; h=In-Reply-To:References:From:To:Subject:Date:From; b=b12edvEC6Cd9+lzThv0TF16/SG5tD+l/8mvTxGiKtAdTgm8szgIO5yF+vn/5U+T55 3+808qHZKr/ypcSlwIzOJtTEN6tPN/wOi7v67RFWNrnC70RE21Bhz3G8EgKHVCffHR ndllQ5LFfqR+hgtg8ou3g9b3gTpAt9ZcSpgec6U/u4GgHep4cX7Lx4TgyPDzZWGqqo v/2uqch5DV62WaiZmff7MpPnEKIUITh0ZgObNK8EAwkyjRDy89w8N/C5gVV7j96lCJ wzoRuQFvv2GQLenULmCWJJyP3T6yDoz2aWxaJ8OoYLmi8I5hDVeANbdYCGQqluhDMJ FzkbaDlhUmkew== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20220510142247.16071-1-wanjiabing@vivo.com> References: <20220510142247.16071-1-wanjiabing@vivo.com> From: Antoine Tenart To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Heiner Kallweit , Jakub Kicinski , Paolo Abeni , Russell King , Wan Jiabing , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v2 net] net: phy: mscc: Add error check when __phy_read() failed Message-ID: <165219411356.3924.11722336879963021691@kwain> Date: Tue, 10 May 2022 16:48:33 +0200 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Quoting Wan Jiabing (2022-05-10 16:22:45) > 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. >=20 > 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. >=20 > Fixes: fa164e40c53b ("net: phy: mscc: split the driver into separate file= s") Does this fix an actual issue or was this found by code inspection? If that is not fixing a real issue I don't think it should go to stable trees. Also this is not the right commit, the __phy_read call was introduced before splitting the file. > static u32 vsc8584_macsec_phy_read(struct phy_device *phydev, > enum macsec_bank bank, u32 reg) > { > - u32 val, val_l =3D 0, val_h =3D 0; > + int rc, val, val_l, val_h; > unsigned long deadline; > - int rc; > + u32 ret =3D 0; > =20 > rc =3D 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 =3D jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEO= UT_MS); > do { > val =3D __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_19); > + if (val < 0) > + goto failed; > } while (time_before(jiffies, deadline) && !(val & MSCC_PHY_MACSE= C_19_CMD)); > =20 > val_l =3D __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_17); > val_h =3D __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_18); > =20 > + if (val_l > 0 && val_h > 0) > + ret =3D (val_h << 16) | val_l; Both values have to be non-0 for the function to return a value? I haven't checked but I would assume it is valid to have one of the two being 0. > failed: > phy_restore_page(phydev, rc, rc); > =20 > - return (val_h << 16) | val_l; > + return ret; > } Thanks, Antoine