Skip to content

Commit

Permalink
drm/meson: Fix potential NULL dereference in meson_drv_bind_master()
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1521555630-29284-1-git-send-email-weiyongjun1@huawei.com
  • Loading branch information
Wei Yongjun authored and Neil Armstrong committed Mar 20, 2018
1 parent ddc389f commit acaa3f1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/gpu/drm/meson/meson_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit acaa3f1

Please sign in to comment.