Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: pata_sil680: fix result type of sil680_sel{dev|reg}()

sil680_sel{dev|reg}() return a PCI config space address but needlessly
use the *unsigned long* type for that, whereas the PCI config space
accessors take *int* for the address parameter. Switch these functions
to returning *int*, updating the local variables at their call sites.
Get rid of the 'base' local variables in these functions, while at it...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static
analysis tool.

Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

authored by

Sergey Shtylyov and committed by
Damien Le Moal
dafbbf5c a28c1ab3

+13 -17
+13 -17
drivers/ata/pata_sil680.c
··· 47 47 * criticial. 48 48 */ 49 49 50 - static unsigned long sil680_selreg(struct ata_port *ap, int r) 50 + static int sil680_selreg(struct ata_port *ap, int r) 51 51 { 52 - unsigned long base = 0xA0 + r; 53 - base += (ap->port_no << 4); 54 - return base; 52 + return 0xA0 + (ap->port_no << 4) + r; 55 53 } 56 54 57 55 /** ··· 63 65 * the unit shift. 64 66 */ 65 67 66 - static unsigned long sil680_seldev(struct ata_port *ap, struct ata_device *adev, int r) 68 + static int sil680_seldev(struct ata_port *ap, struct ata_device *adev, int r) 67 69 { 68 - unsigned long base = 0xA0 + r; 69 - base += (ap->port_no << 4); 70 - base |= adev->devno ? 2 : 0; 71 - return base; 70 + return 0xA0 + (ap->port_no << 4) + r + (adev->devno << 1); 72 71 } 73 72 74 73 ··· 80 85 static int sil680_cable_detect(struct ata_port *ap) 81 86 { 82 87 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 83 - unsigned long addr = sil680_selreg(ap, 0); 88 + int addr = sil680_selreg(ap, 0); 84 89 u8 ata66; 90 + 85 91 pci_read_config_byte(pdev, addr, &ata66); 86 92 if (ata66 & 1) 87 93 return ATA_CBL_PATA80; ··· 109 113 0x328A, 0x2283, 0x1281, 0x10C3, 0x10C1 110 114 }; 111 115 112 - unsigned long tfaddr = sil680_selreg(ap, 0x02); 113 - unsigned long addr = sil680_seldev(ap, adev, 0x04); 114 - unsigned long addr_mask = 0x80 + 4 * ap->port_no; 116 + int tfaddr = sil680_selreg(ap, 0x02); 117 + int addr = sil680_seldev(ap, adev, 0x04); 118 + int addr_mask = 0x80 + 4 * ap->port_no; 115 119 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 116 120 int pio = adev->pio_mode - XFER_PIO_0; 117 121 int lowest_pio = pio; ··· 161 165 static const u16 dma_table[3] = { 0x2208, 0x10C2, 0x10C1 }; 162 166 163 167 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 164 - unsigned long ma = sil680_seldev(ap, adev, 0x08); 165 - unsigned long ua = sil680_seldev(ap, adev, 0x0C); 166 - unsigned long addr_mask = 0x80 + 4 * ap->port_no; 168 + int ma = sil680_seldev(ap, adev, 0x08); 169 + int ua = sil680_seldev(ap, adev, 0x0C); 170 + int addr_mask = 0x80 + 4 * ap->port_no; 167 171 int port_shift = adev->devno * 4; 168 172 u8 scsc, mode; 169 173 u16 multi, ultra; ··· 215 219 static bool sil680_sff_irq_check(struct ata_port *ap) 216 220 { 217 221 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 218 - unsigned long addr = sil680_selreg(ap, 1); 222 + int addr = sil680_selreg(ap, 1); 219 223 u8 val; 220 224 221 225 pci_read_config_byte(pdev, addr, &val);