2015-11-18 23:06:50

by Dan Carpenter

[permalink] [raw]
Subject: re: crypto: sahara - check return value of sg_nents_for_len

Hello LABBE Corentin,

The patch 6c2b74d4774f: "crypto: sahara - check return value of
sg_nents_for_len" from Nov 4, 2015, leads to the following static
checker warning:

drivers/crypto/sahara.c:480 sahara_hw_descriptor_create()
warn: unsigned 'dev->nb_in_sg' is never less than zero.

drivers/crypto/sahara.c
479 dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total);
480 if (dev->nb_in_sg < 0) {
^^^^^^^^^^^^^^^^^
Unsigned is never less than zero.

481 dev_err(dev->device, "Invalid numbers of src SG.\n");
482 return dev->nb_in_sg;
483 }

There are several other similar bugs as well:

drivers/crypto/sahara.c:485 sahara_hw_descriptor_create() warn: unsigned 'dev->nb_out_sg' is never less than zero.
drivers/crypto/sahara.c:804 sahara_sha_hw_links_create() warn: unsigned 'dev->nb_in_sg' is never less than zero.
drivers/crypto/picoxcell_crypto.c:298 spacc_sg_to_ddt() warn: unsigned 'nents' is never less than zero.
drivers/crypto/picoxcell_crypto.c:338 spacc_aead_make_ddts() warn: unsigned 'src_nents' is never less than zero.
drivers/crypto/picoxcell_crypto.c:348 spacc_aead_make_ddts() warn: unsigned 'dst_nents' is never less than zero.

regards,
dan carpenter


2015-11-19 09:30:29

by Corentin Labbe

[permalink] [raw]
Subject: Re: crypto: sahara - check return value of sg_nents_for_len

On Thu, Nov 19, 2015 at 02:06:42AM +0300, Dan Carpenter wrote:
> Hello LABBE Corentin,
>
> The patch 6c2b74d4774f: "crypto: sahara - check return value of
> sg_nents_for_len" from Nov 4, 2015, leads to the following static
> checker warning:
>
> drivers/crypto/sahara.c:480 sahara_hw_descriptor_create()
> warn: unsigned 'dev->nb_in_sg' is never less than zero.
>
> drivers/crypto/sahara.c
> 479 dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total);
> 480 if (dev->nb_in_sg < 0) {
> ^^^^^^^^^^^^^^^^^
> Unsigned is never less than zero.
>
> 481 dev_err(dev->device, "Invalid numbers of src SG.\n");
> 482 return dev->nb_in_sg;
> 483 }
>
> There are several other similar bugs as well:
>
> drivers/crypto/sahara.c:485 sahara_hw_descriptor_create() warn: unsigned 'dev->nb_out_sg' is never less than zero.
> drivers/crypto/sahara.c:804 sahara_sha_hw_links_create() warn: unsigned 'dev->nb_in_sg' is never less than zero.
> drivers/crypto/picoxcell_crypto.c:298 spacc_sg_to_ddt() warn: unsigned 'nents' is never less than zero.
> drivers/crypto/picoxcell_crypto.c:338 spacc_aead_make_ddts() warn: unsigned 'src_nents' is never less than zero.
> drivers/crypto/picoxcell_crypto.c:348 spacc_aead_make_ddts() warn: unsigned 'dst_nents' is never less than zero.
>
> regards,
> dan carpenter

Thanks for the reporting

I will send a patch for solving this.

Regards