LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH -next] drm/meson: Fix potential NULL dereference in meson_drv_bind_master()
@ 2018-03-20 14:20 Wei Yongjun
2018-03-20 15:04 ` Neil Armstrong
0 siblings, 1 reply; 3+ messages in thread
From: Wei Yongjun @ 2018-03-20 14:20 UTC (permalink / raw)
To: Neil Armstrong, David Airlie, Carlo Caione, Kevin Hilman
Cc: Wei Yongjun, dri-devel, linux-amlogic, linux-arm-kernel,
linux-kernel, kernel-janitors
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.
This is detected by Coccinelle semantic patch.
@@
expression pdev, res, n, t, e, e1, e2;
@@
res = platform_get_resource_byname(pdev, t, n);
+ if (!res)
+ return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
drivers/gpu/drm/meson/meson_drv.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
index 3baceb7..32b1a6c 100644
--- a/drivers/gpu/drm/meson/meson_drv.c
+++ b/drivers/gpu/drm/meson/meson_drv.c
@@ -197,6 +197,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
priv->io_base = regs;
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hhi");
+ if (!res)
+ return -EINVAL;
/* Simply ioremap since it may be a shared register zone */
regs = devm_ioremap(dev, res->start, resource_size(res));
if (!regs) {
@@ -213,6 +215,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
}
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmc");
+ if (!res)
+ return -EINVAL;
/* Simply ioremap since it may be a shared register zone */
regs = devm_ioremap(dev, res->start, resource_size(res));
if (!regs) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] drm/meson: Fix potential NULL dereference in meson_drv_bind_master()
2018-03-20 14:20 [PATCH -next] drm/meson: Fix potential NULL dereference in meson_drv_bind_master() Wei Yongjun
@ 2018-03-20 15:04 ` Neil Armstrong
2018-03-20 16:16 ` Neil Armstrong
0 siblings, 1 reply; 3+ messages in thread
From: Neil Armstrong @ 2018-03-20 15:04 UTC (permalink / raw)
To: Wei Yongjun, David Airlie, Carlo Caione, Kevin Hilman
Cc: kernel-janitors, linux-kernel, dri-devel, linux-amlogic,
linux-arm-kernel
On 20/03/2018 15:20, Wei Yongjun 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.
>
> This is detected by Coccinelle semantic patch.
>
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
>
> res = platform_get_resource_byname(pdev, t, n);
> + if (!res)
> + return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap(e1, res->start, e2);
>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
> drivers/gpu/drm/meson/meson_drv.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
> index 3baceb7..32b1a6c 100644
> --- a/drivers/gpu/drm/meson/meson_drv.c
> +++ b/drivers/gpu/drm/meson/meson_drv.c
> @@ -197,6 +197,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
> priv->io_base = regs;
>
> res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hhi");
> + if (!res)
> + return -EINVAL;
> /* Simply ioremap since it may be a shared register zone */
> regs = devm_ioremap(dev, res->start, resource_size(res));
> if (!regs) {
> @@ -213,6 +215,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
> }
>
> res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmc");
> + if (!res)
> + return -EINVAL;
> /* Simply ioremap since it may be a shared register zone */
> regs = devm_ioremap(dev, res->start, resource_size(res));
> if (!regs) {
>
>
> _______________________________________________
> linux-amlogic mailing list
> linux-amlogic@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-amlogic
>
Thanks,
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] drm/meson: Fix potential NULL dereference in meson_drv_bind_master()
2018-03-20 15:04 ` Neil Armstrong
@ 2018-03-20 16:16 ` Neil Armstrong
0 siblings, 0 replies; 3+ messages in thread
From: Neil Armstrong @ 2018-03-20 16:16 UTC (permalink / raw)
To: Wei Yongjun, David Airlie, Carlo Caione, Kevin Hilman
Cc: kernel-janitors, linux-kernel, dri-devel, linux-amlogic,
linux-arm-kernel
On 20/03/2018 16:04, Neil Armstrong wrote:
> On 20/03/2018 15:20, Wei Yongjun 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.
>>
>> This is detected by Coccinelle semantic patch.
>>
>> @@
>> expression pdev, res, n, t, e, e1, e2;
>> @@
>>
>> res = platform_get_resource_byname(pdev, t, n);
>> + if (!res)
>> + return -EINVAL;
>> ... when != res == NULL
>> e = devm_ioremap(e1, res->start, e2);
>>
>> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
>> ---
>> drivers/gpu/drm/meson/meson_drv.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
>> index 3baceb7..32b1a6c 100644
>> --- a/drivers/gpu/drm/meson/meson_drv.c
>> +++ b/drivers/gpu/drm/meson/meson_drv.c
>> @@ -197,6 +197,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
>> priv->io_base = regs;
>>
>> res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hhi");
>> + if (!res)
>> + return -EINVAL;
>> /* Simply ioremap since it may be a shared register zone */
>> regs = devm_ioremap(dev, res->start, resource_size(res));
>> if (!regs) {
>> @@ -213,6 +215,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
>> }
>>
>> res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmc");
>> + if (!res)
>> + return -EINVAL;
>> /* Simply ioremap since it may be a shared register zone */
>> regs = devm_ioremap(dev, res->start, resource_size(res));
>> if (!regs) {
>>
>>
>> _______________________________________________
>> linux-amlogic mailing list
>> linux-amlogic@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-amlogic
>>
> Thanks,
>
> Acked-by: Neil Armstrong <narmstrong@baylibre.com>
>
Applied to drm-misc-next
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-20 16:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-20 14:20 [PATCH -next] drm/meson: Fix potential NULL dereference in meson_drv_bind_master() Wei Yongjun
2018-03-20 15:04 ` Neil Armstrong
2018-03-20 16:16 ` Neil Armstrong
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).