Commit b8d95484 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

pktcdvd: use blkdev_get_by_dev instead of open coding it

Replace bdget + blkdev_get by blkdev_get_by_dev.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2d9e28a9
...@@ -2110,16 +2110,18 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) ...@@ -2110,16 +2110,18 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
int ret; int ret;
long lba; long lba;
struct request_queue *q; struct request_queue *q;
struct block_device *bdev;
/* /*
* We need to re-open the cdrom device without O_NONBLOCK to be able * We need to re-open the cdrom device without O_NONBLOCK to be able
* to read/write from/to it. It is already opened in O_NONBLOCK mode * to read/write from/to it. It is already opened in O_NONBLOCK mode
* so bdget() can't fail. * so open should not fail.
*/ */
bdget(pd->bdev->bd_dev); bdev = blkdev_get_by_dev(pd->bdev->bd_dev, FMODE_READ | FMODE_EXCL, pd);
ret = blkdev_get(pd->bdev, FMODE_READ | FMODE_EXCL, pd); if (IS_ERR(bdev)) {
if (ret) ret = PTR_ERR(bdev);
goto out; goto out;
}
ret = pkt_get_last_written(pd, &lba); ret = pkt_get_last_written(pd, &lba);
if (ret) { if (ret) {
...@@ -2163,7 +2165,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) ...@@ -2163,7 +2165,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
return 0; return 0;
out_putdev: out_putdev:
blkdev_put(pd->bdev, FMODE_READ | FMODE_EXCL); blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
out: out:
return ret; return ret;
} }
...@@ -2500,7 +2502,6 @@ static int pkt_seq_show(struct seq_file *m, void *p) ...@@ -2500,7 +2502,6 @@ static int pkt_seq_show(struct seq_file *m, void *p)
static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
{ {
int i; int i;
int ret = 0;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
struct block_device *bdev; struct block_device *bdev;
...@@ -2523,12 +2524,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) ...@@ -2523,12 +2524,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
} }
} }
bdev = bdget(dev); bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_NDELAY, NULL);
if (!bdev) if (IS_ERR(bdev))
return -ENOMEM; return PTR_ERR(bdev);
ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY, NULL);
if (ret)
return ret;
if (!blk_queue_scsi_passthrough(bdev_get_queue(bdev))) { if (!blk_queue_scsi_passthrough(bdev_get_queue(bdev))) {
blkdev_put(bdev, FMODE_READ | FMODE_NDELAY); blkdev_put(bdev, FMODE_READ | FMODE_NDELAY);
return -EINVAL; return -EINVAL;
...@@ -2546,7 +2544,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) ...@@ -2546,7 +2544,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
pd->cdrw.thread = kthread_run(kcdrwd, pd, "%s", pd->name); pd->cdrw.thread = kthread_run(kcdrwd, pd, "%s", pd->name);
if (IS_ERR(pd->cdrw.thread)) { if (IS_ERR(pd->cdrw.thread)) {
pkt_err(pd, "can't start kernel thread\n"); pkt_err(pd, "can't start kernel thread\n");
ret = -ENOMEM;
goto out_mem; goto out_mem;
} }
...@@ -2558,7 +2555,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) ...@@ -2558,7 +2555,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
blkdev_put(bdev, FMODE_READ | FMODE_NDELAY); blkdev_put(bdev, FMODE_READ | FMODE_NDELAY);
/* This is safe: open() is still holding a reference. */ /* This is safe: open() is still holding a reference. */
module_put(THIS_MODULE); module_put(THIS_MODULE);
return ret; return -ENOMEM;
} }
static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment