public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] block: wrong return value
@ 2014-10-23 16:04 Sudip Mukherjee
  2014-10-23 16:09 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Sudip Mukherjee @ 2014-10-23 16:04 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Sudip Mukherjee, linux-kernel

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.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---

change in v2: added elevator_put

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

diff --git a/block/elevator.c b/block/elevator.c
index 24c28b6..1267c2b 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -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);
 
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] block: wrong return value
  2014-10-23 16:04 [PATCH v2] block: wrong return value Sudip Mukherjee
@ 2014-10-23 16:09 ` Jens Axboe
  2014-10-23 16:28   ` Sudip Mukherjee
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2014-10-23 16:09 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: linux-kernel

On 10/23/2014 10:04 AM, Sudip Mukherjee wrote:
> 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.
> 
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
> 
> change in v2: added elevator_put
> 
>  block/elevator.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/block/elevator.c b/block/elevator.c
> index 24c28b6..1267c2b 100644
> --- a/block/elevator.c
> +++ b/block/elevator.c
> @@ -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?

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] block: wrong return value
  2014-10-23 16:09 ` Jens Axboe
@ 2014-10-23 16:28   ` Sudip Mukherjee
  2014-10-23 16:30     ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Sudip Mukherjee @ 2014-10-23 16:28 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

On Thu, Oct 23, 2014 at 10:09:36AM -0600, Jens Axboe wrote:
> On 10/23/2014 10:04 AM, Sudip Mukherjee wrote:
> > 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.
> > 
> > Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> > ---
> > 
> > change in v2: added elevator_put
> > 
> >  block/elevator.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/block/elevator.c b/block/elevator.c
> > index 24c28b6..1267c2b 100644
> > --- a/block/elevator.c
> > +++ b/block/elevator.c
> > @@ -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
> 
> -- 
> Jens Axboe
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] block: wrong return value
  2014-10-23 16:28   ` Sudip Mukherjee
@ 2014-10-23 16:30     ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2014-10-23 16:30 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: linux-kernel

On 10/23/2014 10:28 AM, Sudip Mukherjee wrote:
> On Thu, Oct 23, 2014 at 10:09:36AM -0600, Jens Axboe wrote:
>> On 10/23/2014 10:04 AM, Sudip Mukherjee wrote:
>>> 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.
>>>
>>> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
>>> ---
>>>
>>> change in v2: added elevator_put
>>>
>>>  block/elevator.c | 6 ++++--
>>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/block/elevator.c b/block/elevator.c
>>> index 24c28b6..1267c2b 100644
>>> --- a/block/elevator.c
>>> +++ b/block/elevator.c
>>> @@ -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?

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

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-23 16:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-23 16:04 [PATCH v2] block: wrong return value Sudip Mukherjee
2014-10-23 16:09 ` Jens Axboe
2014-10-23 16:28   ` Sudip Mukherjee
2014-10-23 16:30     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox