Skip to content

Commit

Permalink
memstick/mspro_block: fix handling of read-only devices
Browse files Browse the repository at this point in the history
[ Upstream commit 6dab421 ]

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: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220215094514.3828912-4-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Christoph Hellwig authored and gregkh committed Apr 8, 2022
1 parent 4d8dbb6 commit 6a0725b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions drivers/memstick/core/mspro_block.c
Expand Up @@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)

mutex_lock(&mspro_block_disk_lock);

if (msb && msb->card) {
if (msb && msb->card)
msb->usage_count++;
if ((mode & FMODE_WRITE) && msb->read_only)
rc = -EROFS;
else
rc = 0;
}

mutex_unlock(&mspro_block_disk_lock);

Expand Down Expand Up @@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card)
set_capacity(msb->disk, 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);
if (rc)
goto out_cleanup_disk;
Expand Down

0 comments on commit 6a0725b

Please sign in to comment.