Skip to content

Commit cff49d5

Browse files
acelanbroonie
authored andcommitted
spi: Unify error codes by replacing -ENOTSUPP with -EOPNOTSUPP
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>
1 parent 8e6a439 commit cff49d5

10 files changed

Lines changed: 14 additions & 12 deletions

File tree

drivers/mtd/nand/spi/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ static int spinand_manufacturer_match(struct spinand_device *spinand,
974974
spinand->manufacturer = manufacturer;
975975
return 0;
976976
}
977-
return -ENOTSUPP;
977+
return -EOPNOTSUPP;
978978
}
979979

980980
static int spinand_id_detect(struct spinand_device *spinand)

drivers/mtd/spi-nor/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,7 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
31463146
int ret;
31473147

31483148
ret = params->set_4byte_addr_mode(nor, enable);
3149-
if (ret && ret != -ENOTSUPP)
3149+
if (ret && ret != -EOPNOTSUPP)
31503150
return ret;
31513151

31523152
if (enable) {

drivers/spi/atmel-quadspi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int atmel_qspi_find_mode(const struct spi_mem_op *op)
272272
if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i]))
273273
return i;
274274

275-
return -ENOTSUPP;
275+
return -EOPNOTSUPP;
276276
}
277277

278278
static bool atmel_qspi_supports_op(struct spi_mem *mem,

drivers/spi/spi-ath79.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int ath79_exec_mem_op(struct spi_mem *mem,
146146
/* Only use for fast-read op. */
147147
if (op->cmd.opcode != 0x0b || op->data.dir != SPI_MEM_DATA_IN ||
148148
op->addr.nbytes != 3 || op->dummy.nbytes != 1)
149-
return -ENOTSUPP;
149+
return -EOPNOTSUPP;
150150

151151
/* disable GPIO mode */
152152
ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);

drivers/spi/spi-bcm-qspi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ static int bcm_qspi_exec_mem_op(struct spi_mem *mem,
11991199

12001200
if (!op->data.nbytes || !op->addr.nbytes || op->addr.nbytes > 4 ||
12011201
op->data.dir != SPI_MEM_DATA_IN)
1202-
return -ENOTSUPP;
1202+
return -EOPNOTSUPP;
12031203

12041204
buf = op->data.buf.in;
12051205
addr = op->addr.val;

drivers/spi/spi-mem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
323323
return ret;
324324

325325
if (!spi_mem_internal_supports_op(mem, op))
326-
return -ENOTSUPP;
326+
return -EOPNOTSUPP;
327327

328328
if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) {
329329
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)
339339
* read path) and expect the core to use the regular SPI
340340
* interface in other cases.
341341
*/
342-
if (!ret || ret != -ENOTSUPP)
342+
if (!ret || ret != -ENOTSUPP || ret != -EOPNOTSUPP)
343343
return ret;
344344
}
345345

@@ -559,7 +559,7 @@ spi_mem_dirmap_create(struct spi_mem *mem,
559559
if (ret) {
560560
desc->nodirmap = true;
561561
if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
562-
ret = -ENOTSUPP;
562+
ret = -EOPNOTSUPP;
563563
else
564564
ret = 0;
565565
}

drivers/spi/spi-npcm-fiu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ static int npcm_fiu_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
556556
op->data.nbytes);
557557

558558
if (fiu->spix_mode || op->addr.nbytes > 4)
559-
return -ENOTSUPP;
559+
return -EOPNOTSUPP;
560560

561561
if (fiu->clkrate != chip->clkrate) {
562562
ret = clk_set_rate(fiu->clk, chip->clkrate);

drivers/spi/spi-ti-qspi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,12 @@ static int ti_qspi_exec_mem_op(struct spi_mem *mem,
613613
/* Only optimize read path. */
614614
if (!op->data.nbytes || op->data.dir != SPI_MEM_DATA_IN ||
615615
!op->addr.nbytes || op->addr.nbytes > 4)
616-
return -ENOTSUPP;
616+
return -EOPNOTSUPP;
617617

618618
/* Address exceeds MMIO window size, fall back to regular mode. */
619619
from = op->addr.val;
620620
if (from + op->data.nbytes > qspi->mmap_size)
621-
return -ENOTSUPP;
621+
return -EOPNOTSUPP;
622622

623623
mutex_lock(&qspi->list_lock);
624624

drivers/spi/spi-wpcm-fiu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static int wpcm_fiu_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
361361

362362
wpcm_fiu_stall_host(fiu, false);
363363

364-
return -ENOTSUPP;
364+
return -EOPNOTSUPP;
365365
}
366366

367367
static int wpcm_fiu_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)

include/linux/spi/spi-mem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem)
233233
* limitations)
234234
* @supports_op: check if an operation is supported by the controller
235235
* @exec_op: execute a SPI memory operation
236+
* not all driver provides supports_op(), so it can return -EOPNOTSUPP
237+
* if the op is not supported by the driver/controller
236238
* @get_name: get a custom name for the SPI mem device from the controller.
237239
* This might be needed if the controller driver has been ported
238240
* to use the SPI mem layer and a custom name is used to keep

0 commit comments

Comments
 (0)