Linux USB
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Sun Ke <sunke32@huawei.com>
Cc: vincent.sunplus@gmail.com, kishon@ti.com, vkoul@kernel.org,
	p.zabel@pengutronix.de, linux-usb@vger.kernel.org,
	linux-phy@lists.infradead.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/2] phy: usb: Fix potential NULL dereference in sp_usb_phy_probe()
Date: Fri, 9 Sep 2022 07:39:32 +0200	[thread overview]
Message-ID: <YxrRlCytfPobnjSv@kroah.com> (raw)
In-Reply-To: <20220909013546.2259545-2-sunke32@huawei.com>

On Fri, Sep 09, 2022 at 09:35:45AM +0800, Sun Ke wrote:
> platform_get_resource_byname() may fail and return NULL, so we should
> better check it s return value to avoid a NULL pointer dereference
> a bit later in the code.
> 
> Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
> Signed-off-by: Sun Ke <sunke32@huawei.com>
> ---
>  drivers/phy/sunplus/phy-sunplus-usb2.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
> index 5269968b3060..d73a8a421d9c 100644
> --- a/drivers/phy/sunplus/phy-sunplus-usb2.c
> +++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
> @@ -249,11 +249,15 @@ static int sp_usb_phy_probe(struct platform_device *pdev)
>  	usbphy->dev = &pdev->dev;
>  
>  	usbphy->phy_res_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy");

How can this fail on this system?

> +	if (!usbphy->phy_res_mem)
> +		return -EINVAL;
>  	usbphy->phy_regs = devm_ioremap_resource(&pdev->dev, usbphy->phy_res_mem);
>  	if (IS_ERR(usbphy->phy_regs))
>  		return PTR_ERR(usbphy->phy_regs);
>  
>  	usbphy->moon4_res_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "moon4");

Same here, how can this fail?
Have you seen these failures happen in real systems?

thanks,

greg k-h

  reply	other threads:[~2022-09-09  5:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09  1:35 [PATCH 0/2] two fixes for phy usb Sun Ke
2022-09-09  1:35 ` [PATCH 1/2] phy: usb: Fix potential NULL dereference in sp_usb_phy_probe() Sun Ke
2022-09-09  5:39   ` Greg KH [this message]
2022-09-09  6:30     ` Sun Ke
2022-09-09  1:35 ` [PATCH 2/2] phy: usb: Fix return value check " Sun Ke

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=YxrRlCytfPobnjSv@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kishon@ti.com \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=sunke32@huawei.com \
    --cc=vincent.sunplus@gmail.com \
    --cc=vkoul@kernel.org \
    /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