spi: Unify error codes by replacing -ENOTSUPP with -EOPNOTSUPP
authorChia-Lin Kao (AceLan) <acelan.kao@canonical.com>
Wed, 29 Nov 2023 06:43:10 +0000 (14:43 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 30 Nov 2023 12:12:39 +0000 (12:12 +0000)
This commit updates the SPI subsystem, particularly affecting "SPI MEM"
drivers and core parts, by replacing the -ENOTSUPP error code with
-EOPNOTSUPP.

The key motivations for this change are as follows:
1. The spi-nor driver currently uses EOPNOTSUPP, whereas calls to spi-mem
might return ENOTSUPP. This update aims to unify the error reporting
within the SPI subsystem for clarity and consistency.

2. The use of ENOTSUPP has been flagged by checkpatch as inappropriate,
mainly being reserved for NFS-related errors. To align with kernel coding
standards and recommendations, this change is being made.

3. By using EOPNOTSUPP, we provide more specific context to the error,
indicating that a particular operation is not supported. This helps
differentiate from the more generic ENOTSUPP error, allowing drivers to
better handle and respond to different error scenarios.

Risks and Considerations:
While this change is primarily intended as a code cleanup and error code
unification, there is a minor risk of breaking user-space applications
that rely on specific return codes for unsupported operations. However,
this risk is considered low, as such use-cases are unlikely to be common
or critical. Nevertheless, developers and users should be aware of this
change, especially if they have scripts or tools that specifically handle
SPI error codes.

This commit does not introduce any functional changes to the SPI subsystem
or the affected drivers.

Signed-off-by: "Chia-Lin Kao (AceLan)" <acelan.kao@canonical.com>
Acked-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20231129064311.272422-1-acelan.kao@canonical.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/mtd/nand/spi/core.c
drivers/mtd/spi-nor/core.c
drivers/spi/atmel-quadspi.c
drivers/spi/spi-ath79.c
drivers/spi/spi-bcm-qspi.c
drivers/spi/spi-mem.c
drivers/spi/spi-npcm-fiu.c
drivers/spi/spi-ti-qspi.c
drivers/spi/spi-wpcm-fiu.c
include/linux/spi/spi-mem.h

index 849ccfedbc72dfb27cd6277d3cacc90a6289c66d..e0b6715e5dfed6f7774228734a2124aad2eafe8e 100644 (file)
@@ -974,7 +974,7 @@ static int spinand_manufacturer_match(struct spinand_device *spinand,
                spinand->manufacturer = manufacturer;
                return 0;
        }
-       return -ENOTSUPP;
+       return -EOPNOTSUPP;
 }
 
 static int spinand_id_detect(struct spinand_device *spinand)
index 1c443fe568cfb45d07b8cda123e5feb0f21d98e5..87cb2047df80905832e00a331554f811b3aa17ea 100644 (file)
@@ -3146,7 +3146,7 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
        int ret;
 
        ret = params->set_4byte_addr_mode(nor, enable);
-       if (ret && ret != -ENOTSUPP)
+       if (ret && ret != -EOPNOTSUPP)
                return ret;
 
        if (enable) {
index 3d1252566134b3cc5c36752695fe8cc9c4de9c68..370c4d1572ed02fa3e3cc54b2fa768e4a9bfa21e 100644 (file)
@@ -272,7 +272,7 @@ static int atmel_qspi_find_mode(const struct spi_mem_op *op)
                if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i]))
                        return i;
 
