Skip to contentSkip to conversation

crypto: qce - simplify devm_qce_register_algs

PATCH In review Thorsten Blum 2 participants 3 messages Jul 31 – Aug 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 crypto: qce - simplify devm_qce_register_algs

Drop the redundant ret = -ENODEV initialization. Use a while loop and reuse the local index variable i on the error path.

---
 drivers/crypto/qce/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/qce/core.c +3 -3
index ea5b9689ce68..a848fd58a354 100644
@@ -51,14 +51,14 @@ static void qce_unregister_algs(void *data)
 static int devm_qce_register_algs(struct qce_device *qce)
 {
 	const struct qce_algo_ops *ops;
-	int i, j, ret = -ENODEV;
+	int i, ret;
 
 	for (i = 0; i < ARRAY_SIZE(qce_ops); i++) {
 		ops = qce_ops[i];
 		ret = ops->register_algs(qce);
 		if (ret) {
-			for (j = i - 1; j >= 0; j--)
-				qce_ops[j]->unregister_algs(qce);
+			while (i--)
+				qce_ops[i]->unregister_algs(qce);
 			return ret;
 		}
 	}
#1 lore raw

PATCH 2/2 crypto: qce - simplify qce_handle_request

Simplify the for loop's control flow and return the results directly.

---
 drivers/crypto/qce/core.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/crypto/qce/core.c +4 -6
index a848fd58a354..dc05f2b9d52e 100644
@@ -68,19 +68,17 @@ static int devm_qce_register_algs(struct qce_device *qce)
 
 static int qce_handle_request(struct crypto_async_request *async_req)
 {
-	int ret = -EINVAL, i;
+	int i;
 	const struct qce_algo_ops *ops;
 	u32 type = crypto_tfm_alg_type(async_req->tfm);
 
 	for (i = 0; i < ARRAY_SIZE(qce_ops); i++) {
 		ops = qce_ops[i];
-		if (type != ops->type)
-			continue;
-		ret = ops->async_req_handle(async_req);
-		break;
+		if (type == ops->type)
+			return ops->async_req_handle(async_req);
 	}
 
-	return ret;
+	return -EINVAL;
 }
 
 static int qce_handle_queue(struct qce_device *qce,
maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 7 lines · Thorsten Blum

Drop the redundant ret = -ENODEV initialization. Use a while loop and reuse the local index variable i on the error path.

---
 drivers/crypto/qce/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt