* [PATCH] kmemleak: Never return a pointer you didn't 'get'
@ 2011-04-21 11:39 Phil Carmody
2011-04-27 9:31 ` Catalin Marinas
0 siblings, 1 reply; 3+ messages in thread
From: Phil Carmody @ 2011-04-21 11:39 UTC (permalink / raw)
To: catalin.marinas; +Cc: linux-mm, linux-kernel, ext-phil.2.carmody
Old - If you don't get the last pointer that you looked at, then it will
still be put, as there's no way of knowing you didn't get it.
New - If you didn't get it, then it refers to something deleted, and
your work is done, so return NULL.
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
---
mm/kmemleak.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 8bf765c..3bf204d 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1350,17 +1350,21 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
struct kmemleak_object *prev_obj = v;
struct kmemleak_object *next_obj = NULL;
struct list_head *n = &prev_obj->object_list;
+ int found = 0;
++(*pos);
list_for_each_continue_rcu(n, &object_list) {
next_obj = list_entry(n, struct kmemleak_object, object_list);
- if (get_object(next_obj))
+ if (get_object(next_obj)) {
+ found = 1;
break;
+ }
}
put_object(prev_obj);
- return next_obj;
+
+ return found ? next_obj : NULL;
}
/*
--
1.7.2.rc1.37.gf8c40
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] kmemleak: Never return a pointer you didn't 'get'
2011-04-21 11:39 [PATCH] kmemleak: Never return a pointer you didn't 'get' Phil Carmody
@ 2011-04-27 9:31 ` Catalin Marinas
2011-04-27 10:11 ` Phil Carmody
0 siblings, 1 reply; 3+ messages in thread
From: Catalin Marinas @ 2011-04-27 9:31 UTC (permalink / raw)
To: Phil Carmody; +Cc: linux-mm, linux-kernel
On Thu, 2011-04-21 at 12:39 +0100, Phil Carmody wrote:
> Old - If you don't get the last pointer that you looked at, then it will
> still be put, as there's no way of knowing you didn't get it.
>
> New - If you didn't get it, then it refers to something deleted, and
> your work is done, so return NULL.
>
> Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Good catch. But I think the code may look slightly simpler as below:
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index c1d5867..aacee45 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1414,9 +1414,12 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
++(*pos);
list_for_each_continue_rcu(n, &object_list) {
- next_obj = list_entry(n, struct kmemleak_object, object_list);
- if (get_object(next_obj))
+ struct kmemleak_object *obj =
+ list_entry(n, struct kmemleak_object, object_list);
+ if (get_object(obj)) {
+ next_obj = obj;
break;
+ }
}
put_object(prev_obj);
Thanks.
--
Catalin
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] kmemleak: Never return a pointer you didn't 'get'
2011-04-27 9:31 ` Catalin Marinas
@ 2011-04-27 10:11 ` Phil Carmody
0 siblings, 0 replies; 3+ messages in thread
From: Phil Carmody @ 2011-04-27 10:11 UTC (permalink / raw)
To: ext Catalin Marinas; +Cc: linux-mm, linux-kernel
On 27/04/11 10:31 +0100, ext Catalin Marinas wrote:
> On Thu, 2011-04-21 at 12:39 +0100, Phil Carmody wrote:
> > Old - If you don't get the last pointer that you looked at, then it will
> > still be put, as there's no way of knowing you didn't get it.
> >
> > New - If you didn't get it, then it refers to something deleted, and
> > your work is done, so return NULL.
> >
> > Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
>
> Good catch. But I think the code may look slightly simpler as below:
>
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index c1d5867..aacee45 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1414,9 +1414,12 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> ++(*pos);
>
> list_for_each_continue_rcu(n, &object_list) {
> - next_obj = list_entry(n, struct kmemleak_object, object_list);
> - if (get_object(next_obj))
> + struct kmemleak_object *obj =
> + list_entry(n, struct kmemleak_object, object_list);
> + if (get_object(obj)) {
> + next_obj = obj;
> break;
> + }
> }
>
> put_object(prev_obj);
I did consider that way too, but had no strong preference. I think I now
prefer yours, so please add:
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Cheers,
Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-04-27 10:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-21 11:39 [PATCH] kmemleak: Never return a pointer you didn't 'get' Phil Carmody
2011-04-27 9:31 ` Catalin Marinas
2011-04-27 10:11 ` Phil Carmody
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).