2021-12-20 06:50:10

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH] USB: host: Check for null res pointer

The return value of platform_get_resource() needs to be checked.
To avoid use of error pointer in case of the failure of alloc.

Fixes: 4808a1c02611 ("[PATCH] USB: Add isp116x-hcd USB host controller driver")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
drivers/usb/host/isp116x-hcd.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 8835f6bd528e..addd2b43a14c 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1541,9 +1541,15 @@ static int isp116x_remove(struct platform_device *pdev)

iounmap(isp116x->data_reg);
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ if (!res)
+ return -EINVAL;
+
release_mem_region(res->start, 2);
iounmap(isp116x->addr_reg);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res)
+ return -EINVAL;
+
release_mem_region(res->start, 2);

usb_put_hcd(hcd);
--
2.25.1



2021-12-20 10:15:24

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] USB: host: Check for null res pointer

Hello!

On 20.12.2021 9:49, Jiasheng Jiang wrote:

> The return value of platform_get_resource() needs to be checked.
> To avoid use of error pointer in case of the failure of alloc.
>
> Fixes: 4808a1c02611 ("[PATCH] USB: Add isp116x-hcd USB host controller driver")
> Signed-off-by: Jiasheng Jiang <[email protected]>
> ---
> drivers/usb/host/isp116x-hcd.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
> index 8835f6bd528e..addd2b43a14c 100644
> --- a/drivers/usb/host/isp116x-hcd.c
> +++ b/drivers/usb/host/isp116x-hcd.c
> @@ -1541,9 +1541,15 @@ static int isp116x_remove(struct platform_device *pdev)
>
> iounmap(isp116x->data_reg);
> res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> + if (!res)
> + return -EINVAL;
> +
> release_mem_region(res->start, 2);
> iounmap(isp116x->addr_reg);
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!res)
> + return -EINVAL;

Hm, these usually are reported as -ENODEV, no?

[...]

MBR, Sergey

2021-12-20 15:23:11

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] USB: host: Check for null res pointer

On Mon, Dec 20, 2021 at 02:49:46PM +0800, Jiasheng Jiang wrote:
> The return value of platform_get_resource() needs to be checked.
> To avoid use of error pointer in case of the failure of alloc.
>
> Fixes: 4808a1c02611 ("[PATCH] USB: Add isp116x-hcd USB host controller driver")
> Signed-off-by: Jiasheng Jiang <[email protected]>
> ---
> drivers/usb/host/isp116x-hcd.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
> index 8835f6bd528e..addd2b43a14c 100644
> --- a/drivers/usb/host/isp116x-hcd.c
> +++ b/drivers/usb/host/isp116x-hcd.c
> @@ -1541,9 +1541,15 @@ static int isp116x_remove(struct platform_device *pdev)
>
> iounmap(isp116x->data_reg);
> res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> + if (!res)
> + return -EINVAL;

You really can not fail a remove call. If you do so here, memory will
leak.

Please make this work no matter what.

thanks,

greg k-h