Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Christian Marangi and committed by
Herbert Xu
21746054 ee509efc

+19 -6
+19 -6
drivers/crypto/inside-secure/eip93/eip93-common.c
··· 202 202 { 203 203 struct scatterlist *src = rctx->sg_src; 204 204 struct scatterlist *dst = rctx->sg_dst; 205 - u32 src_nents, dst_nents; 206 205 u32 textsize = rctx->textsize; 207 206 u32 authsize = rctx->authsize; 208 207 u32 blksize = rctx->blksize; ··· 209 210 u32 totlen_dst = rctx->assoclen + rctx->textsize; 210 211 u32 copy_len; 211 212 bool src_align, dst_align; 213 + int src_nents, dst_nents; 212 214 int err = -EINVAL; 213 215 214 216 if (!IS_CTR(rctx->flags)) { ··· 225 225 } 226 226 227 227 src_nents = sg_nents_for_len(src, totlen_src); 228 + if (src_nents < 0) 229 + return src_nents; 230 + 228 231 dst_nents = sg_nents_for_len(dst, totlen_dst); 232 + if (dst_nents < 0) 233 + return dst_nents; 229 234 230 235 if (src == dst) { 231 236 src_nents = max(src_nents, dst_nents); 232 237 dst_nents = src_nents; 233 - if (unlikely((totlen_src || totlen_dst) && src_nents <= 0)) 238 + if (unlikely((totlen_src || totlen_dst) && !src_nents)) 234 239 return err; 235 240 236 241 } else { 237 - if (unlikely(totlen_src && src_nents <= 0)) 242 + if (unlikely(totlen_src && !src_nents)) 238 243 return err; 239 244 240 - if (unlikely(totlen_dst && dst_nents <= 0)) 245 + if (unlikely(totlen_dst && !dst_nents)) 241 246 return err; 242 247 } 243 248 ··· 278 273 return err; 279 274 } 280 275 281 - rctx->src_nents = sg_nents_for_len(rctx->sg_src, totlen_src); 282 - rctx->dst_nents = sg_nents_for_len(rctx->sg_dst, totlen_dst); 276 + src_nents = sg_nents_for_len(rctx->sg_src, totlen_src); 277 + if (src_nents < 0) 278 + return src_nents; 279 + 280 + dst_nents = sg_nents_for_len(rctx->sg_dst, totlen_dst); 281 + if (dst_nents < 0) 282 + return dst_nents; 283 + 284 + rctx->src_nents = src_nents; 285 + rctx->dst_nents = dst_nents; 283 286 284 287 return 0; 285 288 }