[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231203052125.37334-1-liuhaoran14@163.com>
Date: Sat, 2 Dec 2023 21:21:25 -0800
From: Haoran Liu <liuhaoran14@....com>
To: support.opensource@...semi.com
Cc: lee@...nel.org, linux-kernel@...r.kernel.org,
Haoran Liu <liuhaoran14@....com>
Subject: [PATCH] [mfd] da9052: Add error handling for spi_setup in da9052_spi_probe
This patch adds error handling for the spi_setup call. The need for this
error handling was identified through static analysis, which highlighted
the lack of proper handling for potential failures of spi_setup.
Previously, a failure in spi_setup could lead to unstable behavior of
the DA9052 device.
Although the error addressed by this patch may not occur in the current
environment, I still suggest implementing these error handling routines
if the function is not highly time-sensitive. As the environment evolves
or the code gets reused in different contexts, there's a possibility that
these errors might occur. In case you find this addition unnecessary, I
completely understand and respect your perspective. My intention was to
enhance the robustness of the code, but I acknowledge that practical
considerations and current functionality might not warrant this change
at this point.
Signed-off-by: Haoran Liu <liuhaoran14@....com>
---
drivers/mfd/da9052-spi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/da9052-spi.c b/drivers/mfd/da9052-spi.c
index be5f2b34e18a..c32d5025a18f 100644
--- a/drivers/mfd/da9052-spi.c
+++ b/drivers/mfd/da9052-spi.c
@@ -22,6 +22,7 @@ static int da9052_spi_probe(struct spi_device *spi)
int ret;
const struct spi_device_id *id = spi_get_device_id(spi);
struct da9052 *da9052;
+ int ret;
da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
if (!da9052)
@@ -29,7 +30,11 @@ static int da9052_spi_probe(struct spi_device *spi)
spi->mode = SPI_MODE_0;
spi->bits_per_word = 8;
- spi_setup(spi);
+ ret = spi_setup(spi);
+ if (ret) {
+ dev_err(&spi->dev, "spi_setup failed: %d\n", ret);
+ return ret;
+ }
da9052->dev = &spi->dev;
da9052->chip_irq = spi->irq;
--
2.17.1
Powered by blists - more mailing lists