Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756213Ab1BXOuL (ORCPT ); Thu, 24 Feb 2011 09:50:11 -0500 Received: from fxip-0047f.externet.hu ([88.209.222.127]:37861 "EHLO pomaz-ex.szeredi.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756134Ab1BXOuI (ORCPT ); Thu, 24 Feb 2011 09:50:08 -0500 To: akpm@linux-foundation.org, torvalds@linux-foundation.org CC: rjw@sisk.pl, tj@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: fix refcounting in swapon Message-Id: From: Miklos Szeredi Date: Thu, 24 Feb 2011 15:49:53 +0100 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1294 Lines: 34 From: Miklos Szeredi 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(). CC: Tejun Heo Signed-off-by: Miklos Szeredi --- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux.git/mm/swapfile.c =================================================================== --- linux.git.orig/mm/swapfile.c 2011-02-24 15:29:26.000000000 +0100 +++ linux.git/mm/swapfile.c 2011-02-24 15:32:31.000000000 +0100 @@ -1940,7 +1940,7 @@ SYSCALL_DEFINE2(swapon, const char __use error = -EINVAL; if (S_ISBLK(inode->i_mode)) { - bdev = I_BDEV(inode); + bdev = bdgrab(I_BDEV(inode)); error = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, sys_swapon); if (error < 0) { -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/