From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cantor2.suse.de ([195.135.220.15]:46150 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933542Ab1IILBJ (ORCPT ); Fri, 9 Sep 2011 07:01:09 -0400 From: Mel Gorman To: Linux-MM Cc: Linux-Netdev , Linux-NFS , LKML , Andrew Morton , David Miller , Trond Myklebust , Neil Brown , Peter Zijlstra , Mel Gorman Subject: [PATCH 10/10] Avoid dereferencing bd_disk during swap_entry_free for network storage Date: Fri, 9 Sep 2011 12:00:54 +0100 Message-Id: <1315566054-17209-11-git-send-email-mgorman@suse.de> In-Reply-To: <1315566054-17209-1-git-send-email-mgorman@suse.de> References: <1315566054-17209-1-git-send-email-mgorman@suse.de> Sender: linux-nfs-owner@vger.kernel.org List-ID: Content-Type: text/plain MIME-Version: 1.0 Commit [b3a27d: swap: Add swap slot free callback to block_device_operations] dereferences p->bdev->bd_disk but this is a NULL dereference if using swap-over-NFS. This patch checks SWP_BLKDEV on the swap_info_struct before dereferencing. Signed-off-by: Xiaotian Feng Signed-off-by: Mel Gorman --- mm/swapfile.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 806b994..8b85a88 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -547,7 +547,6 @@ static unsigned char swap_entry_free(struct swap_info_struct *p, /* free if no reference */ if (!usage) { - struct gendisk *disk = p->bdev->bd_disk; if (offset < p->lowest_bit) p->lowest_bit = offset; if (offset > p->highest_bit) @@ -557,9 +556,11 @@ static unsigned char swap_entry_free(struct swap_info_struct *p, swap_list.next = p->type; nr_swap_pages++; p->inuse_pages--; - if ((p->flags & SWP_BLKDEV) && - disk->fops->swap_slot_free_notify) - disk->fops->swap_slot_free_notify(p->bdev, offset); + if (p->flags & SWP_BLKDEV) { + struct gendisk *disk = p->bdev->bd_disk; + if (disk->fops->swap_slot_free_notify) + disk->fops->swap_slot_free_notify(p->bdev, offset); + } } return usage; -- 1.7.3.4