Merge remote-tracking branches 'spi/fix/atmel', 'spi/fix/pxa2xx' and 'spi/fix/unregis...
[muen/linux.git] / drivers / spi / spi.c
index e90fd442b3f044f9911c19f6ca60d42437f9bcc3..7b213faa0a2b7247837372a4bc4a537e1c9a2ad1 100644 (file)
@@ -779,8 +779,14 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
        for (i = 0; i < sgs; i++) {
 
                if (vmalloced_buf || kmap_buf) {
-                       min = min_t(size_t,
-                                   len, desc_len - offset_in_page(buf));
+                       /*
+                        * Next scatterlist entry size is the minimum between
+                        * the desc_len and the remaining buffer length that
+                        * fits in a page.
+                        */
+                       min = min_t(size_t, desc_len,
+                                   min_t(size_t, len,
+                                         PAGE_SIZE - offset_in_page(buf)));
                        if (vmalloced_buf)
                                vm_page = vmalloc_to_page(buf);
                        else