From: narmstrong@baylibre.com (Neil Armstrong)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH -next] drm/meson: Fix potential NULL dereference in meson_drv_bind_master()
Date: Tue, 20 Mar 2018 17:16:41 +0100 [thread overview]
Message-ID: <1772626e-c521-a072-76e4-64e3b4883f2e@baylibre.com> (raw)
In-Reply-To: <4cad8099-dbb8-d12c-9ce8-b64688222bd7@baylibre.com>
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 at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-amlogic
>>
> Thanks,
>
> Acked-by: Neil Armstrong <narmstrong@baylibre.com>
>
Applied to drm-misc-next
prev parent reply other threads:[~2018-03-20 16:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 14:20 Wei Yongjun
2018-03-20 15:04 ` Neil Armstrong
2018-03-20 16:16 ` Neil Armstrong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1772626e-c521-a072-76e4-64e3b4883f2e@baylibre.com \
--to=narmstrong@baylibre.com \
--cc=linus-amlogic@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®