mm: Introduce flush_cache_vmap_early()
[platform/kernel/linux-rpi.git] / fs / buffer.c
index a6785cd..12e9a71 100644 (file)
@@ -2058,8 +2058,17 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,
                fallthrough;
        case IOMAP_MAPPED:
                if ((iomap->flags & IOMAP_F_NEW) ||
-                   offset >= i_size_read(inode))
+                   offset >= i_size_read(inode)) {
+                       /*
+                        * This can happen if truncating the block device races
+                        * with the check in the caller as i_size updates on
+                        * block devices aren't synchronized by i_rwsem for
+                        * block devices.
+                        */
+                       if (S_ISBLK(inode->i_mode))
+                               return -EIO;
                        set_buffer_new(bh);
+               }
                bh->b_blocknr = (iomap->addr + offset - iomap->offset) >>
                                inode->i_blkbits;
                set_buffer_mapped(bh);