2015-06-30 15:19:15

by Taeung Song

[permalink] [raw]
Subject: [PATCH v2 3/5] perf kvm: Fill in the missing freeing a session after an error occur

When an error occur a error value is just returned
without freeing the session. So allocating and freeing
session have to be matched as a pair even if an error occur.

Signed-off-by: Taeung Song <[email protected]>
---
tools/perf/builtin-kvm.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 74878cd..fc1cffb 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1061,8 +1061,10 @@ static int read_events(struct perf_kvm_stat *kvm)

symbol__init(&kvm->session->header.env);

- if (!perf_session__has_traces(kvm->session, "kvm record"))
- return -EINVAL;
+ if (!perf_session__has_traces(kvm->session, "kvm record")) {
+ ret = -EINVAL;
+ goto out_delete;
+ }

/*
* Do not use 'isa' recorded in kvm_exit tracepoint since it is not
@@ -1070,9 +1072,13 @@ static int read_events(struct perf_kvm_stat *kvm)
*/
ret = cpu_isa_config(kvm);
if (ret < 0)
- return ret;
+ goto out_delete;

- return perf_session__process_events(kvm->session);
+ ret = perf_session__process_events(kvm->session);
+
+out_delete:
+ perf_session__delete(kvm->session);
+ return ret;
}

static int parse_target_str(struct perf_kvm_stat *kvm)
--
1.9.1


2015-06-30 15:19:23

by Taeung Song

[permalink] [raw]
Subject: [PATCH v2 4/5] perf mem: Fill in the missing freeing a session after an error occur

When an error occur a error value is just returned
without freeing the session. So allocating and freeing
session have to be matched as a pair even if an error occur.

Signed-off-by: Taeung Song <[email protected]>
---
tools/perf/builtin-mem.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index da2ec06..a914ef7 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -124,7 +124,6 @@ static int report_raw_events(struct perf_mem *mem)
.mode = PERF_DATA_MODE_READ,
.force = mem->force,
};
- int err = -EINVAL;
int ret;
struct perf_session *session = perf_session__new(&file, false,
&mem->tool);
@@ -135,24 +134,23 @@ static int report_raw_events(struct perf_mem *mem)
if (mem->cpu_list) {
ret = perf_session__cpu_bitmap(session, mem->cpu_list,
mem->cpu_bitmap);
- if (ret)
+ if (ret) {
+ ret = -EINVAL;
goto out_delete;
+ }
}

- if (symbol__init(&session->header.env) < 0)
- return -1;
+ ret = symbol__init(&session->header.env);
+ if (ret < 0)
+ goto out_delete;

printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");

- err = perf_session__process_events(session);
- if (err)
- return err;
-
- return 0;
+ ret = perf_session__process_events(session);

out_delete:
perf_session__delete(session);
- return err;
+ return ret;
}

static int report_events(int argc, const char **argv, struct perf_mem *mem)
--
1.9.1

2015-06-30 19:58:03

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] perf mem: Fill in the missing freeing a session after an error occur

Em Wed, Jul 01, 2015 at 12:18:45AM +0900, Taeung Song escreveu:
> When an error occur a error value is just returned
> without freeing the session. So allocating and freeing
> session have to be matched as a pair even if an error occur.
>
> Signed-off-by: Taeung Song <[email protected]>
> ---
> tools/perf/builtin-mem.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
> index da2ec06..a914ef7 100644
> --- a/tools/perf/builtin-mem.c
> +++ b/tools/perf/builtin-mem.c
> @@ -124,7 +124,6 @@ static int report_raw_events(struct perf_mem *mem)
> .mode = PERF_DATA_MODE_READ,
> .force = mem->force,
> };
> - int err = -EINVAL;
> int ret;
> struct perf_session *session = perf_session__new(&file, false,
> &mem->tool);
> @@ -135,24 +134,23 @@ static int report_raw_events(struct perf_mem *mem)
> if (mem->cpu_list) {
> ret = perf_session__cpu_bitmap(session, mem->cpu_list,
> mem->cpu_bitmap);
> - if (ret)
> + if (ret) {
> + ret = -EINVAL;

Why not propagate perf_session__cpu_bitmap() return, this function
wasn't being consistent in returning errors, neither was you, as, see
below...

> goto out_delete;
> + }
> }
>
> - if (symbol__init(&session->header.env) < 0)
> - return -1;
> + ret = symbol__init(&session->header.env);
> + if (ret < 0)
> + goto out_delete;

Here you decided to propagate symbol__init() error return. :-)

I applied all the others, including the 3/5 v2 one.

Thanks,

- Arnaldo

>
> printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
>
> - err = perf_session__process_events(session);
> - if (err)
> - return err;
> -
> - return 0;
> + ret = perf_session__process_events(session);
>
> out_delete:
> perf_session__delete(session);
> - return err;
> + return ret;
> }
>
> static int report_events(int argc, const char **argv, struct perf_mem *mem)
> --
> 1.9.1

2015-07-01 04:58:35

by Taeung Song

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] perf mem: Fill in the missing freeing a session after an error occur



On 07/01/2015 04:57 AM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jul 01, 2015 at 12:18:45AM +0900, Taeung Song escreveu:
>> When an error occur a error value is just returned
>> without freeing the session. So allocating and freeing
>> session have to be matched as a pair even if an error occur.
>>
>> Signed-off-by: Taeung Song <[email protected]>
>> ---
>> tools/perf/builtin-mem.c | 18 ++++++++----------
>> 1 file changed, 8 insertions(+), 10 deletions(-)
>>
>> diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
>> index da2ec06..a914ef7 100644
>> --- a/tools/perf/builtin-mem.c
>> +++ b/tools/perf/builtin-mem.c
>> @@ -124,7 +124,6 @@ static int report_raw_events(struct perf_mem *mem)
>> .mode = PERF_DATA_MODE_READ,
>> .force = mem->force,
>> };
>> - int err = -EINVAL;
>> int ret;
>> struct perf_session *session = perf_session__new(&file, false,
>> &mem->tool);
>> @@ -135,24 +134,23 @@ static int report_raw_events(struct perf_mem *mem)
>> if (mem->cpu_list) {
>> ret = perf_session__cpu_bitmap(session, mem->cpu_list,
>> mem->cpu_bitmap);
>> - if (ret)
>> + if (ret) {
>> + ret = -EINVAL;
> Why not propagate perf_session__cpu_bitmap() return, this function
> wasn't being consistent in returning errors, neither was you, as, see
> below...

perf_session__cpu_bitmap()
when an error occurs in this function, a error value which is -1 is returned.
Therefore, this conditional sentence 'if (ret)' have to be changed to 'if (ret < 0)' as below.

- if (ret)
+ if (ret < 0)
goto out_delete;

Is it what you say ?


--
Thanks,
Taeung

>
>> goto out_delete;
>> + }
>> }
>>
>> - if (symbol__init(&session->header.env) < 0)
>> - return -1;
>> + ret = symbol__init(&session->header.env);
>> + if (ret < 0)
>> + goto out_delete;
> Here you decided to propagate symbol__init() error return. :-)
>
> I applied all the others, including the 3/5 v2 one.
>
> Thanks,
>
> - Arnaldo
>
>>
>> printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
>>
>> - err = perf_session__process_events(session);
>> - if (err)
>> - return err;
>> -
>> - return 0;
>> + ret = perf_session__process_events(session);
>>
>> out_delete:
>> perf_session__delete(session);
>> - return err;
>> + return ret;
>> }
>>
>> static int report_events(int argc, const char **argv, struct perf_mem *mem)
>> --
>> 1.9.1

2015-07-01 14:42:49

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] perf mem: Fill in the missing freeing a session after an error occur

Em Wed, Jul 01, 2015 at 01:58:23PM +0900, taeung escreveu:
> On 07/01/2015 04:57 AM, Arnaldo Carvalho de Melo wrote:
> >Em Wed, Jul 01, 2015 at 12:18:45AM +0900, Taeung Song escreveu:
> >>@@ -135,24 +134,23 @@ static int report_raw_events(struct perf_mem *mem)
> >> if (mem->cpu_list) {
> >> ret = perf_session__cpu_bitmap(session, mem->cpu_list,
> >> mem->cpu_bitmap);
> >>- if (ret)
> >>+ if (ret) {
> >>+ ret = -EINVAL;
> >Why not propagate perf_session__cpu_bitmap() return, this function
> >wasn't being consistent in returning errors, neither was you, as, see
> >below...

> perf_session__cpu_bitmap()
> when an error occurs in this function, a error value which is -1 is returned.
> Therefore, this conditional sentence 'if (ret)' have to be changed to 'if (ret < 0)' as below.
>
> - if (ret)
> + if (ret < 0)
> goto out_delete;
>
> Is it what you say ?

No, the above change is not related to what I mentioned, it is harmless
albeit not needed, what I mentioned was about the part just after the
if:

if (ret) {
ret = -EINVAL; <---------------- This one

But I see you removed that from your latest change, so all is fine now,
I think.

- Arnaldo

>
> --
> Thanks,
> Taeung
>
> >
> >> goto out_delete;
> >>+ }
> >> }
> >>- if (symbol__init(&session->header.env) < 0)
> >>- return -1;
> >>+ ret = symbol__init(&session->header.env);
> >>+ if (ret < 0)
> >>+ goto out_delete;
> >Here you decided to propagate symbol__init() error return. :-)
> >
> >I applied all the others, including the 3/5 v2 one.
> >
> >Thanks,
> >
> >- Arnaldo
> >
> >> printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
> >>- err = perf_session__process_events(session);
> >>- if (err)
> >>- return err;
> >>-
> >>- return 0;
> >>+ ret = perf_session__process_events(session);
> >> out_delete:
> >> perf_session__delete(session);
> >>- return err;
> >>+ return ret;
> >> }
> >> static int report_events(int argc, const char **argv, struct perf_mem *mem)
> >>--
> >>1.9.1

Subject: [tip:perf/urgent] perf kvm: Fill in the missing session freeing after an error occurs

Commit-ID: 41b983609a1618e9fa70023d83232ed959056c8a
Gitweb: http://git.kernel.org/tip/41b983609a1618e9fa70023d83232ed959056c8a
Author: Taeung Song <[email protected]>
AuthorDate: Wed, 1 Jul 2015 00:18:44 +0900
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 1 Jul 2015 17:53:49 -0300

perf kvm: Fill in the missing session freeing after an error occurs

When an error occurs an error value is just returned without freeing the
session. So allocating and freeing session have to be matched as a pair
even if an error occurs.

Signed-off-by: Taeung Song <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-kvm.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 74878cd..fc1cffb 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1061,8 +1061,10 @@ static int read_events(struct perf_kvm_stat *kvm)

symbol__init(&kvm->session->header.env);

- if (!perf_session__has_traces(kvm->session, "kvm record"))
- return -EINVAL;
+ if (!perf_session__has_traces(kvm->session, "kvm record")) {
+ ret = -EINVAL;
+ goto out_delete;
+ }

/*
* Do not use 'isa' recorded in kvm_exit tracepoint since it is not
@@ -1070,9 +1072,13 @@ static int read_events(struct perf_kvm_stat *kvm)
*/
ret = cpu_isa_config(kvm);
if (ret < 0)
- return ret;
+ goto out_delete;

- return perf_session__process_events(kvm->session);
+ ret = perf_session__process_events(kvm->session);
+
+out_delete:
+ perf_session__delete(kvm->session);
+ return ret;
}

static int parse_target_str(struct perf_kvm_stat *kvm)