netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Hui Tang <tanghui20@huawei.com>
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: mdio-ipq4019: fix possible invalid pointer dereference
Date: Tue, 15 Nov 2022 14:36:34 +0100	[thread overview]
Message-ID: <Y3OV4og418SxPF7+@lunn.ch> (raw)
In-Reply-To: <20221115045028.182441-1-tanghui20@huawei.com>

On Tue, Nov 15, 2022 at 12:50:28PM +0800, Hui Tang wrote:
> priv->eth_ldo_rdy is saved the return value of devm_ioremap_resource(),
> which !IS_ERR() should be used to check.
> 
> Fixes: 23a890d493e3 ("net: mdio: Add the reset function for IPQ MDIO driver")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>
> ---
>  drivers/net/mdio/mdio-ipq4019.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/mdio/mdio-ipq4019.c b/drivers/net/mdio/mdio-ipq4019.c
> index 4eba5a91075c..d7a1f7c56f97 100644
> --- a/drivers/net/mdio/mdio-ipq4019.c
> +++ b/drivers/net/mdio/mdio-ipq4019.c
> @@ -188,7 +188,7 @@ static int ipq_mdio_reset(struct mii_bus *bus)
>  	/* To indicate CMN_PLL that ethernet_ldo has been ready if platform resource 1
>  	 * is specified in the device tree.
>  	 */
> -	if (priv->eth_ldo_rdy) {
> +	if (!IS_ERR(priv->eth_ldo_rdy)) {
>  		val = readl(priv->eth_ldo_rdy);
>  		val |= BIT(0);
>  		writel(val, priv->eth_ldo_rdy);

There is a general pattern in the kernel that optional things are set
to NULL if the resource does not exist. Often there is a
get_foo_optional() which will return a NULL point if the things does
not exist, the thing if it does exist, or an error code if a real
error happened.

So please follow this patterns. Check the return value in
ipq4019_mdio_probe(). Looking at __devm_ioremap_resource() i _think_
it returns -ENOMEM if the resource does not exist? So maybe any other
error is a real error, and should be reported, and -ENOMEM should
result in eth_ldo_rdy set to NULL?

       Andrew

  reply	other threads:[~2022-11-15 13:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15  4:50 [PATCH] net: mdio-ipq4019: fix possible invalid pointer dereference Hui Tang
2022-11-15 13:36 ` Andrew Lunn [this message]
2022-11-17  8:50   ` Hui Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3OV4og418SxPF7+@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mw@semihalf.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tanghui20@huawei.com \
    --cc=yusongping@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).