[PATCH] spi: airoha: initialize as_ctrl at pointer declaration

Lorenzo Bianconi lorenzo at kernel.org
Fri May 3 10:03:08 PDT 2024


This patch introduces just two cosmetic changes to airoha spi-nand driver:
- move airoha_snand_ids definition after airoha_snand_probe routine
- always initialize airoha_snand_ctrl pointer similar to
  airoha_snand_dev one

Signed-off-by: Lorenzo Bianconi <lorenzo at kernel.org>
---
 drivers/spi/spi-airoha-snfi.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index 9d97ec98881c..7fc3be6d4a6a 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -638,9 +638,9 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 					u64 offs, size_t len, void *buf)
 {
 	struct spi_device *spi = desc->mem->spi;
+	struct airoha_snand_ctrl *as_ctrl = spi_controller_get_devdata(spi->controller);
 	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
 	struct spi_mem_op *op = &desc->info.op_tmpl;
-	struct airoha_snand_ctrl *as_ctrl;
 	u32 val, rd_mode;
 	int err;
 
@@ -661,7 +661,6 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
 		break;
 	}
 
-	as_ctrl = spi_controller_get_devdata(spi->controller);
 	err = airoha_snand_set_mode(as_ctrl, SPI_MODE_DMA);
 	if (err < 0)
 		return err;
@@ -768,13 +767,12 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 					 u64 offs, size_t len, const void *buf)
 {
 	struct spi_device *spi = desc->mem->spi;
+	struct airoha_snand_ctrl *as_ctrl = spi_controller_get_devdata(spi->controller);
 	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
 	struct spi_mem_op *op = &desc->info.op_tmpl;
-	struct airoha_snand_ctrl *as_ctrl;
 	u32 wr_mode, val;
 	int err;
 
-	as_ctrl = spi_controller_get_devdata(spi->controller);
 	err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL);
 	if (err < 0)
 		return err;
@@ -885,12 +883,12 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
 static int airoha_snand_exec_op(struct spi_mem *mem,
 				const struct spi_mem_op *op)
 {
-	struct airoha_snand_dev *as_dev = spi_get_ctldata(mem->spi);
+	struct spi_device *spi = mem->spi;
+	struct airoha_snand_ctrl *as_ctrl = spi_controller_get_devdata(spi->controller);
+	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
 	u8 data[8], cmd, opcode = op->cmd.opcode;
-	struct airoha_snand_ctrl *as_ctrl;
 	int i, err;
 
-	as_ctrl = spi_controller_get_devdata(mem->spi->controller);
 	if (opcode == SPI_NAND_OP_PROGRAM_EXECUTE &&
 	    op->addr.val == as_dev->cur_page_num) {
 		as_dev->data_need_update = true;
@@ -965,11 +963,9 @@ static const struct spi_controller_mem_ops airoha_snand_mem_ops = {
 
 static int airoha_snand_setup(struct spi_device *spi)
 {
-	struct airoha_snand_ctrl *as_ctrl;
+	struct airoha_snand_ctrl *as_ctrl = spi_controller_get_devdata(spi->controller);
 	struct airoha_snand_dev *as_dev;
 
-	as_ctrl = spi_controller_get_devdata(spi->controller);
-
 	as_dev = devm_kzalloc(as_ctrl->dev, sizeof(*as_dev), GFP_KERNEL);
 	if (!as_dev)
 		return -ENOMEM;
@@ -994,10 +990,9 @@ static int airoha_snand_setup(struct spi_device *spi)
 
 static void airoha_snand_cleanup(struct spi_device *spi)
 {
+	struct airoha_snand_ctrl *as_ctrl = spi_controller_get_devdata(spi->controller);
 	struct airoha_snand_dev *as_dev = spi_get_ctldata(spi);
-	struct airoha_snand_ctrl *as_ctrl;
 
-	as_ctrl = spi_controller_get_devdata(spi->controller);
 	dma_unmap_single(as_ctrl->dev, as_dev->dma_addr,
 			 as_dev->buf_len, DMA_BIDIRECTIONAL);
 	spi_set_ctldata(spi, NULL);
@@ -1049,12 +1044,6 @@ static const struct regmap_config spi_nfi_regmap_config = {
 	.max_register	= REG_SPI_NFI_SNF_NFI_CNFG,
 };
 
-static const struct of_device_id airoha_snand_ids[] = {
-	{ .compatible	= "airoha,en7581-snand" },
-	{ /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(of, airoha_snand_ids);
-
 static int airoha_snand_probe(struct platform_device *pdev)
 {
 	struct airoha_snand_ctrl *as_ctrl;
@@ -1114,6 +1103,12 @@ static int airoha_snand_probe(struct platform_device *pdev)
 	return devm_spi_register_controller(dev, ctrl);
 }
 
+static const struct of_device_id airoha_snand_ids[] = {
+	{ .compatible	= "airoha,en7581-snand" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, airoha_snand_ids);
+
 static struct platform_driver airoha_snand_driver = {
 	.driver = {
 		.name = "airoha-spi",
-- 
2.44.0




More information about the linux-arm-kernel mailing list