Skip to contentSkip to conversation

spi/xilinx: signedness issue checking platform_get_irq()

PATCH Superseded Dan Carpenter 3 participants 6 messages Jul 17, 2013 1 message not in the archive

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

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
index fea815c..e5201fb 100644
@@ -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;
 	}
#1 lore raw
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...

#2 lore raw
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]

maintainer
#4 lore raw
Quoted 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?

#5 lore raw

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
index fea815c..0f4a093 100644
@@ -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 */
maintainer Applied
#6 lore raw
Quoted 3 lines · Dan Carpenter

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.

Applied, thanks.