Skip to content

Commit

Permalink
drivers/mmc/card/block.c: fix refcount leak in mmc_block_open()
Browse files Browse the repository at this point in the history
mmc_block_open() increments md->usage although it returns with -EROFS when
default mounting a MMC/SD card with write protect switch on.  This
reference counting bug prevents /dev/mmcblkX from being released on card
removal, and situation worsen with reinsertion until the minor number
range runs out.

Reported-by: <sasin@solomon-systech.com>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: <stable@kernel.org>		[2.6.25.x, 2.6.26.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Andrew Morton authored and Linus Torvalds committed Sep 5, 2008
1 parent 22f3016 commit 70bb089
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/mmc/card/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ static int mmc_blk_open(struct inode *inode, struct file *filp)
check_disk_change(inode->i_bdev);
ret = 0;

if ((filp->f_mode & FMODE_WRITE) && md->read_only)
if ((filp->f_mode & FMODE_WRITE) && md->read_only) {
mmc_blk_put(md);
ret = -EROFS;
}
}

return ret;
Expand Down

0 comments on commit 70bb089

Please sign in to comment.