All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libceph: fix a memory leak in handle_watch_notify
@ 2014-09-11  0:20 roy.qing.li
  2014-09-11  1:41 ` Alex Elder
  0 siblings, 1 reply; 5+ messages in thread
From: roy.qing.li @ 2014-09-11  0:20 UTC (permalink / raw)
  To: sage, ceph-devel

From: Li RongQing <roy.qing.li@gmail.com> 

event_work should be freed when adding it to queue failed

Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
---
 net/ceph/osd_client.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 30f6faf..1e1b4f1 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -2323,6 +2323,7 @@ static void handle_watch_notify(struct ceph_osd_client *osdc,
 		event_work->opcode = opcode;
 		if (!queue_work(osdc->notify_wq, &event_work->work)) {
 			dout("WARNING: failed to queue notify event work\n");
+			kfree(event_work);
 			goto done_err;
 		}
 	}
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] libceph: fix a memory leak in handle_watch_notify
  2014-09-11  0:20 [PATCH] libceph: fix a memory leak in handle_watch_notify roy.qing.li
@ 2014-09-11  1:41 ` Alex Elder
  2014-09-11  8:31   ` Ilya Dryomov
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Elder @ 2014-09-11  1:41 UTC (permalink / raw)
  To: roy.qing.li, sage, ceph-devel

On 09/10/2014 07:20 PM, roy.qing.li@gmail.com wrote:
> From: Li RongQing <roy.qing.li@gmail.com>
>
> event_work should be freed when adding it to queue failed
>
> Signed-off-by: Li RongQing <roy.qing.li@gmail.com>

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>

> ---
>   net/ceph/osd_client.c |    1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
> index 30f6faf..1e1b4f1 100644
> --- a/net/ceph/osd_client.c
> +++ b/net/ceph/osd_client.c
> @@ -2323,6 +2323,7 @@ static void handle_watch_notify(struct ceph_osd_client *osdc,
>   		event_work->opcode = opcode;
>   		if (!queue_work(osdc->notify_wq, &event_work->work)) {
>   			dout("WARNING: failed to queue notify event work\n");
> +			kfree(event_work);
>   			goto done_err;
>   		}
>   	}
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libceph: fix a memory leak in handle_watch_notify
  2014-09-11  1:41 ` Alex Elder
@ 2014-09-11  8:31   ` Ilya Dryomov
  2014-09-11 10:50     ` Alex Elder
  0 siblings, 1 reply; 5+ messages in thread
From: Ilya Dryomov @ 2014-09-11  8:31 UTC (permalink / raw)
  To: Alex Elder; +Cc: roy.qing.li, Sage Weil, Ceph Development

On Thu, Sep 11, 2014 at 5:41 AM, Alex Elder <elder@ieee.org> wrote:
> On 09/10/2014 07:20 PM, roy.qing.li@gmail.com wrote:
>>
>> From: Li RongQing <roy.qing.li@gmail.com>
>>
>> event_work should be freed when adding it to queue failed
>>
>> Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
>
>
> Looks good.
>
> Reviewed-by: Alex Elder <elder@linaro.org>

Hmm, queue_work() returns %false if @work was already on a queue, %true
otherwise, so this seems bogus to me.  I'd go with something like this
(mangled).

From c0711eee447b199b1c2193460fce8c9d958f23f4 Mon Sep 17 00:00:00 2001
From: Ilya Dryomov <ilya.dryomov@inktank.com>
Date: Thu, 11 Sep 2014 12:18:53 +0400
Subject: [PATCH] libceph: don't try checking queue_work() return value

