Skip to contentSkip to conversation

block: wrong return value

PATCH In review Sudip Mukherjee 2 participants 3 messages Oct 23, 2014 – Oct 28, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 block: wrong return value

while compiling integer err was showing as a set but unused variable. elevator_init_fn can be either cfq_init_queue or deadline_init_queue or noop_init_queue.
all three of these functions are returning -ENOMEM if they fail to allocate the queue.
so we should actually be returning the error code rather than returning 0 always.

---

change in v2: added elevator_put
change in v3: remove unneeded initialization of err

 block/elevator.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/elevator.c +3 -1
index 24c28b6..afa3b03 100644
@@ -229,7 +229,9 @@ int elevator_init(struct request_queue *q, char *name)
 	}
 
 	err = e->ops.elevator_init_fn(q, e);
-	return 0;
+	if (err)
+		elevator_put(e);
+	return err;
 }
 EXPORT_SYMBOL(elevator_init);
 
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 7 lines · Sudip Mukherjee

while compiling integer err was showing as a set but unused variable. elevator_init_fn can be either cfq_init_queue or deadline_init_queue or noop_init_queue.
all three of these functions are returning -ENOMEM if they fail to allocate the queue.
so we should actually be returning the error code rather than returning 0 always.

i have one doubt. shouldn't this patch be marked for stable also?

thanks
sudip

Quoted 28 lines

---

change in v2: added elevator_put
change in v3: remove unneeded initialization of err

 block/elevator.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/elevator.c +3 -1
index 24c28b6..afa3b03 100644
@@ -229,7 +229,9 @@ int elevator_init(struct request_queue *q, char *name)
 	}
 
 	err = e->ops.elevator_init_fn(q, e);
-	return 0;
+	if (err)
+		elevator_put(e);
+	return err;
 }
 EXPORT_SYMBOL(elevator_init);
 
Signature · 1 line
1.8.1.2
maintainer
#2 lore raw
Quoted 9 lines · Sudip Mukherjee
Quoted 7 lines · Sudip Mukherjee

while compiling integer err was showing as a set but unused variable. elevator_init_fn can be either cfq_init_queue or deadline_init_queue or noop_init_queue.
all three of these functions are returning -ENOMEM if they fail to allocate the queue.
so we should actually be returning the error code rather than returning 0 always.

i have one doubt. shouldn't this patch be marked for stable also?

It would not hurt to mark it as stable, but on the other hand, this probably never triggered a problem for anyone. So it's not a critical fix by any stretch.

Signature · 1 line
Jens Axboe