From: Jiri Olsa <olsajiri@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: kim.phillips@amd.com, linux-perf-users@vger.kernel.org
Subject: Re: [bug report] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
Date: Wed, 9 Feb 2022 16:09:46 +0100 [thread overview]
Message-ID: <YgPZOiExIZzgw/PH@krava> (raw)
In-Reply-To: <20220208112239.GA18799@kili>
On Tue, Feb 08, 2022 at 02:22:39PM +0300, Dan Carpenter wrote:
> Hello Kim Phillips,
>
> This is a semi-automatic email about new static checker warnings.
>
> The patch 9fe8895a27a8: "perf env: Add perf_env__cpuid,
> perf_env__{nr_}pmu_mappings" from Aug 17, 2021, leads to the
> following Smatch complaint:
>
> ./tools/perf/util/env.c:476 perf_env__nr_pmu_mappings()
> error: we previously assumed 'env' could be null (see line 470)
>
> ./tools/perf/util/env.c
> 469
> 470 if (!env || !env->nr_pmu_mappings) { /* Assume local operation */
> ^^^
> Checks for NULL
>
> 471 status = perf_env__read_pmu_mappings(env);
> 472 if (status)
> 473 return 0;
> 474 }
> 475
> 476 return env->nr_pmu_mappings;
> ^^^^
> Unchecked dereference
>
> 477 }
>
> regards,
> dan carpenter
I think we need to bail out for !env
jirka
---
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 579e44c59914..bc30d8cd2790 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -467,7 +467,10 @@ int perf_env__nr_pmu_mappings(struct perf_env *env)
{
int status;
- if (!env || !env->nr_pmu_mappings) { /* Assume local operation */
+ if (!env)
+ return 0;
+
+ if (!env->nr_pmu_mappings) { /* Assume local operation */
status = perf_env__read_pmu_mappings(env);
if (status)
return 0;
@@ -480,7 +483,10 @@ const char *perf_env__pmu_mappings(struct perf_env *env)
{
int status;
- if (!env || !env->pmu_mappings) { /* Assume local operation */
+ if (!env)
+ return NULL;
+
+ if (!env->pmu_mappings) { /* Assume local operation */
status = perf_env__read_pmu_mappings(env);
if (status)
return NULL;
next prev parent reply other threads:[~2022-02-09 15:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 11:22 [bug report] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings Dan Carpenter
2022-02-09 15:09 ` Jiri Olsa [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-07-18 13:15 Dan Carpenter
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=YgPZOiExIZzgw/PH@krava \
--to=olsajiri@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=kim.phillips@amd.com \
--cc=linux-perf-users@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.