Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp606105rwb; Fri, 18 Nov 2022 06:03:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5hYjkS9lgT100XZ173nF+MDD3AvObv7Odc2HykJgVLkAlvgWwKTqio7KaiqX15zA9UwcEy X-Received: by 2002:a05:6402:4147:b0:461:b2b1:9702 with SMTP id x7-20020a056402414700b00461b2b19702mr6171798eda.274.1668780213880; Fri, 18 Nov 2022 06:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668780213; cv=none; d=google.com; s=arc-20160816; b=ZbKvdTFsWHXFsRnx3+5vHY3Wq7gLEWeKOHXqCa14vEJW1JsZM3mSoYR+LQ7tUB/yaG 3FpF5K8tXkIhoRLBFGGeO5KjfjDs3e95AsYBMadFghRS8t/iy6SNoDlltnL0R+CvW+PX GmdUFf9Xey1/eGqMlKN5LaLUbPIqaEFjPTN5wt0dIrPsPEokrqTqeQfFHamhyeWj2v/c iRei1SHuqhnVif4qZKEoOXuOfr+9K0PHi4UCr89M2t8qkFqgAUUOceUFdxh5RMMpQdOL 6aOUtxOjccrwCLTsIEsz2T91VM7tKtvGK4UfAufYq/zlDHTKSp2c+VlzDOvrfdq0jCef g+/w== 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=OHv2PldMBepVVDAa5A0JeBaGKPLN9PMK5om1gj1ebDw=; b=TWuqYel5FljNMWW5GLayLeBwT5Wg5jxQs+nbhdnQZZUi2Woq9T365iNwILS2Jd5jqG EkSLe74xt2HfcCaHFB3ra+LIz49IIhuMYGtrJT7nfCLpDqEUcONO57gRaDvlSBoLWPcm o8BiDkxVHkIY0as76hYuN5GyhZiH9R1UmZjp5szwqxW4PszGwmnlEP2i1jmEof02qeW4 1QQMFfhflxP9yz1ftrj9w5NBcMqk52YH8ejlkkqmL6fT4rBvtRYKZ/2QWPJsH3NPrbyH h39pcne552qyIoVsZ8ppXaKvmJKjgpHnO50HjlG4uRUXSj/GxAGd63/pgkHUpdfwZ41j f1GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=iz4b8o5X; 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=lunn.ch Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i30-20020a0564020f1e00b00457c6b5dc07si3237332eda.455.2022.11.18.06.03.08; Fri, 18 Nov 2022 06:03:33 -0800 (PST) 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=@lunn.ch header.s=20171124 header.b=iz4b8o5X; 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=lunn.ch Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242063AbiKRNop (ORCPT + 91 others); Fri, 18 Nov 2022 08:44:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241574AbiKRNon (ORCPT ); Fri, 18 Nov 2022 08:44:43 -0500 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5206C781BB; Fri, 18 Nov 2022 05:44:42 -0800 (PST) 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=OHv2PldMBepVVDAa5A0JeBaGKPLN9PMK5om1gj1ebDw=; b=iz4b8o5Xxospq1YOk7rNOn2xvx W5kXpYeRlHKZhzq4FuMm6INdH/g/isz00SgdqnxwK4LEvl7/bIkud/cfLuo/QJTsaMvd6GbGOLE09 t37xgnsYQFHcoIba4e41VufAQT76vUncRywBdGw6hQMFzSpq9VomE6vuqtVBfp62L06Q=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1ow1fF-002nYk-RN; Fri, 18 Nov 2022 14:44:17 +0100 Date: Fri, 18 Nov 2022 14:44:17 +0100 From: Andrew Lunn To: Hui Tang Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, mw@semihalf.com, linux@armlinux.org.uk, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, yusongping@huawei.com Subject: Re: [PATCH net v2] net: mdio-ipq4019: fix possible invalid pointer dereference Message-ID: References: <20221117090514.118296-1-tanghui20@huawei.com> <6cad3105-0e70-d890-162b-513855885fde@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6cad3105-0e70-d890-162b-513855885fde@huawei.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS 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 > So, the code should be as follows, is that right? > > + void __iomem *devm_ioremap_resource_optional(struct device *dev, > + const struct resource *res) > + { > + void __iomem *base; > + > + base = __devm_ioremap_resource(dev, res, DEVM_IOREMAP); > + if (IS_ERR(base) && PTR_ERR(base) == -ENOMEM) > + return NULL; > + > + return base; > + } > > > [...] > res = platform_get_resource(pdev, IORESOURCE_MEM, 1); > - if (res) > + if (res) { > + priv->eth_ldo_rdy = devm_ioremap_resource_optional(&pdev->dev, res) > + if (IS_ERR(priv->eth_ldo_rdy)) > + return PTR_ERR(priv->eth_ldo_rdy); > + } > [...] Yes, that is the basic concept. The only thing i might change is the double meaning of -ENOMEM. __devm_ioremap_resource() allocates memory, and if that memory allocation fails, it returns -ENOMEM. If the resource does not exist, it also returns -ENOMEM. So you cannot tell these two error conditions apart. Most of the other get_foo() calls return -ENODEV if the gpio/regulator/clock does not exist, so you can tell if you are out of memory. But ioremap is specifically about memory so -ENOMEM actually makes sense. If you are out of memory, it seems likely the problem is not going to go away quickly, so the next allocation will also fail, and hopefully the error handling will then work. So i don't think it is major issue. So yes, go with the code above. Andrew