mm/readahead: Fix null pointer
authorAaron Marcher <aaron@sigma-star.at>
Wed, 15 Jul 2020 07:21:39 +0000 (09:21 +0200)
committerAaron Marcher <aaron@sigma-star.at>
Fri, 17 Jul 2020 13:57:56 +0000 (15:57 +0200)
When using BTRFS, the kernel panics on boot during mount with the following
error message: `Unable to handle kernel NULL pointer dereference at virtual
address 00000044`

The responsible code snippet has been added to mm/readahead and contains a
null pointer: `filp` can be NULL when using filesystems writing metadata
(e.g. btrfs)

Fix this issue by extending the if-clause

mm/readahead.c

index 58f5a3bb2b0750df76a93a582ab83518267ed13d..4fb71a4bb085c086a32c61bbb2ee3b75f10c5e4a 100644 (file)
@@ -161,7 +161,7 @@ int __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
        gfp_t gfp_mask = readahead_gfp_mask(mapping);
 
 #ifdef CONFIG_AMLOGIC_CMA
-       if (filp->f_mode & (FMODE_WRITE | FMODE_WRITE_IOCTL))
+       if (filp && (filp->f_mode & (FMODE_WRITE | FMODE_WRITE_IOCTL)))
                gfp_mask |= __GFP_WRITE;
 #endif /* CONFIG_AMLOGIC_CMA */