Skip to content

Commit 6dab421

Browse files
Christoph Hellwigaxboe
authored andcommitted
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: 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>
1 parent e2efa07 commit 6dab421

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

drivers/memstick/core/mspro_block.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
186186

187187
mutex_lock(&mspro_block_disk_lock);
188188

189-
if (msb && msb->card) {
189+
if (msb && msb->card)
190190
msb->usage_count++;
191-
if ((mode & FMODE_WRITE) && msb->read_only)
192-
rc = -EROFS;
193-
else
194-
rc = 0;
195-
}
196191

197192
mutex_unlock(&mspro_block_disk_lock);
198193

@@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card)
12391234
set_capacity(msb->disk, capacity);
12401235
dev_dbg(&card->dev, "capacity set %ld\n", capacity);
12411236

1237+
if (msb->read_only)
1238+
set_disk_ro(msb->disk, true);
1239+
12421240
rc = device_add_disk(&card->dev, msb->disk, NULL);
12431241
if (rc)
12441242
goto out_cleanup_disk;

0 commit comments

Comments
 (0)