* [PATCH] Free memory when create_device is failed
@ 2010-01-11 7:15 Minchan Kim
2010-01-11 8:23 ` Nitin Gupta
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Minchan Kim @ 2010-01-11 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Nitin Gupta, linux-mm
Hi, Greg.
I don't know where I send this patch.
Do I send this patch to akpm or only you and LKML?
== CUT HERE ==
If create_device is failed, it can't free gendisk and request_queue
of preceding devices. It cause memory leak.
This patch fixes it.
Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
CC: Nitin Gupta <ngupta@vflare.org>
---
drivers/staging/ramzswap/ramzswap_drv.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c
index 18196f3..faa412d 100644
--- a/drivers/staging/ramzswap/ramzswap_drv.c
+++ b/drivers/staging/ramzswap/ramzswap_drv.c
@@ -1292,7 +1292,7 @@ static struct block_device_operations ramzswap_devops = {
.owner = THIS_MODULE,
};
-static void create_device(struct ramzswap *rzs, int device_id)
+static int create_device(struct ramzswap *rzs, int device_id)
{
mutex_init(&rzs->lock);
INIT_LIST_HEAD(&rzs->backing_swap_extent_list);
@@ -1301,7 +1301,7 @@ static void create_device(struct ramzswap *rzs, int device_id)
if (!rzs->queue) {
pr_err("Error allocating disk queue for device %d\n",
device_id);
- return;
+ return 0;
}
blk_queue_make_request(rzs->queue, ramzswap_make_request);
@@ -1313,7 +1313,7 @@ static void create_device(struct ramzswap *rzs, int device_id)
blk_cleanup_queue(rzs->queue);
pr_warning("Error allocating disk structure for device %d\n",
device_id);
- return;
+ return 0;
}
rzs->disk->major = ramzswap_major;
@@ -1331,6 +1331,7 @@ static void create_device(struct ramzswap *rzs, int device_id)
add_disk(rzs->disk);
rzs->init_done = 0;
+ return 1;
}
static void destroy_device(struct ramzswap *rzs)
@@ -1368,16 +1369,20 @@ static int __init ramzswap_init(void)
/* Allocate the device array and initialize each one */
pr_info("Creating %u devices ...\n", num_devices);
devices = kzalloc(num_devices * sizeof(struct ramzswap), GFP_KERNEL);
- if (!devices) {
- ret = -ENOMEM;
+ if (!devices)
goto out;
- }
for (i = 0; i < num_devices; i++)
- create_device(&devices[i], i);
-
+ if (!create_device(&devices[i], i)) {
+ ret = i;
+ goto free_devices;
+ }
return 0;
+free_devices:
+ for (i = 0; i < ret; i++)
+ destroy_device(&devices[i]);
out:
+ ret = -ENOMEM;
unregister_blkdev(ramzswap_major, "ramzswap");
return ret;
}
--
1.5.6.3
--
Kind regards,
Minchan Kim
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Free memory when create_device is failed
2010-01-11 7:15 [PATCH] Free memory when create_device is failed Minchan Kim
@ 2010-01-11 8:23 ` Nitin Gupta
2010-01-11 8:31 ` Minchan Kim
2010-01-11 15:20 ` Greg KH
2010-01-15 1:36 ` patch staging-ramzswap-free-memory-when-create_device-is-failed.patch added to gregkh-2.6 tree gregkh
2 siblings, 1 reply; 5+ messages in thread
From: Nitin Gupta @ 2010-01-11 8:23 UTC (permalink / raw)
To: Minchan Kim; +Cc: Greg Kroah-Hartman, linux-mm
Hi Minchan,
On Mon, Jan 11, 2010 at 12:45 PM, Minchan Kim <minchan.kim@gmail.com> wrote:
>
>
> I don't know where I send this patch.
> Do I send this patch to akpm or only you and LKML?
>
I think current TO, CC list is okay for this driver.
>
> If create_device is failed, it can't free gendisk and request_queue
> of preceding devices. It cause memory leak.
>
> This patch fixes it.
>
> Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
> CC: Nitin Gupta <ngupta@vflare.org>
FWIW,
Acked-by: Nitin Gupta <ngupta@vflare.org>
Thanks for the fix.
Nitin
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Free memory when create_device is failed
2010-01-11 8:23 ` Nitin Gupta
@ 2010-01-11 8:31 ` Minchan Kim
0 siblings, 0 replies; 5+ messages in thread
From: Minchan Kim @ 2010-01-11 8:31 UTC (permalink / raw)
To: Nitin Gupta; +Cc: Greg Kroah-Hartman, linux-mm
On Mon, Jan 11, 2010 at 5:23 PM, Nitin Gupta <ngupta@vflare.org> wrote:
> Hi Minchan,
>
> On Mon, Jan 11, 2010 at 12:45 PM, Minchan Kim <minchan.kim@gmail.com> wrote:
>>
>>
>> I don't know where I send this patch.
>> Do I send this patch to akpm or only you and LKML?
>>
>
> I think current TO, CC list is okay for this driver.
>
>>
>> If create_device is failed, it can't free gendisk and request_queue
>> of preceding devices. It cause memory leak.
>>
>> This patch fixes it.
>>
>> Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
>> CC: Nitin Gupta <ngupta@vflare.org>
>
>
> FWIW,
> Acked-by: Nitin Gupta <ngupta@vflare.org>
Thanks for the ACK, Nitin. :)
--
Kind regards,
Minchan Kim
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Free memory when create_device is failed
2010-01-11 7:15 [PATCH] Free memory when create_device is failed Minchan Kim
2010-01-11 8:23 ` Nitin Gupta
@ 2010-01-11 15:20 ` Greg KH
2010-01-15 1:36 ` patch staging-ramzswap-free-memory-when-create_device-is-failed.patch added to gregkh-2.6 tree gregkh
2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2010-01-11 15:20 UTC (permalink / raw)
To: Minchan Kim; +Cc: Nitin Gupta, linux-mm
On Mon, Jan 11, 2010 at 04:15:53PM +0900, Minchan Kim wrote:
>
> Hi, Greg.
>
> I don't know where I send this patch.
> Do I send this patch to akpm or only you and LKML?
Look at the drivers/staging/ramzswap/TODO file, and also use the
scripts/get_maintainer.pl script to determine the correct people and
mailing lists to send patches to in the future.
I'll queue this up later this week.
thanks,
greg k-h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* patch staging-ramzswap-free-memory-when-create_device-is-failed.patch added to gregkh-2.6 tree
2010-01-11 7:15 [PATCH] Free memory when create_device is failed Minchan Kim
2010-01-11 8:23 ` Nitin Gupta
2010-01-11 15:20 ` Greg KH
@ 2010-01-15 1:36 ` gregkh
2 siblings, 0 replies; 5+ messages in thread
From: gregkh @ 2010-01-15 1:36 UTC (permalink / raw)
To: minchan.kim, gregkh, greg, linux-mm, ngupta
This is a note to let you know that I've just added the patch titled
Subject: Staging: ramzswap: Free memory when create_device is failed
to my gregkh-2.6 tree. Its filename is
staging-ramzswap-free-memory-when-create_device-is-failed.patch
This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-01-15 1:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-11 7:15 [PATCH] Free memory when create_device is failed Minchan Kim
2010-01-11 8:23 ` Nitin Gupta
2010-01-11 8:31 ` Minchan Kim
2010-01-11 15:20 ` Greg KH
2010-01-15 1:36 ` patch staging-ramzswap-free-memory-when-create_device-is-failed.patch added to gregkh-2.6 tree gregkh
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).