[PATCH 1/2] phy: usb: Fix potential NULL dereference in sp_usb_phy_probe()
Sun Ke
sunke32 at huawei.com
Thu Sep 8 23:30:32 PDT 2022
在 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 at 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?
No, just code review.
Thanks,
Sun Ke
>
> thanks,
>
> greg k-h
> .
>
More information about the linux-phy
mailing list