Skip to contentSkip to conversation

elevator: fix double release for elevator module

PATCH In review Chao Yu 3 participants 4 messages Apr 23, 2015 – Apr 24, 2015 Block layer

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 elevator: fix double release for elevator module

Our issue is descripted in below call path:
->elevator_init
->elevator_init_fn
->{cfq,deadline,noop}_init_queue
->elevator_alloc

    ->kzalloc_node

fail to call kzalloc_node and then put module in elevator_alloc;
fail to call elevator_init_fn and then put module again in elevator_init.

Remove elevator_put invoking in error path of elevator_alloc to avoid double release issue.

---
 block/elevator.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/elevator.c +1 -4
index d146a5e..8985038 100644
@@ -157,7 +157,7 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
 
 	eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node);
 	if (unlikely(!eq))
-		goto err;
+		return NULL;
 
 	eq->type = e;
 	kobject_init(&eq->kobj, &elv_ktype);
@@ -165,9 +165,6 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
 	hash_init(eq->hash);
 
 	return eq;
-err:
-	elevator_put(e);
-	return NULL;
 }
 EXPORT_SYMBOL(elevator_alloc);
 
Signature · 1 line
2.3.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Chao Yu

Our issue is descripted in below call path:
->elevator_init
->elevator_init_fn
->{cfq,deadline,noop}_init_queue
->elevator_alloc

    ->kzalloc_node

fail to call kzalloc_node and then put module in elevator_alloc;
fail to call elevator_init_fn and then put module again in elevator_init.

Remove elevator_put invoking in error path of elevator_alloc to avoid double release issue.

---
 block/elevator.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/elevator.c +1 -1
index d146a5e..8985038 100644
@@ -157,7 +157,7 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
 
 	eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node);
 	if (unlikely(!eq))
-		goto err;
+		return NULL;
 
 	eq->type = e;
 	kobject_init(&eq->kobj, &elv_ktype);

block/elevator.c struct elevator_queue *elevator_alloc(struct request_queue *q, · line 169

Quoted 8 lines
block/elevator.c +0 -3
@@ -165,9 +165,6 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
 	hash_init(eq->hash);
 
 	return eq;
-err:
-	elevator_put(e);
-	return NULL;
 }
 EXPORT_SYMBOL(elevator_alloc);

You could have posted the two patches together, as they are related. Anyway, looks good to me.

maintainer
#2 lore raw
Quoted 45 lines · Jeff Moyer
Quoted 31 lines · Chao Yu

Our issue is descripted in below call path:
->elevator_init
->elevator_init_fn
->{cfq,deadline,noop}_init_queue

    ->elevator_alloc
     ->kzalloc_node
    fail to call kzalloc_node and then put module in elevator_alloc;

fail to call elevator_init_fn and then put module again in elevator_init.

Remove elevator_put invoking in error path of elevator_alloc to avoid double release issue.

---
  block/elevator.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
block/elevator.c +1 -1
index d146a5e..8985038 100644
@@ -157,7 +157,7 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
 
  	eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node);
  	if (unlikely(!eq))
-		goto err;
+		return NULL;
 
  	eq->type = e;
  	kobject_init(&eq->kobj, &elv_ktype);

block/elevator.c struct elevator_queue *elevator_alloc(struct request_queue *q, · line 169

Quoted 8 lines
block/elevator.c +0 -3
@@ -165,9 +165,6 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
  	hash_init(eq->hash);
 
  	return eq;
-err:
-	elevator_put(e);
-	return NULL;
  }
  EXPORT_SYMBOL(elevator_alloc);

You could have posted the two patches together, as they are related. Anyway, looks good to me.

Quoted 1 line

Agree, it should be one patch. I've combined them, and applied the fix for 4.1. Thanks.

Signature · 1 line
Jens Axboe
author
#3 lore raw

Hi Jens and Jeff,

Thanks for your review and help! :)

Regards,

Quoted 60 lines

-----Original Message-----
From: Jens Axboe [mailto:[email protected]]
Sent: Friday, April 24, 2015 12:49 AM
To: Jeff Moyer; Chao Yu
Cc: [email protected]
Subject: Re: [PATCH] elevator: fix double release for elevator module

Quoted 45 lines · Jeff Moyer
Quoted 31 lines · Chao Yu

Our issue is descripted in below call path:
->elevator_init
->elevator_init_fn
->{cfq,deadline,noop}_init_queue

    ->elevator_alloc
     ->kzalloc_node
    fail to call kzalloc_node and then put module in elevator_alloc;

fail to call elevator_init_fn and then put module again in elevator_init.

Remove elevator_put invoking in error path of elevator_alloc to avoid double release issue.

---
  block/elevator.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
block/elevator.c +1 -1
index d146a5e..8985038 100644
@@ -157,7 +157,7 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
 
  	eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node);
  	if (unlikely(!eq))
-		goto err;
+		return NULL;
 
  	eq->type = e;
  	kobject_init(&eq->kobj, &elv_ktype);

block/elevator.c struct elevator_queue *elevator_alloc(struct request_queue *q, · line 169

Quoted 8 lines
block/elevator.c +0 -3
@@ -165,9 +165,6 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
  	hash_init(eq->hash);
 
  	return eq;
-err:
-	elevator_put(e);
-	return NULL;
  }
  EXPORT_SYMBOL(elevator_alloc);

You could have posted the two patches together, as they are related. Anyway, looks good to me.

Quoted 1 line

Agree, it should be one patch. I've combined them, and applied the fix for 4.1. Thanks.

--
Jens Axboe