public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] char: xillybus: use devm_add_action_or_reset
@ 2016-04-30 16:13 Sudip Mukherjee
  2016-05-01  6:28 ` Eli Billauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sudip Mukherjee @ 2016-04-30 16:13 UTC (permalink / raw)
  To: Eli Billauer, Greg Kroah-Hartman; +Cc: linux-kernel, Sudip Mukherjee

If devm_add_action() fails we are explicitly calling dma_unmap_single(),
pci_unmap_single() and kfree(). Lets use the helper
devm_add_action_or_reset() and return directly in case of error, as we
know that the cleanup function has been already called by the helper if
there was any error. At that same time remove the variable rc which
becomes unused now.

Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---

v2: returns directly instead of having an extra variable rc.

 drivers/char/xillybus/xillybus_of.c   | 11 +----------
 drivers/char/xillybus/xillybus_pcie.c | 10 +---------
 2 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xillybus_of.c
index 7818650..78a492f 100644
--- a/drivers/char/xillybus/xillybus_of.c
+++ b/drivers/char/xillybus/xillybus_of.c
@@ -81,7 +81,6 @@ static int xilly_map_single_of(struct xilly_endpoint *ep,
 {
 	dma_addr_t addr;
 	struct xilly_mapping *this;
-	int rc;
 
 	this = kzalloc(sizeof(*this), GFP_KERNEL);
 	if (!this)
@@ -101,15 +100,7 @@ static int xilly_map_single_of(struct xilly_endpoint *ep,
 
 	*ret_dma_handle = addr;
 
-	rc = devm_add_action(ep->dev, xilly_of_unmap, this);
-
-	if (rc) {
-		dma_unmap_single(ep->dev, addr, size, direction);
-		kfree(this);
-		return rc;
-	}
-
-	return 0;
+	return devm_add_action_or_reset(ep->dev, xilly_of_unmap, this);
 }
 
 static struct xilly_endpoint_hardware of_hw = {
diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index 9418300..dff2d15 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -98,7 +98,6 @@ static int xilly_map_single_pci(struct xilly_endpoint *ep,
 	int pci_direction;
 	dma_addr_t addr;
 	struct xilly_mapping *this;
-	int rc;
 
 	this = kzalloc(sizeof(*this), GFP_KERNEL);
 	if (!this)
@@ -120,14 +119,7 @@ static int xilly_map_single_pci(struct xilly_endpoint *ep,
 
 	*ret_dma_handle = addr;
 
-	rc = devm_add_action(ep->dev, xilly_pci_unmap, this);
-	if (rc) {
-		pci_unmap_single(ep->pdev, addr, size, pci_direction);
-		kfree(this);
-		return rc;
-	}
-
-	return 0;
+	return devm_add_action_or_reset(ep->dev, xilly_pci_unmap, this);
 }
 
 static struct xilly_endpoint_hardware pci_hw = {
-- 
1.9.1

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

* Re: [PATCH v2] char: xillybus: use devm_add_action_or_reset
  2016-04-30 16:13 [PATCH v2] char: xillybus: use devm_add_action_or_reset Sudip Mukherjee
@ 2016-05-01  6:28 ` Eli Billauer
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Billauer @ 2016-05-01  6:28 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: Greg Kroah-Hartman, linux-kernel

Fine with me. Thanks.

Acked-by: Eli Billauer <eli.billauer@gmail.com>

On 30/04/16 19:13, Sudip Mukherjee wrote:
> If devm_add_action() fails we are explicitly calling dma_unmap_single(),
> pci_unmap_single() and kfree(). Lets use the helper
> devm_add_action_or_reset() and return directly in case of error, as we
> know that the cleanup function has been already called by the helper if
> there was any error. At that same time remove the variable rc which
> becomes unused now.
>
> Signed-off-by: Sudip Mukherjee<sudip.mukherjee@codethink.co.uk>
> ---
>
>    

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

end of thread, other threads:[~2016-05-01  6:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-30 16:13 [PATCH v2] char: xillybus: use devm_add_action_or_reset Sudip Mukherjee
2016-05-01  6:28 ` Eli Billauer

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