Commit 6dab421b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

memstick/mspro_block: fix handling of read-only devices

Use set_disk_ro to propagate the read-only state to the block layer
instead of checking for it in ->open and leaking a reference in case
of a read-only device.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220215094514.3828912-4-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e2efa079
...@@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode) ...@@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
mutex_lock(&mspro_block_disk_lock); mutex_lock(&mspro_block_disk_lock);
if (msb && msb->card) { if (msb && msb->card)
msb->usage_count++; msb->usage_count++;
if ((mode & FMODE_WRITE) && msb->read_only)
rc = -EROFS;
else
rc = 0;
}
mutex_unlock(&mspro_block_disk_lock); mutex_unlock(&mspro_block_disk_lock);
...@@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card) ...@@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card)
set_capacity(msb->disk, capacity); set_capacity(msb->disk, capacity);
dev_dbg(&card->dev, "capacity set %ld\n", capacity); dev_dbg(&card->dev, "capacity set %ld\n", capacity);
if (msb->read_only)
set_disk_ro(msb->disk, true);
rc = device_add_disk(&card->dev, msb->disk, NULL); rc = device_add_disk(&card->dev, msb->disk, NULL);
if (rc) if (rc)
goto out_cleanup_disk; goto out_cleanup_disk;
......
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