Message ID | 20190219063302.22888-1-yuehaibing@huawei.com (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Herbert Xu |
Headers | show |
Series | [-next] hwrng: Fix unsigned comparison with less than zero | expand |
On Tue, 19 Feb 2019 at 12:04, YueHaibing <yuehaibing@huawei.com> wrote: > > The return from the call to tee_client_invoke_func can be a > negative error code however this is being assigned to an > unsigned variable 'ret' hence the check is always false. > Fix this by making 'ret' an int. > > Detected by Coccinelle ("Unsigned expression compared with zero: > ret < 0") > > Fixes: 5fe8b1cc6a03 ("hwrng: add OP-TEE based rng driver") > Signed-off-by: YueHaibing <yuehaibing@huawei.com> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> > --- > drivers/char/hw_random/optee-rng.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/char/hw_random/optee-rng.c b/drivers/char/hw_random/optee-rng.c > index 2b9fc8a..e9f4e10 100644 > --- a/drivers/char/hw_random/optee-rng.c > +++ b/drivers/char/hw_random/optee-rng.c > @@ -73,7 +73,7 @@ struct optee_rng_private { > static size_t get_optee_rng_data(struct optee_rng_private *pvt_data, > void *buf, size_t req_size) > { > - u32 ret = 0; > + int ret = 0; > u8 *rng_data = NULL; > size_t rng_size = 0; > struct tee_ioctl_invoke_arg inv_arg = {0}; > @@ -172,7 +172,7 @@ static struct optee_rng_private pvt_data = { > > static int get_optee_rng_info(struct device *dev) > { > - u32 ret = 0; > + int ret = 0; > struct tee_ioctl_invoke_arg inv_arg = {0}; > struct tee_param param[4] = {0}; > > -- > 2.7.0 > >
diff --git a/drivers/char/hw_random/optee-rng.c b/drivers/char/hw_random/optee-rng.c index 2b9fc8a..e9f4e10 100644 --- a/drivers/char/hw_random/optee-rng.c +++ b/drivers/char/hw_random/optee-rng.c @@ -73,7 +73,7 @@ struct optee_rng_private { static size_t get_optee_rng_data(struct optee_rng_private *pvt_data, void *buf, size_t req_size) { - u32 ret = 0; + int ret = 0; u8 *rng_data = NULL; size_t rng_size = 0; struct tee_ioctl_invoke_arg inv_arg = {0}; @@ -172,7 +172,7 @@ static struct optee_rng_private pvt_data = { static int get_optee_rng_info(struct device *dev) { - u32 ret = 0; + int ret = 0; struct tee_ioctl_invoke_arg inv_arg = {0}; struct tee_param param[4] = {0};
The return from the call to tee_client_invoke_func can be a negative error code however this is being assigned to an unsigned variable 'ret' hence the check is always false. Fix this by making 'ret' an int. Detected by Coccinelle ("Unsigned expression compared with zero: ret < 0") Fixes: 5fe8b1cc6a03 ("hwrng: add OP-TEE based rng driver") Signed-off-by: YueHaibing <yuehaibing@huawei.com> --- drivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)