spi: return error if kmap'd buffers passed to spi_map_buf()
authorVignesh R <vigneshr@ti.com>
Mon, 25 Apr 2016 09:44:00 +0000 (15:14 +0530)
committerMark Brown <broonie@kernel.org>
Mon, 25 Apr 2016 17:55:57 +0000 (18:55 +0100)
Current spi_map_buf() implementation supports creates sg_table for
vmalloc'd and kmalloc'd buffers. Therefore return error if kmap'd buffer
(or any other buffer) is passed to spi_map_buf().

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c

index 6c4c050e6b651742bdb09f3e7b03c044d9174d50..a50f880a5036dfcad719a3ab7ad7c937864394a6 100644 (file)
@@ -717,9 +717,11 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
        if (vmalloced_buf) {
                desc_len = min_t(int, max_seg_size, PAGE_SIZE);
                sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
-       } else {
+       } else if (virt_addr_valid(buf)) {
                desc_len = min_t(int, max_seg_size, master->max_dma_len);
                sgs = DIV_ROUND_UP(len, desc_len);
+       } else {
+               return -EINVAL;
        }
 
        ret = sg_alloc_table(sgt, sgs, GFP_KERNEL);