Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752686AbbD0FbK (ORCPT ); Mon, 27 Apr 2015 01:31:10 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:36702 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751748AbbD0FbG (ORCPT ); Mon, 27 Apr 2015 01:31:06 -0400 X-AuditID: cbfee61b-f79536d000000f1f-83-553dc998125f From: Chao Yu To: axboe@kernel.dk, "'Jeff Moyer'" Cc: linux-kernel@vger.kernel.org References: In-reply-to: Subject: RE: [PATCH] elevator: fix memory leak in ->elevator_init_fn Date: Mon, 27 Apr 2015 13:30:22 +0800 Message-id: <017601d080ab$597eceb0$0c7c6c10$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdB+Mue1NVGAX0ULTlKtBubljw7vfwCdoY8Q Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRmVeSWpSXmKPExsVy+t9jQd0ZJ21DDR5MFLVYfbefzeLsr6ss Fpd3zWFzYPa4fLbU4/2+q2wenzfJBTBHcdmkpOZklqUW6dslcGVs3XaOuWCBUMWjX3/ZGxgf 8XUxcnJICJhIdG+ZygJhi0lcuLeerYuRi0NIYDqjxInX+xghnFeMEvP+/WMHqWITUJFY3vGf CcQWETCVmNx9BKybWUBB4te9TaxdjBxADdwSq5uDQMKcAjwS6/50MoPYwgIuEutWLgdrZRFQ leh4+QUszitgKfFv51EWCFtQ4sfke1AjtSTW7zzOBGHLS2xe85YZ4lAFiR1nXzNCnGAk0bRp ETNEjbjExiO3WCYwCs1CMmoWklGzkIyahaRlASPLKkbR1ILkguKk9FwjveLE3OLSvHS95Pzc TYzgcH8mvYNxVYPFIUYBDkYlHl6JibahQqyJZcWVuYcYJTiYlUR4jXYDhXhTEiurUovy44tK c1KLDzFKc7AoifPO0ZULFRJITyxJzU5NLUgtgskycXBKNTA6WD+Z1/7DRuF2lrKId/AJ7VVX M4uqDrt91/loOfvK8tdcG4L2JEq1tbNY7wv+IFhYuObTpOvTvjv9vVVsojVf9kb44nML7rR8 SHl4pfrr/a2pG/t4E5NCS87uExUpU33w95V+SFdZggO3nUOrcVl5ocdz1obl+q6Pvq+6zMly cnbChE8NuxYpsRRnJBpqMRcVJwIA6zMbEHMCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2510 Lines: 76 Hi all, I found that when we release eq->kobj by invoking kobject_put() we had gave misson to workqueue, so that workqueue will release the elevator queue space in elevator_alloc() which is registered in ->release of elv_ktype object. We should not release it again. So, this fix is wrong, please ignore this patch, sorry for the noisy! Regards, > -----Original Message----- > From: Chao Yu [mailto:chao2.yu@samsung.com] > Sent: Friday, April 24, 2015 10:09 AM > To: 'axboe@kernel.dk' > Cc: 'linux-kernel@vger.kernel.org' > Subject: [PATCH] elevator: fix memory leak in ->elevator_init_fn > > In ->elevator_init_fn, if we fail to call kzalloc_node, we should release > elevator queue space which is allocated previously, otherwise it will cause > memory leak. > > Signed-off-by: Chao Yu > --- > block/cfq-iosched.c | 1 + > block/deadline-iosched.c | 1 + > block/noop-iosched.c | 1 + > 3 files changed, 3 insertions(+) > > diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c > index 5da8e6e..2793fb7 100644 > --- a/block/cfq-iosched.c > +++ b/block/cfq-iosched.c > @@ -4391,6 +4391,7 @@ static int cfq_init_queue(struct request_queue *q, struct elevator_type > *e) > cfqd = kzalloc_node(sizeof(*cfqd), GFP_KERNEL, q->node); > if (!cfqd) { > kobject_put(&eq->kobj); > + kfree(eq); > return -ENOMEM; > } > eq->elevator_data = cfqd; > diff --git a/block/deadline-iosched.c b/block/deadline-iosched.c > index a753df2..bc6d7d9 100644 > --- a/block/deadline-iosched.c > +++ b/block/deadline-iosched.c > @@ -349,6 +349,7 @@ static int deadline_init_queue(struct request_queue *q, struct elevator_type > *e) > dd = kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node); > if (!dd) { > kobject_put(&eq->kobj); > + kfree(eq); > return -ENOMEM; > } > eq->elevator_data = dd; > diff --git a/block/noop-iosched.c b/block/noop-iosched.c > index 3de89d4..1399c78 100644 > --- a/block/noop-iosched.c > +++ b/block/noop-iosched.c > @@ -71,6 +71,7 @@ static int noop_init_queue(struct request_queue *q, struct elevator_type *e) > nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node); > if (!nd) { > kobject_put(&eq->kobj); > + kfree(eq); > return -ENOMEM; > } > eq->elevator_data = nd; > -- > 2.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/