soundwire: qcom: use signed variable for error return
Subsystems (3)
Vinod Koul
maintainerPATCH 1/1 soundwire: qcom: use signed variable for error return
We get warning for using a unsigned variable being compared to less than zero. The comparison is correct as it checks for errors from previous call to qcom_swrm_get_alert_slave_dev_num(), so we should use a signed variable instead.
drivers/soundwire/qcom.c: qcom_swrm_irq_handler() warn: impossible condition '(devnum < 0) => (0-255 < 0)'
--- drivers/soundwire/qcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/qcom.c +1 -1
@@ -428,7 +428,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id)struct qcom_swrm_ctrl *swrm = dev_id;u32 value, intr_sts, intr_sts_masked, slave_status;u32 i; -u8 devnum =0 ; +s8 devnum =0 ;int ret =IRQ_HANDLED ; swrm->reg_read (swrm,SWRM_INTERRUPT_STATUS , &intr_sts);
Signature · 1 line
2.26.3
Quoted 19 lines · Vinod Koul
We get warning for using a unsigned variable being compared to less than zero. The comparison is correct as it checks for errors from previous call to
qcom_swrm_get_alert_slave_dev_num(), so we should use a signed variable instead.
drivers/soundwire/qcom.c:qcom_swrm_irq_handler()warn: impossible condition '(devnum < 0) => (0-255 < 0)'Reported-by kernel test robot <[email protected]>Signed-off-by Vinod Koul <[email protected]>--- drivers/soundwire/qcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soundwire/qcom.c +0
-0
drivers/soundwire/qcom.c static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) · line 431
Quoted 5 lines
drivers/soundwire/qcom.c +1
-1@@ -428,7 +428,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id)struct qcom_swrm_ctrl *swrm = dev_id;u32 value, intr_sts, intr_sts_masked, slave_status;u32 i; -u8 devnum =0 ; +s8 devnum =0 ;
it's not great to store negative error codes with s8. That works in this specific case because the function only returns -EINVAL.
We actually have zero occurrences of s8 in the drivers/soundwire/ code.
Quoted 4 lines
drivers/soundwire/qcom.c +0
-0int ret =IRQ_HANDLED ; swrm->reg_read (swrm,SWRM_INTERRUPT_STATUS , &intr_sts);
Vinod Koul
maintainerQuoted 17 lines · Pierre-Louis Bossart
Quoted 14 lines · Vinod Koul
We get warning for using a unsigned variable being compared to less than zero. The comparison is correct as it checks for errors from previous call to
qcom_swrm_get_alert_slave_dev_num(), so we should use a signed variable instead.
drivers/soundwire/qcom.c:qcom_swrm_irq_handler()warn: impossible condition '(devnum < 0) => (0-255 < 0)'Reported-by kernel test robot <[email protected]>Signed-off-by Vinod Koul <[email protected]>--- drivers/soundwire/qcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
drivers/soundwire/qcom.c static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) · line 431
Quoted 10 lines
drivers/soundwire/qcom.c +1
-1@@ -428,7 +428,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id)struct qcom_swrm_ctrl *swrm = dev_id;u32 value, intr_sts, intr_sts_masked, slave_status;u32 i; -u8 devnum =0 ; +s8 devnum =0 ;it's not great to store negative error codes with s8. That works in this specific case because the function only returns
-EINVAL.
Yeah I did check EINVAL was the case which would work but in general I agree that makes sense, I discussed with Srini on IRC and looks like I havent posted v2, should hit the pipes shortly
Signature · 1 line
~Vinod
Quoted 19 lines · Vinod Koul
We get warning for using a unsigned variable being compared to less than zero. The comparison is correct as it checks for errors from previous call to
qcom_swrm_get_alert_slave_dev_num(), so we should use a signed variable instead.
drivers/soundwire/qcom.c:qcom_swrm_irq_handler()warn: impossible condition '(devnum < 0) => (0-255 < 0)'Reported-by kernel test robot <[email protected]>Signed-off-by Vinod Koul <[email protected]>--- drivers/soundwire/qcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soundwire/qcom.c +0
-0
drivers/soundwire/qcom.c static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) · line 431
Quoted 5 lines
drivers/soundwire/qcom.c +1
-1@@ -428,7 +428,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id)struct qcom_swrm_ctrl *swrm = dev_id;u32 value, intr_sts, intr_sts_masked, slave_status;u32 i; -u8 devnum =0 ; +s8 devnum =0 ;
At least in today's linux-next qcom_swrm_get_alert_slave_dev_num() returns an int and the code only checks to see if this is negative. So it seems like making this a full int ensures there's no truncation etc.
And at least as written today there's no need to initialize the variable.
Regards,
Bjorn
Quoted 6 lines
drivers/soundwire/qcom.c +0
-0int ret =IRQ_HANDLED ; swrm->reg_read (swrm,SWRM_INTERRUPT_STATUS , &intr_sts);Signature · 1 line
2.26.3