Merge tag 'spi-fix-v5.5-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
[sfrench/cifs-2.6.git] / lib / logic_pio.c
index 905027574e5d8041d1394dc4e5582061ed084e2f..f511a99bb38999d03aef67a9b512b6e5702742d0 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2017 HiSilicon Limited, All Rights Reserved.
  * Author: Gabriele Paoloni <gabriele.paoloni@huawei.com>
  * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
+ * Author: John Garry <john.garry@huawei.com>
  */
 
 #define pr_fmt(fmt)    "LOGIC PIO: " fmt
@@ -39,7 +40,8 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
        resource_size_t iio_sz = MMIO_UPPER_LIMIT;
        int ret = 0;
 
-       if (!new_range || !new_range->fwnode || !new_range->size)
+       if (!new_range || !new_range->fwnode || !new_range->size ||
+           (new_range->flags == LOGIC_PIO_INDIRECT && !new_range->ops))
                return -EINVAL;
 
        start = new_range->hw_start;
@@ -237,7 +239,7 @@ type logic_in##bw(unsigned long addr)                                       \
        } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
                struct logic_pio_hwaddr *entry = find_io_range(addr);   \
                                                                        \
-               if (entry && entry->ops)                                \
+               if (entry)                                              \
                        ret = entry->ops->in(entry->hostdata,           \
                                        addr, sizeof(type));            \
                else                                                    \
@@ -253,7 +255,7 @@ void logic_out##bw(type value, unsigned long addr)                  \
        } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
                struct logic_pio_hwaddr *entry = find_io_range(addr);   \
                                                                        \
-               if (entry && entry->ops)                                \
+               if (entry)                                              \
                        entry->ops->out(entry->hostdata,                \
                                        addr, value, sizeof(type));     \
                else                                                    \
@@ -261,7 +263,7 @@ void logic_out##bw(type value, unsigned long addr)                  \
        }                                                               \
 }                                                                      \
                                                                        \
-void logic_ins##bw(unsigned long addr, void *buffer,           \
+void logic_ins##bw(unsigned long addr, void *buffer,                   \
                   unsigned int count)                                  \
 {                                                                      \
        if (addr < MMIO_UPPER_LIMIT) {                                  \
@@ -269,7 +271,7 @@ void logic_ins##bw(unsigned long addr, void *buffer,                \
        } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
                struct logic_pio_hwaddr *entry = find_io_range(addr);   \
                                                                        \
-               if (entry && entry->ops)                                \
+               if (entry)                                              \
                        entry->ops->ins(entry->hostdata,                \
                                addr, buffer, sizeof(type), count);     \
                else                                                    \
@@ -286,7 +288,7 @@ void logic_outs##bw(unsigned long addr, const void *buffer,         \
        } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
                struct logic_pio_hwaddr *entry = find_io_range(addr);   \
                                                                        \
-               if (entry && entry->ops)                                \
+               if (entry)                                              \
                        entry->ops->outs(entry->hostdata,               \
                                addr, buffer, sizeof(type), count);     \
                else                                                    \