linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] crypto: bfin_crc: ignore duplicated registration of the same algorithm
@ 2014-04-11  5:10 Sonic Zhang
  2014-04-11  7:47 ` Marek Vasut
  0 siblings, 1 reply; 2+ messages in thread
From: Sonic Zhang @ 2014-04-11  5:10 UTC (permalink / raw)
  To: Marek Vasut, Herbert Xu; +Cc: linux-crypto, adi-buildroot-devel, Sonic Zhang

From: Sonic Zhang <sonic.zhang@analog.com>

in case of multiple crc devices are probed.
Call platform_set_drvdata() before adding new CRC device into the list.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
v2-chagnes:
- check the CRC list and avoid call crypto_register_ahash() if not empty
- move platform_set_drvdata() before adding CRC device into the list

 drivers/crypto/bfin_crc.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/bfin_crc.c b/drivers/crypto/bfin_crc.c
index cea3e8c..7154d68 100644
--- a/drivers/crypto/bfin_crc.c
+++ b/drivers/crypto/bfin_crc.c
@@ -665,20 +665,23 @@ static int bfin_crypto_crc_probe(struct platform_device *pdev)
 	if (timeout == 0)
 		dev_info(&pdev->dev, "init crc poly timeout\n");
 
+	platform_set_drvdata(pdev, crc);
+
 	spin_lock(&crc_list.lock);
-	list_add(&crc->list, &crc_list.dev_list);
-	spin_unlock(&crc_list.lock);
 
-	platform_set_drvdata(pdev, crc);
+	if (list_empty(&crc_list.dev_list)) {
+		list_add(&crc->list, &crc_list.dev_list);
+		ret = crypto_register_ahash(&algs);
+		if (ret) {
+			spin_unlock(&crc_list.lock);
+			dev_err(&pdev->dev,
+				"Cann't register crypto ahash device\n");
+			goto out_error_dma;
+		}
+	} else
+		list_add(&crc->list, &crc_list.dev_list);
 
-	ret = crypto_register_ahash(&algs);
-	if (ret) {
-		spin_lock(&crc_list.lock);
-		list_del(&crc->list);
-		spin_unlock(&crc_list.lock);
-		dev_err(&pdev->dev, "Cann't register crypto ahash device\n");
-		goto out_error_dma;
-	}
+	spin_unlock(&crc_list.lock);
 
 	dev_info(&pdev->dev, "initialized\n");
 
-- 
1.8.2.3

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

* Re: [PATCH v2 1/2] crypto: bfin_crc: ignore duplicated registration of the same algorithm
  2014-04-11  5:10 [PATCH v2 1/2] crypto: bfin_crc: ignore duplicated registration of the same algorithm Sonic Zhang
@ 2014-04-11  7:47 ` Marek Vasut
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2014-04-11  7:47 UTC (permalink / raw)
  To: Sonic Zhang; +Cc: Herbert Xu, linux-crypto, adi-buildroot-devel, Sonic Zhang

On Friday, April 11, 2014 at 07:10:24 AM, Sonic Zhang wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>
> 
> in case of multiple crc devices are probed.
> Call platform_set_drvdata() before adding new CRC device into the list.
> 
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
> ---
> v2-chagnes:
> - check the CRC list and avoid call crypto_register_ahash() if not empty
> - move platform_set_drvdata() before adding CRC device into the list
> 
>  drivers/crypto/bfin_crc.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/crypto/bfin_crc.c b/drivers/crypto/bfin_crc.c
> index cea3e8c..7154d68 100644
> --- a/drivers/crypto/bfin_crc.c
> +++ b/drivers/crypto/bfin_crc.c
> @@ -665,20 +665,23 @@ static int bfin_crypto_crc_probe(struct
> platform_device *pdev) if (timeout == 0)
>  		dev_info(&pdev->dev, "init crc poly timeout\n");
> 
> +	platform_set_drvdata(pdev, crc);
> +
>  	spin_lock(&crc_list.lock);
> -	list_add(&crc->list, &crc_list.dev_list);
> -	spin_unlock(&crc_list.lock);
> 
> -	platform_set_drvdata(pdev, crc);
> +	if (list_empty(&crc_list.dev_list)) {

Try the following, which would remove the need for the else{} branch altogether:

list_add(...);
if (list_is_singular(...)) {
  crypto_register_....
  ...
}


Other than that

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

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

end of thread, other threads:[~2014-04-11  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-11  5:10 [PATCH v2 1/2] crypto: bfin_crc: ignore duplicated registration of the same algorithm Sonic Zhang
2014-04-11  7:47 ` Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).