Re: Linux v2.5.42

Alexander Viro
2002-10-14T19:26:15Z

On Mon, 14 Oct 2002, Christoph Hellwig wrote:

> +{
> + int r;
> +
> + if (d->bdev)
> + BUG();
> +
> + if (!(d->bdev = bdget(kdev_t_to_nr(d->dev))))
> + return -ENOMEM;
> +
> + r = blkdev_get(d->bdev, d->mode, 0, BDEV_RAW);
> + if (r) {
> + bdput(d->bdev);

*blam*
failing blkdev_get() does bdput() itself.

> +
> + if (sscanf(path, "%x:%x", &major, &minor) == 2) {
> + /* Extract the major/minor numbers */
> + dev = mk_kdev(major, minor);
> + } else {
> + /* convert the path to a device */
> + if ((r = lookup_device(path, &dev)))
> + return r;
> + }
>
> What do you need the major/minor version for?

... and in any case, both branches should result in struct block_device *
(the former - via bdget(MKDEV(...));)

> + switch (command) {
> + case BLKGETSIZE:
> + l_size = (long) size;
> + if (copy_to_user((void *) a, &l_size, sizeof(long)))
> + return -EFAULT;
> + break;

> These two are in generic code and odn't need to be implemented
> by a lowlevel driver (won't ever be called).

Not only that, but BLKGETSIZE above is missing overflow check.
(these two are still called, with generic version called if we
get -EINVAL; with patches submitted to Linus they won't be even
tried).