Skip to contentSkip to conversation

perf_event: fix error handling path

PATCH In review [email protected] 4 participants 7 messages Dec 5, 2010 – Dec 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf_event: fix error handling path

fix error handling path

 kernel/perf_event.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -2
index cb6c0d2..62f9e9d 100644
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
 	}
 
 	err = alloc_callchain_buffers();
-	if (err)
-		release_callchain_buffers();
 exit:
 	mutex_unlock(&callchain_mutex);
 
#1 lore raw
Quoted 11 lines · On Sat, Dec 4, 2010 at 1:19 AM, <[email protected]> wrote:

fix error handling path

 kernel/perf_event.c |    2 --

 1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -0
index cb6c0d2..62f9e9d 100644

kernel/perf_event.c static int get_callchain_buffers(void) · line 1922

Quoted 5 lines
kernel/perf_event.c +0 -2
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
        }
 
        err = alloc_callchain_buffers();
-       if (err)
-               release_callchain_buffers();

Care to explain in the change log message? As I reader, is not clear to me what is wrong with this.

author
#2 lore raw
Quoted 15 lines · Thiago Farina
Quoted 13 lines · On Sat, Dec 4, 2010 at 1:19 AM,  <[email protected]> wrote:

fix error handling path

 kernel/perf_event.c |    2 --

 1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -0
index cb6c0d2..62f9e9d 100644
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
        }
 
Quoted 6 lines

kernel/perf_event.c static int get_callchain_buffers(void) · line 1922

Quoted 3 lines
kernel/perf_event.c +0 -2
        err = alloc_callchain_buffers();
-       if (err)
-               release_callchain_buffers();

Care to explain in the change log message? As I reader, is not clear to me what is wrong with this.

Sorry, the description should be as:
fix error handling path. alloc_callchain_buffers() can return -ENOMEM, in this time callchain_cpus_entries maybe is NULL, It will oops if invoke release_callchain_buffers() when callchain_cpus_entries is NULL.

author
#3 lore raw
Quoted 23 lines · jovi zhang
Quoted 15 lines · Thiago Farina
Quoted 13 lines · On Sat, Dec 4, 2010 at 1:19 AM,  <[email protected]> wrote:

fix error handling path

 kernel/perf_event.c |    2 --

 1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -0
index cb6c0d2..62f9e9d 100644
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
        }
 
Quoted 6 lines

kernel/perf_event.c static int get_callchain_buffers(void) · line 1922

Quoted 3 lines
kernel/perf_event.c +0 -2
        err = alloc_callchain_buffers();
-       if (err)
-               release_callchain_buffers();

Care to explain in the change log message? As I reader, is not clear to me what is wrong with this.

Quoted 6 lines

Sorry, the description should be as:
fix error handling path. alloc_callchain_buffers() can return -ENOMEM, in this time callchain_cpus_entries maybe is NULL, It will oops if invoke release_callchain_buffers() when callchain_cpus_entries is NULL.

I hope my understanding is right, is it?

#4 lore raw
Quoted 24 lines · jovi zhang
Quoted 23 lines · jovi zhang
Quoted 21 lines · Thiago Farina
Quoted 11 lines · On Sat, Dec 4, 2010 at 1:19 AM,<[email protected]> wrote:

fix error handling path

  kernel/perf_event.c |    2 --
  1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -0
index cb6c0d2..62f9e9d 100644

kernel/perf_event.c static int get_callchain_buffers(void) · line 1922

Quoted 5 lines
kernel/perf_event.c +0 -2
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
        }
 
        err = alloc_callchain_buffers();
-       if (err)
-               release_callchain_buffers();

Care to explain in the change log message? As I reader, is not clear to me what is wrong with this.

Quoted 7 lines
Quoted 6 lines

Sorry, the description should be as:
fix error handling path. alloc_callchain_buffers() can return -ENOMEM, in this time callchain_cpus_entries maybe is NULL, It will oops if invoke release_callchain_buffers() when callchain_cpus_entries is NULL.

I hope my understanding is right, is it?

One possible problem here is what if it returns an error other than -ENOMEM, and the buffers do need to be released? Maybe you could change the code to

err = alloc_callchain_buffers();
if (err != -ENOMEM)

	release_callchain_buffers();

Currently, alloc_callchain_buffers cannot return any error code other than -ENOMEM, but that might change in the future.

- Corey

#5 lore raw
Quoted 37 lines · Corey Ashford
Quoted 24 lines · jovi zhang
Quoted 23 lines · jovi zhang
Quoted 21 lines · Thiago Farina
Quoted 11 lines · On Sat, Dec 4, 2010 at 1:19 AM,<[email protected]> wrote:

fix error handling path

  kernel/perf_event.c |    2 --
  1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -0
index cb6c0d2..62f9e9d 100644

kernel/perf_event.c static int get_callchain_buffers(void) · line 1922

Quoted 5 lines
kernel/perf_event.c +0 -2
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
        }
 
        err = alloc_callchain_buffers();
-       if (err)
-               release_callchain_buffers();

Care to explain in the change log message? As I reader, is not clear to me what is wrong with this.

Quoted 7 lines
Quoted 6 lines

Sorry, the description should be as:
fix error handling path. alloc_callchain_buffers() can return -ENOMEM, in this time callchain_cpus_entries maybe is NULL, It will oops if invoke release_callchain_buffers() when callchain_cpus_entries is NULL.

I hope my understanding is right, is it?

One possible problem here is what if it returns an error other than -ENOMEM, and the buffers do need to be released? Maybe you could change the code to

Quoted 7 lines

err = alloc_callchain_buffers();
if (err != -ENOMEM)

	release_callchain_buffers();

Currently, alloc_callchain_buffers cannot return any error code other than -ENOMEM, but that might change in the future.

The kernel convention is to fully clean up after yourself if you return an error. So in that sense the patch seems right.

Anyway, anybody care to post a new patch with slightly extended changelog?

author
#6 lore raw
Quoted 34 lines · Peter Zijlstra
Quoted 33 lines · Corey Ashford
Quoted 31 lines · jovi zhang
Quoted 23 lines · jovi zhang
Quoted 15 lines · Thiago Farina
Quoted 13 lines · On Sat, Dec 4, 2010 at 1:19 AM,<[email protected]>  wrote:

fix error handling path

  kernel/perf_event.c |    2 --

  1 files changed, 0 insertions(+), 2 deletions(-)
kernel/perf_event.c +0 -0
index cb6c0d2..62f9e9d 100644
@@ -1918,8 +1918,6 @@ static int get_callchain_buffers(void)
         }
 
Quoted 6 lines

kernel/perf_event.c static int get_callchain_buffers(void) · line 1922

Quoted 3 lines
kernel/perf_event.c +0 -2
         err = alloc_callchain_buffers();
-       if (err)
-               release_callchain_buffers();

Care to explain in the change log message? As I reader, is not clear to me what is wrong with this.

Quoted 6 lines

Sorry, the description should be as:
fix error handling path. alloc_callchain_buffers() can return -ENOMEM, in this time callchain_cpus_entries maybe is NULL, It will oops if invoke release_callchain_buffers() when callchain_cpus_entries is NULL.

I hope my understanding is right, is it?

Quoted 8 lines
Quoted 8 lines

One possible problem here is what if it returns an error other than -ENOMEM, and the buffers do need to be released?  Maybe you could change the code to

err = alloc_callchain_buffers();
if (err != -ENOMEM)
      release_callchain_buffers();

Thanks for you suggestion. I also thought it, but I think it should release the buffers in alloc_callchain_buffers if there have some error(like many other part of kernel code).

It's not a good way to trace return error code outside of alloc_callchain_buffer, if there have many return error code in future, maybe need to write code like this:
if(err && err != -ENOMEM && err != -EXXX ) ...

It's very ugly. is right?

Quoted 10 lines
Quoted 3 lines

Currently, alloc_callchain_buffers cannot return any error code other than -ENOMEM, but that might change in the future.

The kernel convention is to fully clean up after yourself if you return an error. So in that sense the patch seems right.

Anyway, anybody care to post a new patch with slightly extended changelog?