Re: + zram-fix-error-return-code.patch added to -mm tree

From: Sergey Senozhatsky
Date: Mon Apr 06 2015 - 21:56:50 EST


On (04/06/15 12:43), akpm@xxxxxxxxxxxxxxxxxxxx wrote:
> From: Julia Lawall <Julia.Lawall@xxxxxxx>
> Subject: zram: fix error return code
>
> Return a negative error code on failure.
>
[..]
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> Signed-off-by: Julia Lawall <Julia.Lawall@xxxxxxx>
> Cc: Minchan Kim <minchan@xxxxxxxxxx>
> Cc: Nitin Gupta <ngupta@xxxxxxxxxx>
> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> ---

good catch.
Acked-by: Sergey Senozhatsky <sergey.senozhatsky.work@xxxxxxxxx>

> drivers/block/zram/zram_drv.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff -puN drivers/block/zram/zram_drv.c~zram-fix-error-return-code drivers/block/zram/zram_drv.c
> --- a/drivers/block/zram/zram_drv.c~zram-fix-error-return-code
> +++ a/drivers/block/zram/zram_drv.c
> @@ -1188,6 +1188,7 @@ static int zram_add(int device_id)
> if (!queue) {
> pr_err("Error allocating disk queue for device %d\n",
> device_id);
> + ret = -ENOMEM;
> goto out_free_idr;
> }
>
> @@ -1198,6 +1199,7 @@ static int zram_add(int device_id)
> if (!zram->disk) {
> pr_warn("Error allocating disk structure for device %d\n",
> device_id);
> + ret = -ENOMEM;
> goto out_free_queue;
> }

I think we can drop the default `ret' value and just return explicit `-ENOMEM' in
!zram case.

---
drivers/block/zram/zram_drv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index fe67ebb..f444c15 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1164,11 +1164,11 @@ static int zram_add(int device_id)
{
struct zram *zram;
struct request_queue *queue;
- int ret = -ENOMEM;
+ int ret;

zram = kzalloc(sizeof(struct zram), GFP_KERNEL);
if (!zram)
- return ret;
+ return -ENOMEM;

if (device_id < 0) {
/* generate new device_id */
--
2.4.0.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/