public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [scsi] lasi700: Add error handling in lasi700_probe
@ 2023-11-29 14:52 Haoran Liu
  2023-11-29 16:14 ` James Bottomley
  0 siblings, 1 reply; 2+ messages in thread
From: Haoran Liu @ 2023-11-29 14:52 UTC (permalink / raw)
  To: jejb; +Cc: martin.petersen, linux-scsi, linux-kernel, Haoran Liu

This patch introduces improved error handling for the dma_set_mask and
ioremap calls in the lasi700_probe function within drivers/scsi/lasi700.c.
Previously, the function did not properly handle the potential failure of
these calls, which could lead to improper device initialization and
unpredictable behavior.

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. Addressing them now can prevent potential
debugging efforts in the future, which could be quite resource-intensive.

Signed-off-by: Haoran Liu <liuhaoran14@163.com>
---
 drivers/scsi/lasi700.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/lasi700.c b/drivers/scsi/lasi700.c
index 86fe19e0468d..8d482bee940d 100644
--- a/drivers/scsi/lasi700.c
+++ b/drivers/scsi/lasi700.c
@@ -87,6 +87,7 @@ lasi700_probe(struct parisc_device *dev)
 	unsigned long base = dev->hpa.start + LASI_SCSI_CORE_OFFSET;
 	struct NCR_700_Host_Parameters *hostdata;
 	struct Scsi_Host *host;
+	int err;
 
 	hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
 	if (!hostdata) {
@@ -95,8 +96,20 @@ lasi700_probe(struct parisc_device *dev)
 	}
 
 	hostdata->dev = &dev->dev;
-	dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
+	err = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
+	if (err) {
+		dev_err(&dev->dev, "Failed to set DMA mask: %d\n", err);
+		kfree(hostdata);
+		return err;
+	}
+
 	hostdata->base = ioremap(base, 0x100);
+	if (!hostdata->base) {
+		dev_err(&dev->dev, "ioremap failed\n");
+		kfree(hostdata);
+		return -ENOMEM;
+	}
+
 	hostdata->differential = 0;
 
 	if (dev->id.sversion == LASI_700_SVERSION) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-29 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-29 14:52 [PATCH] [scsi] lasi700: Add error handling in lasi700_probe Haoran Liu
2023-11-29 16:14 ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox