diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index 0c04615651b7e8b412e85cdeee26365ddee7515c..427dfe3ce78c68eebe0afde4636b6fdc91ecdec5 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -89,8 +89,8 @@ do_xip_mapping_read(struct address_space *mapping,
 			}
 		}
 		nr = nr - offset;
-		if (nr > len)
-			nr = len;
+		if (nr > len - copied)
+			nr = len - copied;
 
 		error = mapping->a_ops->get_xip_mem(mapping, index, 0,
 							&xip_mem, &xip_pfn);