Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1386883 > unrolled thread

[PATCH] char: xillybus: use devm_add_action_or_reset

Started bySudip Mukherjee <sudipm.mukherjee@gmail.com>
First post2016-04-25 23:00 +0200
Last post2016-04-26 12:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] char: xillybus: use devm_add_action_or_reset Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-04-25 23:00 +0200
    Re: [PATCH] char: xillybus: use devm_add_action_or_reset Eli Billauer <eli.billauer@gmail.com> - 2016-04-26 12:50 +0200

#1386883 — [PATCH] char: xillybus: use devm_add_action_or_reset

FromSudip Mukherjee <sudipm.mukherjee@gmail.com>
Date2016-04-25 23:00 +0200
Subject[PATCH] char: xillybus: use devm_add_action_or_reset
Message-ID<rrVLP-3EY-1@gated-at.bofh.it>
If devm_add_action() fails we are explicitly calling dma_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.

Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
 drivers/char/xillybus/xillybus_of.c   | 7 ++-----
 drivers/char/xillybus/xillybus_pcie.c | 7 ++-----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xillybus_of.c
index 7818650..17f45b6 100644
--- a/drivers/char/xillybus/xillybus_of.c
+++ b/drivers/char/xillybus/xillybus_of.c
@@ -101,13 +101,10 @@ static int xilly_map_single_of(struct xilly_endpoint *ep,
 
 	*ret_dma_handle = addr;
 
-	rc = devm_add_action(ep->dev, xilly_of_unmap, this);
+	rc = devm_add_action_or_reset(ep->dev, xilly_of_unmap, this);
 
-	if (rc) {
-		dma_unmap_single(ep->dev, addr, size, direction);
-		kfree(this);
+	if (rc)
 		return rc;
-	}
 
 	return 0;
 }
diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index 9418300..99c688f 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -120,12 +120,9 @@ 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);
+	rc = devm_add_action_or_reset(ep->dev, xilly_pci_unmap, this);
+	if (rc)
 		return rc;
-	}
 
 	return 0;
 }
-- 
1.9.1

[toc] | [next] | [standalone]


#1387355

FromEli Billauer <eli.billauer@gmail.com>
Date2016-04-26 12:50 +0200
Message-ID<rs8J4-691-7@gated-at.bofh.it>
In reply to#1386883
Thanks,

I like the direction, however both xilly_map_single_* functions turn out 
ending with

     if (rc)
         return rc;

     return 0;

Which is equivalent to just "return rc". Or maybe return the value of 
the devm_add_action_or_reset() call directly, and remove the "rc" 
variable? I don't know which one is better coding style.

Could you please take care of that and resubmit? Just want to save 
ourselves another patch that fixes this.

Regards,
    Eli


On 25/04/16 23:51, Sudip Mukherjee wrote:
> If devm_add_action() fails we are explicitly calling dma_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.
>
> Signed-off-by: Sudip Mukherjee<sudip.mukherjee@codethink.co.uk>
> ---
>   drivers/char/xillybus/xillybus_of.c   | 7 ++-----
>   drivers/char/xillybus/xillybus_pcie.c | 7 ++-----
>   2 files changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xillybus_of.c
> index 7818650..17f45b6 100644
> --- a/drivers/char/xillybus/xillybus_of.c
> +++ b/drivers/char/xillybus/xillybus_of.c
> @@ -101,13 +101,10 @@ static int xilly_map_single_of(struct xilly_endpoint *ep,
>
>   	*ret_dma_handle = addr;
>
> -	rc = devm_add_action(ep->dev, xilly_of_unmap, this);
> +	rc = devm_add_action_or_reset(ep->dev, xilly_of_unmap, this);
>
> -	if (rc) {
> -		dma_unmap_single(ep->dev, addr, size, direction);
> -		kfree(this);
> +	if (rc)
>   		return rc;
> -	}
>
>   	return 0;
>   }
> diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
> index 9418300..99c688f 100644
> --- a/drivers/char/xillybus/xillybus_pcie.c
> +++ b/drivers/char/xillybus/xillybus_pcie.c
> @@ -120,12 +120,9 @@ 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);
> +	rc = devm_add_action_or_reset(ep->dev, xilly_pci_unmap, this);
> +	if (rc)
>   		return rc;
> -	}
>
>   	return 0;
>   }
>    

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web