-       return -ENOTSUPP;
+       return -EOPNOTSUPP;
 }
 
 static bool atmel_qspi_supports_op(struct spi_mem *mem,
index c9f1d1e1dcf7553613cb37ba25feb3b7ac6291f3..b7ada981464a5e7c9eb5cceed556cb684eb5b820 100644 (file)
@@ -146,7 +146,7 @@ static int ath79_exec_mem_op(struct spi_mem *mem,
        /* Only use for fast-read op. */
        if (op->cmd.opcode != 0x0b || op->data.dir != SPI_MEM_DATA_IN ||
            op->addr.nbytes != 3 || op->dummy.nbytes != 1)
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        /* disable GPIO mode */
        ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
index ef08fcac2f6dab59a692ad7d577b4b2067b8ed06..d96222e6d7d2d4022753d3120b4c36ea759dad75 100644 (file)
@@ -1199,7 +1199,7 @@ static int bcm_qspi_exec_mem_op(struct spi_mem *mem,
 
        if (!op->data.nbytes || !op->addr.nbytes || op->addr.nbytes > 4 ||
            op->data.dir != SPI_MEM_DATA_IN)
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        buf = op->data.buf.in;
        addr = op->addr.val;
index edd7430d4c052bf31c122bfac684e8edfdad4de4..2dc8ceb85374b1e1e4e5de3b4ff0c106bd0fccce 100644 (file)
@@ -323,7 +323,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
                return ret;
 
        if (!spi_mem_internal_supports_op(mem, op))
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) {
                ret = spi_mem_access_start(mem);
@@ -339,7 +339,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
                 * read path) and expect the core to use the regular SPI
                 * interface in other cases.
                 */
-               if (!ret || ret != -ENOTSUPP)
+               if (!ret || ret != -ENOTSUPP || ret != -EOPNOTSUPP)
                        return ret;
        }
 
@@ -559,7 +559,7 @@ spi_mem_dirmap_create(struct spi_mem *mem,
        if (ret) {
                desc->nodirmap = true;
                if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
-                       ret = -ENOTSUPP;
+                       ret = -EOPNOTSUPP;
                else
                        ret = 0;
        }
index 03db9f016a1112dce73b95a1355581bad1219146..f3bb8bbc192f297a31e18ac28b1ba1bc520ffa73 100644 (file)
@@ -556,7 +556,7 @@ static int npcm_fiu_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
                op->data.nbytes);
 
        if (fiu->spix_mode || op->addr.nbytes > 4)
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        if (fiu->clkrate != chip->clkrate) {
                ret = clk_set_rate(fiu->clk, chip->clkrate);
index fdc092a05284abae71cf839640805da34ce39f92..a6a89c59c4189e779ca1b2fae3b5f1c5ef17998e 100644 (file)
@@ -613,12 +613,12 @@ static int ti_qspi_exec_mem_op(struct spi_mem *mem,
        /* Only optimize read path. */
        if (!op->data.nbytes || op->data.dir != SPI_MEM_DATA_IN ||
            !op->addr.nbytes || op->addr.nbytes > 4)
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        /* Address exceeds MMIO window size, fall back to regular mode. */
        from = op->addr.val;
        if (from + op->data.nbytes > qspi->mmap_size)
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        mutex_lock(&qspi->list_lock);
 
index 852ffe013d326eba680c7060ebda1b17e3d35f5f..d76f7b5a9b9738f6e55dc38a22fb5648e477d438 100644 (file)
@@ -361,7 +361,7 @@ static int wpcm_fiu_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 
        wpcm_fiu_stall_host(fiu, false);
 
-       return -ENOTSUPP;
+       return -EOPNOTSUPP;
 }
 
 static int wpcm_fiu_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
index 6b0a7dc48a4b799d0cfa2ed8b4534128b63c14de..f866d5c8ed32ad2b6e8d39ca644f20a89eedc647 100644 (file)
@@ -233,6 +233,8 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem)
  *                 limitations)
  * @supports_op: check if an operation is supported by the controller
  * @exec_op: execute a SPI memory operation
+ *           not all driver provides supports_op(), so it can return -EOPNOTSUPP
+ *           if the op is not supported by the driver/controller
  * @get_name: get a custom name for the SPI mem device from the controller.
  *           This might be needed if the controller driver has been ported
  *           to use the SPI mem layer and a custom name is used to keep