]> www.infradead.org Git - users/hch/block.git/commitdiff
memstick/mspro_block: fix handling of read-only devices
authorChristoph Hellwig <hch@lst.de>
Fri, 28 Jan 2022 13:25:11 +0000 (14:25 +0100)
committerChristoph Hellwig <hch@lst.de>
Tue, 15 Feb 2022 08:08:20 +0000 (09:08 +0100)
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>
drivers/memstick/core/mspro_block.c

index c0450397b67355c41b5e4b94682c07230e486ca3..7ea312f0840e01bc231fc782ad629eee68959788 100644 (file)
@@ -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);
 
@@ -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;