From: Boris Brezillon <boris.brezillon@collabora.com>
To: Yu Liao <liaoyu15@huawei.com>
Cc: <emma@anholt.net>, <mripard@kernel.org>, <eric@anholt.net>,
<bbrezillon@kernel.org>, <liwei391@huawei.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/vc4: fix dereference before NULL check
Date: Tue, 28 Jun 2022 08:55:33 +0200 [thread overview]
Message-ID: <20220628085533.7b7885fb@collabora.com> (raw)
In-Reply-To: <20220628063657.3169049-1-liaoyu15@huawei.com>
On Tue, 28 Jun 2022 14:36:57 +0800
Yu Liao <liaoyu15@huawei.com> wrote:
> The "perfmon" pointer is equal to the return value of idr_find
> which may be NULL, access by vc4_perfmon_get before checking if
> it was NULL. Fix this by dereferencing "perfmon" after "perfmon"
> has been null checked.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 65101d8c9108 ("drm/vc4: Expose performance counters to userspace")
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/vc4/vc4_perfmon.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
> index c7f5adb6bcf8..ca969b8c7dde 100644
> --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
> +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
> @@ -17,13 +17,17 @@
>
> void vc4_perfmon_get(struct vc4_perfmon *perfmon)
> {
> - struct vc4_dev *vc4 = perfmon->dev;
> + struct vc4_dev *vc4;
> +
> + if (!perfmon)
> + return;
> +
> + vc4 = perfmon->dev;
>
> if (WARN_ON_ONCE(vc4->is_vc5))
> return;
>
> - if (perfmon)
> - refcount_inc(&perfmon->refcnt);
> + refcount_inc(&perfmon->refcnt);
> }
>
> void vc4_perfmon_put(struct vc4_perfmon *perfmon)
next prev parent reply other threads:[~2022-06-28 6:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 6:36 [PATCH] drm/vc4: fix dereference before NULL check Yu Liao
2022-06-28 6:55 ` Boris Brezillon [this message]
2022-06-28 8:18 ` Maxime Ripard
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=20220628085533.7b7885fb@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=bbrezillon@kernel.org \
--cc=emma@anholt.net \
--cc=eric@anholt.net \
--cc=liaoyu15@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liwei391@huawei.com \
--cc=mripard@kernel.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