diff mbox series

[v2,4/4] perf cs-etm: Smatch: Fix potential NULL pointer dereference

Message ID 20190708143937.7722-5-leo.yan@linaro.org
State New
Headers show
Series perf: Fix errors detected by Smatch | expand

Commit Message

Leo Yan July 8, 2019, 2:39 p.m. UTC
Based on the following report from Smatch, fix the potential
NULL pointer dereference check.

  tools/perf/util/cs-etm.c:2545
  cs_etm__process_auxtrace_info() error: we previously assumed
  'session->itrace_synth_opts' could be null (see line 2541)

tools/perf/util/cs-etm.c
2541         if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
2542                 etm->synth_opts = *session->itrace_synth_opts;
2543         } else {
2544                 itrace_synth_opts__set_default(&etm->synth_opts,
2545                                 session->itrace_synth_opts->default_no_sample);
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
2546                 etm->synth_opts.callchain = false;
2547         }

'session->itrace_synth_opts' is impossible to be a NULL pointer in
cs_etm__process_auxtrace_info(), thus this patch removes the NULL
test for 'session->itrace_synth_opts'.

Signed-off-by: Leo Yan <leo.yan@linaro.org>

---
 tools/perf/util/cs-etm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.17.1

Comments

Mathieu Poirier July 8, 2019, 5:38 p.m. UTC | #1
On Mon, 8 Jul 2019 at 08:40, Leo Yan <leo.yan@linaro.org> wrote:
>

> Based on the following report from Smatch, fix the potential

> NULL pointer dereference check.

>

>   tools/perf/util/cs-etm.c:2545

>   cs_etm__process_auxtrace_info() error: we previously assumed

>   'session->itrace_synth_opts' could be null (see line 2541)

>

> tools/perf/util/cs-etm.c

> 2541         if (session->itrace_synth_opts && session->itrace_synth_opts->set) {

> 2542                 etm->synth_opts = *session->itrace_synth_opts;

> 2543         } else {

> 2544                 itrace_synth_opts__set_default(&etm->synth_opts,

> 2545                                 session->itrace_synth_opts->default_no_sample);

>                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^

> 2546                 etm->synth_opts.callchain = false;

> 2547         }

>

> 'session->itrace_synth_opts' is impossible to be a NULL pointer in

> cs_etm__process_auxtrace_info(), thus this patch removes the NULL

> test for 'session->itrace_synth_opts'.

>

> Signed-off-by: Leo Yan <leo.yan@linaro.org>

> ---

>  tools/perf/util/cs-etm.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

>

> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c

> index ad43a6e31827..ab578a06a790 100644

> --- a/tools/perf/util/cs-etm.c

> +++ b/tools/perf/util/cs-etm.c

> @@ -2537,7 +2537,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event,

>                 return 0;

>         }

>

> -       if (session->itrace_synth_opts && session->itrace_synth_opts->set) {

> +       if (session->itrace_synth_opts->set) {

>                 etm->synth_opts = *session->itrace_synth_opts;

>         } else {

>                 itrace_synth_opts__set_default(&etm->synth_opts,


This is in accordance with what was previously discussed.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>


> --

> 2.17.1

>
Arnaldo Carvalho de Melo July 8, 2019, 9:57 p.m. UTC | #2
Em Mon, Jul 08, 2019 at 11:38:48AM -0600, Mathieu Poirier escreveu:
> On Mon, 8 Jul 2019 at 08:40, Leo Yan <leo.yan@linaro.org> wrote:

> >

> > Based on the following report from Smatch, fix the potential

> > NULL pointer dereference check.

> >

> >   tools/perf/util/cs-etm.c:2545

> >   cs_etm__process_auxtrace_info() error: we previously assumed

> >   'session->itrace_synth_opts' could be null (see line 2541)

> >

> > tools/perf/util/cs-etm.c

> > 2541         if (session->itrace_synth_opts && session->itrace_synth_opts->set) {

> > 2542                 etm->synth_opts = *session->itrace_synth_opts;

> > 2543         } else {

> > 2544                 itrace_synth_opts__set_default(&etm->synth_opts,

> > 2545                                 session->itrace_synth_opts->default_no_sample);

> >                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^

> > 2546                 etm->synth_opts.callchain = false;

> > 2547         }

> >

> > 'session->itrace_synth_opts' is impossible to be a NULL pointer in

> > cs_etm__process_auxtrace_info(), thus this patch removes the NULL

> > test for 'session->itrace_synth_opts'.

> >

> > Signed-off-by: Leo Yan <leo.yan@linaro.org>

> > ---

> >  tools/perf/util/cs-etm.c | 2 +-

> >  1 file changed, 1 insertion(+), 1 deletion(-)

> >

> > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c

> > index ad43a6e31827..ab578a06a790 100644

> > --- a/tools/perf/util/cs-etm.c

> > +++ b/tools/perf/util/cs-etm.c

> > @@ -2537,7 +2537,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event,

> >                 return 0;

> >         }

> >

> > -       if (session->itrace_synth_opts && session->itrace_synth_opts->set) {

> > +       if (session->itrace_synth_opts->set) {

> >                 etm->synth_opts = *session->itrace_synth_opts;

> >         } else {

> >                 itrace_synth_opts__set_default(&etm->synth_opts,

> 

> This is in accordance with what was previously discussed.

> 

> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>


Thanks, applied.

- Arnaldo
diff mbox series

Patch

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index ad43a6e31827..ab578a06a790 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2537,7 +2537,7 @@  int cs_etm__process_auxtrace_info(union perf_event *event,
 		return 0;
 	}
 
-	if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
+	if (session->itrace_synth_opts->set) {
 		etm->synth_opts = *session->itrace_synth_opts;
 	} else {
 		itrace_synth_opts__set_default(&etm->synth_opts,