[PATCH] crypto: cleanup warning in qm_get_qos_value()

trix@redhat.com posted 1 patch 4 years, 6 months ago
drivers/crypto/hisilicon/qm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] crypto: cleanup warning in qm_get_qos_value()
Posted by trix@redhat.com 4 years, 6 months ago
From: Tom Rix <trix@redhat.com>

Building with clang static analysis returns this warning:

qm.c:4382:11: warning: The left operand of '==' is a garbage value
        if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
            ~~~~ ^

The call to qm_qos_value_init() can return an error without setting
*val.  So check ret before checking *val.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/crypto/hisilicon/qm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index b1fe9c7b8cc89..c906f2e59277b 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -4379,7 +4379,7 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
 		return -EINVAL;
 
 	ret = qm_qos_value_init(val_buf, val);
-	if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
+	if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) {
 		pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
 		return -EINVAL;
 	}
-- 
2.26.3

Re: [PATCH] crypto: cleanup warning in qm_get_qos_value()
Posted by Zhou Wang 4 years, 6 months ago
在 2021/12/22 4:59, trix@redhat.com 写道:
> From: Tom Rix <trix@redhat.com>
> 
> Building with clang static analysis returns this warning:
> 
> qm.c:4382:11: warning: The left operand of '==' is a garbage value
>         if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
>             ~~~~ ^
> 
> The call to qm_qos_value_init() can return an error without setting
> *val.  So check ret before checking *val.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/crypto/hisilicon/qm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index b1fe9c7b8cc89..c906f2e59277b 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -4379,7 +4379,7 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
>  		return -EINVAL;
>  
>  	ret = qm_qos_value_init(val_buf, val);
> -	if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
> +	if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) {
>  		pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
>  		return -EINVAL;
>  	}
> 

Should check return firstly, thanks.

Zhou
Re: [PATCH] crypto: cleanup warning in qm_get_qos_value()
Posted by Nathan Chancellor 4 years, 6 months ago
On Tue, Dec 21, 2021 at 12:59:53PM -0800, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> Building with clang static analysis returns this warning:
> 
> qm.c:4382:11: warning: The left operand of '==' is a garbage value
>         if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
>             ~~~~ ^
> 
> The call to qm_qos_value_init() can return an error without setting
> *val.  So check ret before checking *val.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

Should this have a fixes tag?

Fixes: 72b010dc33b9 ("crypto: hisilicon/qm - supports writing QoS int the host")

> ---
>  drivers/crypto/hisilicon/qm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index b1fe9c7b8cc89..c906f2e59277b 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -4379,7 +4379,7 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
>  		return -EINVAL;
>  
>  	ret = qm_qos_value_init(val_buf, val);
> -	if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
> +	if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) {
>  		pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
>  		return -EINVAL;
>  	}
> -- 
> 2.26.3
> 
Re: [PATCH] crypto: cleanup warning in qm_get_qos_value()
Posted by Tom Rix 4 years, 6 months ago
On 12/21/21 1:31 PM, Nathan Chancellor wrote:
> On Tue, Dec 21, 2021 at 12:59:53PM -0800, trix@redhat.com wrote:
>> From: Tom Rix <trix@redhat.com>
>>
>> Building with clang static analysis returns this warning:
>>
>> qm.c:4382:11: warning: The left operand of '==' is a garbage value
>>          if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
>>              ~~~~ ^
>>
>> The call to qm_qos_value_init() can return an error without setting
>> *val.  So check ret before checking *val.
>>
>> Signed-off-by: Tom Rix <trix@redhat.com>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
>
> Should this have a fixes tag?

I was debating that, the existing if-check will catch this, just not as 
efficiently.

I'll add the line.

Tom

>
> Fixes: 72b010dc33b9 ("crypto: hisilicon/qm - supports writing QoS int the host")
>
>> ---
>>   drivers/crypto/hisilicon/qm.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
>> index b1fe9c7b8cc89..c906f2e59277b 100644
>> --- a/drivers/crypto/hisilicon/qm.c
>> +++ b/drivers/crypto/hisilicon/qm.c
>> @@ -4379,7 +4379,7 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
>>   		return -EINVAL;
>>   
>>   	ret = qm_qos_value_init(val_buf, val);
>> -	if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
>> +	if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) {
>>   		pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
>>   		return -EINVAL;
>>   	}
>> -- 
>> 2.26.3
>>