linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] bus: mhi: ep: Fix an ignored error return from ida_alloc()
@ 2022-03-04  0:11 Yang Li
  2022-03-07  7:17 ` Manivannan Sadhasivam
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Li @ 2022-03-04  0:11 UTC (permalink / raw)
  To: mani; +Cc: hemantk, mhi, linux-arm-msm, linux-kernel, Yang Li, Abaci Robot

The return from the call to ida_alloc() is int, it can be a negative
error code, however this is being assigned to an unsigned int variable
'mhi_cntrl->index', so assign the value to 'ret' concurrently to solve
this problem without affecting other functions.

Eliminate the following coccicheck warning:
./drivers/bus/mhi/ep/main.c:1422:5-21: WARNING: Unsigned expression
compared with zero: mhi_cntrl -> index < 0

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 drivers/bus/mhi/ep/main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
index 3e98107f08c4..b27e90d97029 100644
--- a/drivers/bus/mhi/ep/main.c
+++ b/drivers/bus/mhi/ep/main.c
@@ -1418,11 +1418,9 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
 	mhi_ep_mmio_set_env(mhi_cntrl, MHI_EE_AMSS);
 
 	/* Set controller index */
-	mhi_cntrl->index = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
-	if (mhi_cntrl->index < 0) {
-		ret = mhi_cntrl->index;
+	mhi_cntrl->index = ret = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
+	if (ret < 0)
 		goto err_destroy_wq;
-	}
 
 	irq_set_status_flags(mhi_cntrl->irq, IRQ_NOAUTOEN);
 	ret = request_irq(mhi_cntrl->irq, mhi_ep_irq, IRQF_TRIGGER_HIGH,
-- 
2.20.1.7.g153144c


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] bus: mhi: ep: Fix an ignored error return from ida_alloc()
  2022-03-04  0:11 [PATCH -next] bus: mhi: ep: Fix an ignored error return from ida_alloc() Yang Li
@ 2022-03-07  7:17 ` Manivannan Sadhasivam
  0 siblings, 0 replies; 2+ messages in thread
From: Manivannan Sadhasivam @ 2022-03-07  7:17 UTC (permalink / raw)
  To: Yang Li; +Cc: hemantk, mhi, linux-arm-msm, linux-kernel, Abaci Robot

On Fri, Mar 04, 2022 at 08:11:39AM +0800, Yang Li wrote:
> The return from the call to ida_alloc() is int, it can be a negative
> error code, however this is being assigned to an unsigned int variable
> 'mhi_cntrl->index', so assign the value to 'ret' concurrently to solve
> this problem without affecting other functions.
> 
> Eliminate the following coccicheck warning:
> ./drivers/bus/mhi/ep/main.c:1422:5-21: WARNING: Unsigned expression
> compared with zero: mhi_cntrl -> index < 0
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>

Thanks for the fix. Since the MHI EP series is under development, I've
squashed this patch with the original patch that added the offending code.

I'll make a note about this in changelog.

> ---
>  drivers/bus/mhi/ep/main.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
> index 3e98107f08c4..b27e90d97029 100644
> --- a/drivers/bus/mhi/ep/main.c
> +++ b/drivers/bus/mhi/ep/main.c
> @@ -1418,11 +1418,9 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
>  	mhi_ep_mmio_set_env(mhi_cntrl, MHI_EE_AMSS);
>  
>  	/* Set controller index */
> -	mhi_cntrl->index = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
> -	if (mhi_cntrl->index < 0) {
> -		ret = mhi_cntrl->index;
> +	mhi_cntrl->index = ret = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
> +	if (ret < 0)
>  		goto err_destroy_wq;
> -	}

I've just used "ret" for catching the ida_alloc() and assigned it to
index after success.

Thanks,
Mani
>  
>  	irq_set_status_flags(mhi_cntrl->irq, IRQ_NOAUTOEN);
>  	ret = request_irq(mhi_cntrl->irq, mhi_ep_irq, IRQF_TRIGGER_HIGH,
> -- 
> 2.20.1.7.g153144c
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-07  7:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04  0:11 [PATCH -next] bus: mhi: ep: Fix an ignored error return from ida_alloc() Yang Li
2022-03-07  7:17 ` Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).