All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: aacraid: Fix some error handling paths in 'aac_probe_one()'
@ 2020-04-12  9:40 ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2020-04-12  9:40 UTC (permalink / raw)
  To: aacraid, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

If 'scsi_host_alloc()' or 'kcalloc()' fail, 'error' is known to be 0. Set
it explicitly to -ENOMEM instead before branching to the error handling
path.

While at it, axe 2 useless assignments to 'error'. These values are
overwridden a few lines later.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/scsi/aacraid/linit.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 83a60b0a8cd8..a0a2b3abc512 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1632,7 +1632,7 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct Scsi_Host *shost;
 	struct aac_dev *aac;
 	struct list_head *insert = &aac_devices;
-	int error = -ENODEV;
+	int error;
 	int unique_id = 0;
 	u64 dmamask;
 	int mask_bits = 0;
@@ -1657,7 +1657,6 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	error = pci_enable_device(pdev);
 	if (error)
 		goto out;
-	error = -ENODEV;
 
 	if (!(aac_drivers[index].quirks & AAC_QUIRK_SRC)) {
 		error = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
@@ -1689,8 +1688,10 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_set_master(pdev);
 
 	shost = scsi_host_alloc(&aac_driver_template, sizeof(struct aac_dev));
-	if (!shost)
+	if (!shost) {
+		error = -ENOMEM;
 		goto out_disable_pdev;
+	}
 
 	shost->irq = pdev->irq;
 	shost->unique_id = unique_id;
@@ -1714,8 +1715,11 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	aac->fibs = kcalloc(shost->can_queue + AAC_NUM_MGT_FIB,
 			    sizeof(struct fib),
 			    GFP_KERNEL);
-	if (!aac->fibs)
+	if (!aac->fibs) {
+		error = -ENOMEM;
 		goto out_free_host;
+	}
+
 	spin_lock_init(&aac->fib_lock);
 
 	mutex_init(&aac->ioctl_mutex);
-- 
2.20.1


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

* [PATCH] scsi: aacraid: Fix some error handling paths in 'aac_probe_one()'
@ 2020-04-12  9:40 ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2020-04-12  9:40 UTC (permalink / raw)
  To: aacraid, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

If 'scsi_host_alloc()' or 'kcalloc()' fail, 'error' is known to be 0. Set
it explicitly to -ENOMEM instead before branching to the error handling
path.

While at it, axe 2 useless assignments to 'error'. These values are
overwridden a few lines later.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/scsi/aacraid/linit.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 83a60b0a8cd8..a0a2b3abc512 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1632,7 +1632,7 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct Scsi_Host *shost;
 	struct aac_dev *aac;
 	struct list_head *insert = &aac_devices;
-	int error = -ENODEV;
+	int error;
 	int unique_id = 0;
 	u64 dmamask;
 	int mask_bits = 0;
@@ -1657,7 +1657,6 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	error = pci_enable_device(pdev);
 	if (error)
 		goto out;
-	error = -ENODEV;
 
 	if (!(aac_drivers[index].quirks & AAC_QUIRK_SRC)) {
 		error = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
@@ -1689,8 +1688,10 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_set_master(pdev);
 
 	shost = scsi_host_alloc(&aac_driver_template, sizeof(struct aac_dev));
-	if (!shost)
+	if (!shost) {
+		error = -ENOMEM;
 		goto out_disable_pdev;
+	}
 
 	shost->irq = pdev->irq;
 	shost->unique_id = unique_id;
@@ -1714,8 +1715,11 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	aac->fibs = kcalloc(shost->can_queue + AAC_NUM_MGT_FIB,
 			    sizeof(struct fib),
 			    GFP_KERNEL);
-	if (!aac->fibs)
+	if (!aac->fibs) {
+		error = -ENOMEM;
 		goto out_free_host;
+	}
+
 	spin_lock_init(&aac->fib_lock);
 
 	mutex_init(&aac->ioctl_mutex);
-- 
2.20.1

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

* Re: [PATCH] scsi: aacraid: Fix some error handling paths in 'aac_probe_one()'
  2020-04-12  9:40 ` Christophe JAILLET
@ 2020-04-27 22:49   ` Martin K. Petersen
  -1 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-04-27 22:49 UTC (permalink / raw)
  To: jejb, aacraid, Christophe JAILLET
  Cc: Martin K . Petersen, linux-scsi, kernel-janitors, linux-kernel

On Sun, 12 Apr 2020 11:40:39 +0200, Christophe JAILLET wrote:

> If 'scsi_host_alloc()' or 'kcalloc()' fail, 'error' is known to be 0. Set
> it explicitly to -ENOMEM instead before branching to the error handling
> path.
> 
> While at it, axe 2 useless assignments to 'error'. These values are
> overwridden a few lines later.

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: aacraid: Fix error handling paths in aac_probe_one()
      https://git.kernel.org/mkp/scsi/c/f7854c382240

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] scsi: aacraid: Fix some error handling paths in 'aac_probe_one()'
@ 2020-04-27 22:49   ` Martin K. Petersen
  0 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-04-27 22:49 UTC (permalink / raw)
  To: jejb, aacraid, Christophe JAILLET
  Cc: Martin K . Petersen, linux-scsi, kernel-janitors, linux-kernel

On Sun, 12 Apr 2020 11:40:39 +0200, Christophe JAILLET wrote:

> If 'scsi_host_alloc()' or 'kcalloc()' fail, 'error' is known to be 0. Set
> it explicitly to -ENOMEM instead before branching to the error handling
> path.
> 
> While at it, axe 2 useless assignments to 'error'. These values are
> overwridden a few lines later.

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: aacraid: Fix error handling paths in aac_probe_one()
      https://git.kernel.org/mkp/scsi/c/f7854c382240

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-04-27 22:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12  9:40 [PATCH] scsi: aacraid: Fix some error handling paths in 'aac_probe_one()' Christophe JAILLET
2020-04-12  9:40 ` Christophe JAILLET
2020-04-27 22:49 ` Martin K. Petersen
2020-04-27 22:49   ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.