Commit 21746054 authored by Christian Marangi's avatar Christian Marangi Committed by Herbert Xu
Browse files

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: 9739f5f9 ("crypto: eip93 - Add Inside Secure SafeXcel EIP-93 crypto engine support")
Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarChristian Marangi <ansuelsmth@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ee509efc
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -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;
}