block: fix refcounting in BLKBSZSET
authorMiklos Szeredi <mszeredi@suse.cz>
Thu, 24 Feb 2011 14:45:41 +0000 (15:45 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 Feb 2011 16:54:21 +0000 (08:54 -0800)
commit3c522cedb572bb8d2e4867f358bdaa7d0c53d88c
treeb348cabd2574638702f9abcccd0b8b711b136162
parentdcace5ac85c628af21878a1fa151e5e6403fb8eb
block: fix refcounting in BLKBSZSET

Adam Kovari and others reported that disconnecting an USB drive with
an ntfs-3g filesystem would cause "kernel BUG at fs/inode.c:1421!" to
be triggered.

The BUG could be traced back to ioctl(BLKBSZSET), which would
erroneously decrement the refcount on the bdev.  This is because
blkdev_get() expects the refcount to be already incremented and either
returns success or decrements the refcount and returns an error.

The bug was introduced by e525fd89 (block: make blkdev_get/put()
handle exclusive access), which didn't take into account this behavior
of blkdev_get().

This fixes
  https://bugzilla.kernel.org/show_bug.cgi?id=29202
(and likely 29792 too)

Reported-by: Adam Kovari <kovariadam@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
block/ioctl.c