Skip to contentSkip to conversation

block: wrong return value

PATCH Superseded Sudip Mukherjee 2 participants 4 messages Oct 23, 2014 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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

 block/elevator.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/elevator.c +4 -2
index 24c28b6..1267c2b 100644
@@ -184,7 +184,7 @@ static void elevator_release(struct kobject *kobj)
 int elevator_init(struct request_queue *q, char *name)
 {
 	struct elevator_type *e = NULL;
-	int err;
+	int err = 0;
 
 	/*
 	 * q->sysfs_lock must be held to provide mutual exclusion between
@@ -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
#1 lore raw
Quoted 21 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.

---

change in v2: added elevator_put

 block/elevator.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/elevator.c +0 -0
index 24c28b6..1267c2b 100644

block/elevator.c static void elevator_release(struct kobject *kobj) · line 187

Quoted 5 lines
block/elevator.c +1 -1
@@ -184,7 +184,7 @@ static void elevator_release(struct kobject *kobj)
 int elevator_init(struct request_queue *q, char *name)
 {
 	struct elevator_type *e = NULL;
-	int err;
+	int err = 0;

Why init it to 0?

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 17 lines · Jens Axboe
Quoted 16 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.

---

change in v2: added elevator_put

 block/elevator.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 12 lines

block/elevator.c static void elevator_release(struct kobject *kobj) · line 187

Quoted 10 lines
block/elevator.c +1 -1
index 24c28b6..1267c2b 100644
@@ -184,7 +184,7 @@ static void elevator_release(struct kobject *kobj)
 int elevator_init(struct request_queue *q, char *name)
 {
 	struct elevator_type *e = NULL;
-	int err;
+	int err = 0;

Why init it to 0?

not required actually. my initial thinking was that we are returning 0 on success or else the error code. so gave it a default value of 0. but elevator_init_fn is returning 0 on success , so we will get 0 even if we do not initialize it.
should i resend after modifying it?

thanks
sudip

Quoted 4 lines
Signature · 2 lines
-- 
Jens Axboe
maintainer
#3 lore raw
Quoted 30 lines · Sudip Mukherjee
Quoted 17 lines · Jens Axboe
Quoted 16 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.

---

change in v2: added elevator_put

 block/elevator.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 12 lines

block/elevator.c static void elevator_release(struct kobject *kobj) · line 187

Quoted 10 lines
block/elevator.c +1 -1
index 24c28b6..1267c2b 100644
@@ -184,7 +184,7 @@ static void elevator_release(struct kobject *kobj)
 int elevator_init(struct request_queue *q, char *name)
 {
 	struct elevator_type *e = NULL;
-	int err;
+	int err = 0;

Why init it to 0?

Quoted 3 lines

not required actually. my initial thinking was that we are returning 0 on success or else the error code. so gave it a default value of 0. but elevator_init_fn is returning 0 on success , so we will get 0 even if we do not initialize it.
should i resend after modifying it?

Yes resend it please, the assignment is meaningless as it is overwritten later before being used.

Signature · 1 line
Jens Axboe