Skip to contentSkip to conversation

bus: mhi: ep: Fix signedness bug in mhi_ep_register_controller()

PATCH In review Dan Carpenter 3 participants 4 messages Mar 7, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: mhi: ep: Fix signedness bug in mhi_ep_register_controller()

The "mhi_cntrl->index" variable is unsigned so the error handling will not work.

Fixes 10f0ab9c6787 ("bus: mhi: ep: Add support for registering MHI endpoint controllers")
---
 drivers/bus/mhi/ep/main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/bus/mhi/ep/main.c +3 -4
index 3e98107f08c4..879071b021d5 100644
@@ -1418,11 +1418,10 @@ 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;
+	ret = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
+	if (ret < 0)
 		goto err_destroy_wq;
-	}
+	mhi_cntrl->index = ret;
 
 	irq_set_status_flags(mhi_cntrl->irq, IRQ_NOAUTOEN);
 	ret = request_irq(mhi_cntrl->irq, mhi_ep_irq, IRQF_TRIGGER_HIGH,
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

The "mhi_cntrl->index" variable is unsigned so the error handling will not work.

Fixes 10f0ab9c6787 ("bus: mhi: ep: Add support for registering MHI endpoint controllers")

Good fix. Is this code upstream somewhere?

Quoted 23 lines
---
  drivers/bus/mhi/ep/main.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/bus/mhi/ep/main.c +3 -4
index 3e98107f08c4..879071b021d5 100644
@@ -1418,11 +1418,10 @@ 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;
+	ret = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
+	if (ret < 0)
  		goto err_destroy_wq;
-	}
+	mhi_cntrl->index = ret;
 
  	irq_set_status_flags(mhi_cntrl->irq, IRQ_NOAUTOEN);
  	ret = request_irq(mhi_cntrl->irq, mhi_ep_irq, IRQF_TRIGGER_HIGH,
#2 lore raw
Quoted 8 lines · Alex Elder
Quoted 5 lines · Dan Carpenter

The "mhi_cntrl->index" variable is unsigned so the error handling will not work.

Fixes 10f0ab9c6787 ("bus: mhi: ep: Add support for registering MHI endpoint controllers")

Good fix. Is this code upstream somewhere?

It's in linux-next.

regards,
dan carpenter

#3 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

The "mhi_cntrl->index" variable is unsigned so the error handling will not work.

Fixes 10f0ab9c6787 ("bus: mhi: ep: Add support for registering MHI endpoint controllers")

Thanks for the fix! The fix was already added to mhi-next (squashed) as a response to the previous report.

https://lore.kernel.org/mhi/20220307071739.GM12451@workstation/T/#t

Thanks,
Mani

Quoted 26 lines
---
 drivers/bus/mhi/ep/main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/bus/mhi/ep/main.c +3 -4
index 3e98107f08c4..879071b021d5 100644
@@ -1418,11 +1418,10 @@ 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;
+	ret = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
+	if (ret < 0)
 		goto err_destroy_wq;
-	}
+	mhi_cntrl->index = ret;
 
 	irq_set_status_flags(mhi_cntrl->irq, IRQ_NOAUTOEN);
 	ret = request_irq(mhi_cntrl->irq, mhi_ep_irq, IRQF_TRIGGER_HIGH,
Signature · 1 line
2.20.1