Skip to contentSkip to conversation

crypto: inside-secure: eip93: Correctly handle return of for sg_nents_for_len

PATCH In review Christian Marangi 2 participants 2 messages Feb 15, 2025 – Feb 21, 2025

Subsystems (3)
lore
Share & tools
lore

Christian Marangi

author maintainer
#0 lore raw

PATCH 1/1 crypto: inside-secure: eip93: Correctly handle return of for sg_nents_for_len

Fix smatch warning for sg_nents_for_len return value in Inside Secure EIP93 driver.

The return value of sg_nents_for_len was assigned to an u32 and the error was ignored and converted to a positive integer.

Rework the code to correctly handle the error from sg_nents_for_len to mute smatch warning.

Fixes 9739f5f93b78 ("crypto: eip93 - Add Inside Secure SafeXcel EIP-93 crypto engine support")
---
 .../crypto/inside-secure/eip93/eip93-common.c | 25 ++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/crypto/inside-secure/eip93/eip93-common.c +19 -6
index 446a047c242d..66153aa2493f 100644
@@ -202,7 +202,6 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 {
 	struct scatterlist *src = rctx->sg_src;
 	struct scatterlist *dst = rctx->sg_dst;
-	u32 src_nents, dst_nents;
 	u32 textsize = rctx->textsize;
 	u32 authsize = rctx->authsize;
 	u32 blksize = rctx->blksize;
@@ -210,6 +209,7 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 	u32 totlen_dst = rctx->assoclen + rctx->textsize;
 	u32 copy_len;
 	bool src_align, dst_align;
+	int src_nents, dst_nents;
 	int err = -EINVAL;
 
 	if (!IS_CTR(rctx->flags)) {
@@ -225,19 +225,24 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 	}
 
 	src_nents = sg_nents_for_len(src, totlen_src);
+	if (src_nents < 0)
+		return src_nents;
+
 	dst_nents = sg_nents_for_len(dst, totlen_dst);
+	if (dst_nents < 0)
+		return dst_nents;
 
 	if (src == dst) {
 		src_nents = max(src_nents, dst_nents);
 		dst_nents = src_nents;
-		if (unlikely((totlen_src || totlen_dst) && src_nents <= 0))
+		if (unlikely((totlen_src || totlen_dst) && !src_nents))
 			return err;
 
 	} else {
-		if (unlikely(totlen_src && src_nents <= 0))
+		if (unlikely(totlen_src && !src_nents))
 			return err;
 
-		if (unlikely(totlen_dst && dst_nents <= 0))
+		if (unlikely(totlen_dst && !dst_nents))
 			return err;
 	}
 
@@ -273,8 +278,16 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 			return err;
 	}
 
-	rctx->src_nents = sg_nents_for_len(rctx->sg_src, totlen_src);
-	rctx->dst_nents = sg_nents_for_len(rctx->sg_dst, totlen_dst);
+	src_nents = sg_nents_for_len(rctx->sg_src, totlen_src);
+	if (src_nents < 0)
+		return src_nents;
+
+	dst_nents = sg_nents_for_len(rctx->sg_dst, totlen_dst);
+	if (dst_nents < 0)
+		return dst_nents;
+
+	rctx->src_nents = src_nents;
+	rctx->dst_nents = dst_nents;
 
 	return 0;
 }
Signature · 1 line
2.47.1
maintainer
#1 lore raw
Quoted 9 lines · Christian Marangi

Fix smatch warning for sg_nents_for_len return value in Inside Secure EIP93 driver.

The return value of sg_nents_for_len was assigned to an u32 and the error was ignored and converted to a positive integer.

Rework the code to correctly handle the error from sg_nents_for_len to mute smatch warning.

Quoted 6 lines
Fixes 9739f5f93b78 ("crypto: eip93 - Add Inside Secure SafeXcel EIP-93 crypto engine support")
---
 .../crypto/inside-secure/eip93/eip93-common.c | 25 ++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)

Patch 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