public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Nicholas Krause <xerofoify@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block:Add proper error checking to genhd.c for the function,add_disk
Date: Tue, 10 Feb 2015 14:04:51 -0700	[thread overview]
Message-ID: <54DA7273.40100@kernel.dk> (raw)
In-Reply-To: <1423531337-27297-1-git-send-email-xerofoify@gmail.com>

On 02/09/2015 06:22 PM, Nicholas Krause wrote:
> Adds error handling to the function add_disk. Error checking is
> added by removing the calls to WARN_ON when there is a failure in
> various places in the function to proper return statements with
> a error code. Further more due to this we must also add a statement
> to return 0 at the end of the function to signal success to the
> caller of the function to notify it that the function,add_disk has
> succeeded and change the function's return type to a int now to
> allow returning of error codes  for the function,add_disk to be
> allowed.

There's a lot wrong with this still:

> @@ -595,10 +594,9 @@ void add_disk(struct gendisk *disk)
>   	disk->flags |= GENHD_FL_UP;
>
>   	retval = blk_alloc_devt(&disk->part0, &devt);
> -	if (retval) {
> -		WARN_ON(1);
> -		return;
> -	}
> +	if (retval)
> +		return -ENOMEM;

Why isn't that returning retval?

> +
>   	disk_to_dev(disk)->devt = devt;
>
>   	/* ->major and ->first_minor aren't supposed to be
> @@ -622,13 +620,16 @@ void add_disk(struct gendisk *disk)
>   	 * Take an extra ref on queue which will be put on disk_release()
>   	 * so that it sticks around as long as @disk is there.
>   	 */
> -	WARN_ON_ONCE(!blk_get_queue(disk->queue));
> +	if (!blk_get_queue(disk->queue))
> +		return -ENODEV;

You just leaked the devt alloc.

>   	retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
>   				   "bdi");
> -	WARN_ON(retval);
> -
> +	if (retval)
> +		return -EFAULT;

Leaked devt alloc and queue ref.

On top of that, some of the functions that add_disk() calls can fail, 
yet it doesn't check for those. And the most major part of this is 
ensuring that all callders of add_disk() properly check and handle the 
error it will pass back, that is completely ignored. Just making 
add_disk() error and unroll itself is the smaller part of the task.


-- 
Jens Axboe


           reply	other threads:[~2015-02-10 21:04 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1423531337-27297-1-git-send-email-xerofoify@gmail.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54DA7273.40100@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xerofoify@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox