Re: [PATCH 1/2] phy: usb: Fix potential NULL dereference in sp_usb_phy_probe()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





在 2022/9/9 13:39, Greg KH 写道:
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@xxxxxxxxxx>
---
  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?

No, just code review.

Thanks,
Sun Ke

thanks,

greg k-h
.




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux