mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tina Johnson <tinajohnson.1234@gmail.com>
To: nagalakshmi.nandigama@avagotech.com
Cc: praveen.krishnamoorthy@avagotech.com,
	sreekanth.reddy@avagotech.com, abhijit.mahajan@avagotech.com,
	linux-scsi@vger.kernel.org, MPT-FusionLinux.pdl@avagotech.com,
	linux-kernel@vger.kernel.org, julia.lawall@lip6.fr,
	Tina Johnson <tinajohnson.1234@gmail.com>
Subject: [PATCH] drivers: message: Clean up error handling for calls to pci_map_single
Date: Wed, 14 Jan 2015 00:16:02 +0530	[thread overview]
Message-ID: <1421174763-8802-1-git-send-email-tinajohnson.1234@gmail.com> (raw)

Replaced null tests on the value return by pci_map_single by calls to
pci_dma_mapping_error.

Added initialization of the ret variable, to return an error code on
failure.

Reorganized error handling code to remove the need for tests on
dma_addr_out, dma_addr_in, and mf.

Added new error labels for freeing dma_addr_out (unmap_out) and
dma_addr_in (unmap_in).

Coccinelle was used to find unchecked dma handles, as follows:

@rule1@
expression e1;
identifier x;
@@

*x = pci_map_single(...);
 ... when != pci_dma_mapping_error(e1,x)

Signed-off-by: Tina Johnson <tinajohnson.1234@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
 drivers/message/fusion/mptsas.c |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 5bdaae1..bac6bec 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -2282,8 +2282,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 	dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
 				      blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
-	if (!dma_addr_out)
+	if (pci_dma_mapping_error(ioc->pcidev, dma_addr_out)) {
+		ret = -ENOMEM;
 		goto put_mf;
+	}
 	ioc->add_sge(psge, flagsLength, dma_addr_out);
 	psge += ioc->SGE_size;
 
@@ -2297,8 +2299,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	flagsLength |= blk_rq_bytes(rsp) + 4;
 	dma_addr_in =  pci_map_single(ioc->pcidev, bio_data(rsp->bio),
 				      blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
-	if (!dma_addr_in)
-		goto unmap;
+	if (pci_dma_mapping_error(ioc->pcidev, dma_addr_in)) {
+		ret = -ENOMEM;
+		goto unmap_out;
+	}
 	ioc->add_sge(psge, flagsLength, dma_addr_in);
 
 	INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
@@ -2310,10 +2314,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		mpt_free_msg_frame(ioc, mf);
 		mf = NULL;
 		if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
-			goto unmap;
+			goto unmap_in;
 		if (!timeleft)
 			mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
-		goto unmap;
+		goto unmap_in;
 	}
 	mf = NULL;
 
@@ -2331,16 +2335,14 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		    ioc->name, __func__);
 		ret = -ENXIO;
 	}
-unmap:
-	if (dma_addr_out)
-		pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
-				 PCI_DMA_BIDIRECTIONAL);
-	if (dma_addr_in)
-		pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
-				 PCI_DMA_BIDIRECTIONAL);
+unmap_in:
+	pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
+			 PCI_DMA_BIDIRECTIONAL);
+unmap_out:
+	pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
+			 PCI_DMA_BIDIRECTIONAL);
 put_mf:
-	if (mf)
-		mpt_free_msg_frame(ioc, mf);
+	mpt_free_msg_frame(ioc, mf);
 out_unlock:
 	CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
 	mutex_unlock(&ioc->sas_mgmt.mutex);
-- 
1.7.10.4


                 reply	other threads:[~2015-01-13 18:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421174763-8802-1-git-send-email-tinajohnson.1234@gmail.com \
    --to=tinajohnson.1234@gmail.com \
    --cc=MPT-FusionLinux.pdl@avagotech.com \
    --cc=abhijit.mahajan@avagotech.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=nagalakshmi.nandigama@avagotech.com \
    --cc=praveen.krishnamoorthy@avagotech.com \
    --cc=sreekanth.reddy@avagotech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®