Commit 8074b26f67165bf045d92e778c9c10dc5e207fc6

Authored by Miklos Szeredi
Committed by Linus Torvalds
1 parent 3c522cedb5

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 e525fd89 (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>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

... ... @@ -1940,7 +1940,7 @@
1940 1940  
1941 1941 error = -EINVAL;
1942 1942 if (S_ISBLK(inode->i_mode)) {
1943   - bdev = I_BDEV(inode);
  1943 + bdev = bdgrab(I_BDEV(inode));
1944 1944 error = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL,
1945 1945 sys_swapon);
1946 1946 if (error < 0) {