Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3944431pxj; Mon, 21 Jun 2021 09:55:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHhg8bQVo+UTOKHlndis+pLYRvlFbG7sNy/NM5saPx2kZSLY/YFUDDdZfwI+bXjsatSBW7 X-Received: by 2002:a05:6638:379d:: with SMTP id w29mr18612014jal.2.1624294538419; Mon, 21 Jun 2021 09:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294538; cv=none; d=google.com; s=arc-20160816; b=Rqp++/B755JG37m4MMn9z8Qrn7a6LribO/RpIF4Hcb5uFmzjwV8WVht/aSxI2hDZsU +vDB2AzUaR61ODIWvXrjnsz0OjtEcJFb0YPeKQO16UjnYzxwCGRc2FmSXwUgcILp4MyJ ATdJ4E0k4IhltJNFxGFYs2eJPx5bEiEPQUS6Ixdq9XL6olRH0RyHj2po7m9MpVDPqQwE eqX3ASE6whQSVqZYrbXTsx+omzPZfoo50YHlAF55s8gl6EjqyztQefcDs2/MCD2C87sm /TYjtHC4OMG7MexQ7e/WvAqzv9GWTgF3wh6Xa+/yAVVN7g31cT/atrRYXtQxhuffKU5A HYvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jaDryQKrGcLdUuIlHGlcHnVBpuzpZlL3j5CmdvJL+k4=; b=tWdRB5LsuKqAo0yGwqq4HcGXWjDF7MclOAnKVKkhVO2MPiF6JDbgR4UzR30nWwZCPK Xffi3YLmOqBR5DasP4T1Cyx9Bg49a/syoOyRFDH3LygSrtX81M/qg9iU7rHz0M00pBKn rHK4ErmCI24ztSJ4BBPEtsz8gQhuFOR0hjXjgAAvaO6NpoPsCql6VshEBMaQ7oAqVjkn IlWpAVQKW6lEBPZ6MVi15TkNut/mxy1L++7u5ptZhAto7I4o/Il+Nbn/zBRH8RQN3jyH 8spfDafF3Ud+CYoOhS4HfKAWqcuvKSQBBkJJ+8O5iDfve2L0K5y8h9tPPyO8/EkrWLoI A3qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="aWUR+/R5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si14582215ilv.59.2021.06.21.09.55.26; Mon, 21 Jun 2021 09:55:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="aWUR+/R5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233291AbhFUQ41 (ORCPT + 99 others); Mon, 21 Jun 2021 12:56:27 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:47952 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233483AbhFUQy3 (ORCPT ); Mon, 21 Jun 2021 12:54:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=jaDryQKrGcLdUuIlHGlcHnVBpuzpZlL3j5CmdvJL+k4=; b=aWUR+/R5EO1aRCxQCNGCMZoRE4 T4sp0dVTbrRIowJsEUvMopr0XmqD5ScuH7jZxGhfUmUCCRvmxHLyGtZFlxa4XmziuKEEnW6XW5+xb zYjin4yF5NkBvAO/63hV/d/mFfqVtThkyAkVvbIiveJ54BoxUN1YehSTCAmKebiDCBEQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1lvN9R-00AXl6-E3; Mon, 21 Jun 2021 18:51:57 +0200 Date: Mon, 21 Jun 2021 18:51:57 +0200 From: Andrew Lunn To: Colin Ian King Cc: Qing Zhang , Jiaxun Yang , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Maxime Coquelin , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: stmmac: pci: Add dwmac support for Loongson Message-ID: References: <37057fe8-f7d1-7ee0-01c7-916577526b5b@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <37057fe8-f7d1-7ee0-01c7-916577526b5b@canonical.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 21, 2021 at 04:51:28PM +0100, Colin Ian King wrote: > Hi, > > Static analysis by Coverity on today's linux-next has found an issue in > function loongson_dwmac_probe with the following commit: > > commit 30bba69d7db40e732d6c0aa6d4890c60d717e314 > Author: Qing Zhang > Date: Fri Jun 18 10:53:34 2021 +0800 > > stmmac: pci: Add dwmac support for Loongson > > The analysis is as follows: > > 110 plat->phy_interface = device_get_phy_mode(&pdev->dev); > > Enum compared against 0 > (NO_EFFECT) > unsigned_compare: This less-than-zero comparison of an > unsigned value is never true. plat->phy_interface < 0U. > > 111 if (plat->phy_interface < 0) > 112 dev_err(&pdev->dev, "phy_mode not found\n"); > > Enum plat->phy_interface is unsigned, so can't be negative and so the > comparison will always be false. > > A possible fix is to use int variable ret for the assignment and check: > > > ret = device_get_phy_mode(&pdev->dev); > if (ret < 0) > dev_err(&pdev->dev, "phy_mode not found\n"); > plat->phy_interface = ret; > > ..however, I think the dev_err may need handling too, e.g. > > ret = device_get_phy_mode(&pdev->dev); > if (ret < 0) { > dev_err(&pdev->dev, "phy_mode not found\n"); > ret = -ENODEV; > goto cleanup; /* needs to be written */ > } > plat->phy_interface = ret; Potentially a cleaner fix is to use of_get_phy_mode(), which separates the success/error value from the phy_interface_t. Andrew