queue_work() doesn't "fail to queue", it returns false if work was
already on a queue, which can't happen here since we allocate
event_work right before we queue it.  So don't bother at all.

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
---
 net/ceph/osd_client.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 0f569d322405..952e9c254cc7 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -2355,26 +2355,21 @@ static void handle_watch_notify(struct
ceph_osd_client *osdc,
        if (event) {
                event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
                if (!event_work) {
-                       dout("ERROR: could not allocate event_work\n");
-                       goto done_err;
+                       pr_err("couldn't allocate event_work\n");
+                       ceph_osdc_put_event(event);
+                       return;
                }
                INIT_WORK(&event_work->work, do_event_work);
                event_work->event = event;
                event_work->ver = ver;
                event_work->notify_id = notify_id;
                event_work->opcode = opcode;
-               if (!queue_work(osdc->notify_wq, &event_work->work)) {
-                       dout("WARNING: failed to queue notify event work\n");
-                       goto done_err;
-               }
+
+               queue_work(osdc->notify_wq, &event_work->work);
        }

        return;

-done_err:
-       ceph_osdc_put_event(event);
-       return;
-
 bad:
        pr_err("osdc handle_watch_notify corrupt msg\n");
 }
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] libceph: fix a memory leak in handle_watch_notify
  2014-09-11  8:31   ` Ilya Dryomov
@ 2014-09-11 10:50     ` Alex Elder
  2014-09-11 11:11       ` Ilya Dryomov
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Elder @ 2014-09-11 10:50 UTC (permalink / raw)
  To: Ilya Dryomov; +Cc: roy.qing.li, Sage Weil, Ceph Development

On 09/11/2014 03:31 AM, Ilya Dryomov wrote:
> On Thu, Sep 11, 2014 at 5:41 AM, Alex Elder <elder@ieee.org> wrote:
>> On 09/10/2014 07:20 PM, roy.qing.li@gmail.com wrote:
>>>
>>> From: Li RongQing <roy.qing.li@gmail.com>
>>>
>>> event_work should be freed when adding it to queue failed
>>>
>>> Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
>>
>>
>> Looks good.
>>
>> Reviewed-by: Alex Elder <elder@linaro.org>
>
> Hmm, queue_work() returns %false if @work was already on a queue, %true
> otherwise, so this seems bogus to me.  I'd go with something like this
> (mangled).

The original change was fine.  Whether it matters is another question.
Your suggestion looks good as well, and on the assumption that if you
choose to use it instead your "real" fix is done correctly you can
use "Reviewed-by: <me>" if you like.

					-Alex

>
>  From c0711eee447b199b1c2193460fce8c9d958f23f4 Mon Sep 17 00:00:00 2001
> From: Ilya Dryomov <ilya.dryomov@inktank.com>
> Date: Thu, 11 Sep 2014 12:18:53 +0400
> Subject: [PATCH] libceph: don't try checking queue_work() return value
>
> queue_work() doesn't "fail to queue", it returns false if work was
> already on a queue, which can't happen here since we allocate
> event_work right before we queue it.  So don't bother at all.
>
> Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
> ---
>   net/ceph/osd_client.c |   15 +++++----------
>   1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
> index 0f569d322405..952e9c254cc7 100644
> --- a/net/ceph/osd_client.c
> +++ b/net/ceph/osd_client.c
> @@ -2355,26 +2355,21 @@ static void handle_watch_notify(struct
> ceph_osd_client *osdc,
>          if (event) {
>                  event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
>                  if (!event_work) {
> -                       dout("ERROR: could not allocate event_work\n");
> -                       goto done_err;
> +                       pr_err("couldn't allocate event_work\n");
> +                       ceph_osdc_put_event(event);
> +                       return;
>                  }
>                  INIT_WORK(&event_work->work, do_event_work);
>                  event_work->event = event;
>                  event_work->ver = ver;
>                  event_work->notify_id = notify_id;
>                  event_work->opcode = opcode;
> -               if (!queue_work(osdc->notify_wq, &event_work->work)) {
> -                       dout("WARNING: failed to queue notify event work\n");
> -                       goto done_err;
> -               }
> +
> +               queue_work(osdc->notify_wq, &event_work->work);
>          }
>
>          return;
>
> -done_err:
> -       ceph_osdc_put_event(event);
> -       return;
> -
>   bad:
>          pr_err("osdc handle_watch_notify corrupt msg\n");
>   }
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libceph: fix a memory leak in handle_watch_notify
  2014-09-11 10:50     ` Alex Elder
@ 2014-09-11 11:11       ` Ilya Dryomov
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Dryomov @ 2014-09-11 11:11 UTC (permalink / raw)
  To: Alex Elder; +Cc: roy.qing.li, Sage Weil, Ceph Development

On Thu, Sep 11, 2014 at 2:50 PM, Alex Elder <elder@ieee.org> wrote:
> On 09/11/2014 03:31 AM, Ilya Dryomov wrote:
>>
>> On Thu, Sep 11, 2014 at 5:41 AM, Alex Elder <elder@ieee.org> wrote:
>>>
>>> On 09/10/2014 07:20 PM, roy.qing.li@gmail.com wrote:
>>>>
>>>>
>>>> From: Li RongQing <roy.qing.li@gmail.com>
>>>>
>>>> event_work should be freed when adding it to queue failed
>>>>
>>>> Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
>>>
>>>
>>>
>>> Looks good.
>>>
>>> Reviewed-by: Alex Elder <elder@linaro.org>
>>
>>
>> Hmm, queue_work() returns %false if @work was already on a queue, %true
>> otherwise, so this seems bogus to me.  I'd go with something like this
>> (mangled).
>
>
> The original change was fine.  Whether it matters is another question.
> Your suggestion looks good as well, and on the assumption that if you
> choose to use it instead your "real" fix is done correctly you can
> use "Reviewed-by: <me>" if you like.

Well, the original change makes something bogus even more bogus.  It's
basically:

    foo = kmalloc(...);
    foo->bar = 0;

    if (foo->bar & BAZ) {
        /* WARNING */
        kfree(foo);
        goto ...
    }

So yeah, I'm going to use your Reviewed-by on my "real" fix ;)

Thanks,

                Ilya

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-09-11 11:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11  0:20 [PATCH] libceph: fix a memory leak in handle_watch_notify roy.qing.li
2014-09-11  1:41 ` Alex Elder
2014-09-11  8:31   ` Ilya Dryomov
2014-09-11 10:50     ` Alex Elder
2014-09-11 11:11       ` Ilya Dryomov

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.