spi/xilinx: signedness issue checking platform_get_irq()
Subsystems (3)
PATCH 1/1 spi/xilinx: signedness issue checking platform_get_irq()
"xspi->irq" is unsigned int so it's never less than zero. I have added a cast.
drivers/spi/spi-xilinx.c +1 -1
@@ -442,7 +442,7 @@ static int xilinx_spi_probe(struct platform_device *pdev)xspi_init_hw (xspi); xspi->irq =platform_get_irq (pdev,0 ); -if (xspi->irq <0 ) { +if ((int )xspi->irq <0 ) { ret = xspi->irq; goto put_master; }
Quoted 2 lines · Dan Carpenter
"
xspi->irq" is unsigned int so it's never less than zero. I have added a cast.
Um. Doesn't this just hide a warning, not solve the problem? If the value can't be negative, so the if condition never fires, then the cast won't change that...
Quoted 7 lines · Stephen Warren
Quoted 2 lines · Dan Carpenter
"
xspi->irq" is unsigned int so it's never less than zero. I have added a cast.Um. Doesn't this just hide a warning, not solve the problem? If the value can't be negative, so the if condition never fires, then the cast won't change that...
No. It fixes the problem but Mark is right that it's ugly. Sorry for that. I will resend.
regards,
dan carpenter
A message that is not in the archive (sent off-list or not yet received): [email protected]
Mark Brown
maintainerQuoted 2 lines · Dan Carpenter
"
xspi->irq" is unsigned int so it's never less than zero. I have added a cast.
Why is this better than changing irq to a signed type?
PATCH v2 1/1 spi/xilinx: signedness issue checking platform_get_irq()
In xilinx_spi_probe() we use xspi->irq to store negative error codes so it has to be signed. We weren't going to use the upper bit any way so this is fine.
---
v2: The first version introduced an ugly cast. Sorry for that.
drivers/spi/spi-xilinx.c +1 -1
@@ -82,7 +82,7 @@ struct xilinx_spi {struct completion done;void __iomem *regs;/* virt. address of the control registers */ -u32 irq; +int irq;u8 *rx_ptr;/* pointer in the Tx buffer */ const u8 *tx_ptr;/* pointer in the Rx buffer */
Quoted 3 lines · Dan Carpenter
In
xilinx_spi_probe()we usexspi->irqto store negative error codes so it has to be signed. We weren't going to use the upper bit any way so this is fine.
Applied, thanks.