Skip to content

Commit 8074b26

Browse files
Miklos Szereditorvalds
authored andcommitted
mm: fix refcounting in swapon
Grab a reference to bdev before calling blkdev_get(), which expects the refcount to be already incremented and either returns success or decrements the refcount and returns an error. The bug was introduced by e525fd8 (block: make blkdev_get/put() handle exclusive access), which didn't take into account this behavior of blkdev_get(). Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3c522ce commit 8074b26

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎mm/swapfile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
19401940

19411941
error = -EINVAL;
19421942
if (S_ISBLK(inode->i_mode)) {
1943-
bdev = I_BDEV(inode);
1943+
bdev = bdgrab(I_BDEV(inode));
19441944
error = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL,
19451945
sys_swapon);
19461946
if (error < 0) {

0 commit comments

Comments
 (0)