Skip to contentSkip to conversation

crypto: bfin_crc: ignore duplicated registration of the same algorithm

PATCH Superseded Sonic Zhang 2 participants 2 messages Apr 11, 2014 Crypto API

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 crypto: bfin_crc: ignore duplicated registration of the same algorithm

From: Sonic Zhang <[email protected]>

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

---
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(-)
drivers/crypto/bfin_crc.c +14 -11
index cea3e8c..7154d68 100644
@@ -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");
 
Signature · 1 line
1.8.2.3
Reviewed-by on v2 1/2
#1 lore raw
Quoted 20 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

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

---
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(-)
drivers/crypto/bfin_crc.c +0 -0
index cea3e8c..7154d68 100644
@@ -665,20 +665,23 @@ static int bfin_crypto_crc_probe(struct
 platform_device *pdev) if (timeout == 0)

drivers/crypto/bfin_crc.c static int bfin_crypto_crc_probe(struct · line 672

Quoted 10 lines
drivers/crypto/bfin_crc.c +3 -3
 		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

Best regards,
Marek Vasut