]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
swapfile: avoid dereferencing bd_disk during swap_entry_free for network storage
authorMel Gorman <mgorman@suse.de>
Sat, 21 Jul 2012 00:54:29 +0000 (10:54 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 25 Jul 2012 03:02:40 +0000 (13:02 +1000)
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.

With reference to this callback, Christoph Hellwig stated "Please just
remove the callback entirely.  It has no user outside the staging tree and
was added clearly against the rules for that staging tree".  This would
also be my preference but there was not an obvious way of keeping zram in
staging/ happy.

Signed-off-by: Xiaotian Feng <dfeng@redhat.com>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Acked-by: Rik van Riel <riel@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric B Munson <emunson@mgebm.net>
Cc: Eric Paris <eparis@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Cc: Neil Brown <neilb@suse.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c

index 7307fc928d7b2d2e07bc4ee91ca8e4f7875b9bd0..63958d60ecb080728343c52f3728b4aebe93c5bd 100644 (file)
@@ -549,7 +549,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)
@@ -560,9 +559,12 @@ static unsigned char swap_entry_free(struct swap_info_struct *p,
                nr_swap_pages++;
                p->inuse_pages--;
                frontswap_invalidate_page(p->type, offset);
-               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;