Skip to content

Commit baf8855

Browse files
arndbgregkh
authored andcommitted
staging: gpib: fix address space mixup
Throughout the gpib drivers, a 'void *' struct member is used in place of either port numbers or __iomem pointers, which leads to lots of extra type casts, sparse warnings and less portable code. Split the struct member in two separate ones with the correct types, so each driver can pick which one to use. Signed-off-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fec866a commit baf8855

File tree

22 files changed

+123
-116
lines changed

22 files changed

+123
-116
lines changed

drivers/staging/gpib/agilent_82350b/agilent_82350b.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ static int agilent_82350b_generic_attach(gpib_board_t *board, const gpib_board_c
700700
GPIB_82350A_REGION));
701701
dev_dbg(board->gpib_dev, "%s: gpib base address remapped to 0x%p\n",
702702
driver_name, a_priv->gpib_base);
703-
tms_priv->iobase = a_priv->gpib_base + TMS9914_BASE_REG;
703+
tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;
704704
a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device,
705705
SRAM_82350A_REGION),
706706
pci_resource_len(a_priv->pci_device,
@@ -724,7 +724,7 @@ static int agilent_82350b_generic_attach(gpib_board_t *board, const gpib_board_c
724724
pci_resource_len(a_priv->pci_device, GPIB_REGION));
725725
dev_dbg(board->gpib_dev, "%s: gpib base address remapped to 0x%p\n",
726726
driver_name, a_priv->gpib_base);
727-
tms_priv->iobase = a_priv->gpib_base + TMS9914_BASE_REG;
727+
tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;
728728
a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device, SRAM_REGION),
729729
pci_resource_len(a_priv->pci_device, SRAM_REGION));
730730
dev_dbg(board->gpib_dev, "%s: sram base address remapped to 0x%p\n",

drivers/staging/gpib/cb7210/cb7210.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,12 @@ int cb_pci_attach(gpib_board_t *board, const gpib_board_config_t *config)
971971
switch (cb_priv->pci_chip) {
972972
case PCI_CHIP_AMCC_S5933:
973973
cb_priv->amcc_iobase = pci_resource_start(cb_priv->pci_device, 0);
974-
nec_priv->iobase = (void *)(pci_resource_start(cb_priv->pci_device, 1));
974+
nec_priv->iobase = pci_resource_start(cb_priv->pci_device, 1);
975975
cb_priv->fifo_iobase = pci_resource_start(cb_priv->pci_device, 2);
976976
break;
977977
case PCI_CHIP_QUANCOM:
978-
nec_priv->iobase = (void *)(pci_resource_start(cb_priv->pci_device, 0));
979-
cb_priv->fifo_iobase = (unsigned long)nec_priv->iobase;
978+
nec_priv->iobase = pci_resource_start(cb_priv->pci_device, 0);
979+
cb_priv->fifo_iobase = nec_priv->iobase;
980980
break;
981981
default:
982982
pr_err("cb7210: bug! unhandled pci_chip=%i\n", cb_priv->pci_chip);
@@ -1040,8 +1040,8 @@ int cb_isa_attach(gpib_board_t *board, const gpib_board_config_t *config)
10401040
return retval;
10411041
cb_priv = board->private_data;
10421042
nec_priv = &cb_priv->nec7210_priv;
1043-
if (request_region((unsigned long)config->ibbase, cb7210_iosize, "cb7210") == 0) {
1044-
pr_err("gpib: ioports starting at 0x%p are already in use\n", config->ibbase);
1043+
if (request_region(config->ibbase, cb7210_iosize, "cb7210") == 0) {
1044+
pr_err("gpib: ioports starting at 0x%u are already in use\n", config->ibbase);
10451045
return -EIO;
10461046
}
10471047
nec_priv->iobase = config->ibbase;
@@ -1471,7 +1471,7 @@ int cb_pcmcia_attach(gpib_board_t *board, const gpib_board_config_t *config)
14711471
(unsigned long)curr_dev->resource[0]->start);
14721472
return -EIO;
14731473
}
1474-
nec_priv->iobase = (void *)(unsigned long)curr_dev->resource[0]->start;
1474+
nec_priv->iobase = curr_dev->resource[0]->start;
14751475
cb_priv->fifo_iobase = curr_dev->resource[0]->start;
14761476

14771477
if (request_irq(curr_dev->irq, cb7210_interrupt, IRQF_SHARED,

drivers/staging/gpib/cb7210/cb7210.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ enum hs_regs {
113113
HS_STATUS = 0x8, /* HS_STATUS register */
114114
};
115115

116-
static inline unsigned long nec7210_iobase(const struct cb7210_priv *cb_priv)
116+
static inline u32 nec7210_iobase(const struct cb7210_priv *cb_priv)
117117
{
118-
return (unsigned long)(cb_priv->nec7210_priv.iobase);
118+
return cb_priv->nec7210_priv.iobase;
119119
}
120120

121121
static inline int cb7210_page_in_bits(unsigned int page)

drivers/staging/gpib/cec/cec_gpib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ int cec_pci_attach(gpib_board_t *board, const gpib_board_config_t *config)
297297

298298
cec_priv->plx_iobase = pci_resource_start(cec_priv->pci_device, 1);
299299
pr_info(" plx9050 base address 0x%lx\n", cec_priv->plx_iobase);
300-
nec_priv->iobase = (void *)(pci_resource_start(cec_priv->pci_device, 3));
301-
pr_info(" nec7210 base address 0x%p\n", nec_priv->iobase);
300+
nec_priv->iobase = pci_resource_start(cec_priv->pci_device, 3);
301+
pr_info(" nec7210 base address 0x%x\n", nec_priv->iobase);
302302

303303
isr_flags |= IRQF_SHARED;
304304
if (request_irq(cec_priv->pci_device->irq, cec_interrupt, isr_flags, "pci-gpib", board)) {

drivers/staging/gpib/common/gpib_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ static int iobase_ioctl(gpib_board_config_t *config, unsigned long arg)
15731573

15741574
if (WARN_ON_ONCE(sizeof(void *) > sizeof(base_addr)))
15751575
return -EFAULT;
1576-
config->ibbase = (void *)(unsigned long)(base_addr);
1576+
config->ibbase = base_addr;
15771577

15781578
return 0;
15791579
}

drivers/staging/gpib/eastwood/fluke_gpib.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,12 +1011,12 @@ static int fluke_attach_impl(gpib_board_t *board, const gpib_board_config_t *con
10111011
}
10121012
e_priv->gpib_iomem_res = res;
10131013

1014-
nec_priv->iobase = ioremap(e_priv->gpib_iomem_res->start,
1014+
nec_priv->mmiobase = ioremap(e_priv->gpib_iomem_res->start,
10151015
resource_size(e_priv->gpib_iomem_res));
1016-
pr_info("gpib: iobase %lx remapped to %p, length=%d\n",
1017-
(unsigned long)e_priv->gpib_iomem_res->start,
1018-
nec_priv->iobase, (int)resource_size(e_priv->gpib_iomem_res));
1019-
if (!nec_priv->iobase) {
1016+
pr_info("gpib: mmiobase %llx remapped to %p, length=%d\n",
1017+
(u64)e_priv->gpib_iomem_res->start,
1018+
nec_priv->mmiobase, (int)resource_size(e_priv->gpib_iomem_res));
1019+
if (!nec_priv->mmiobase) {
10201020
dev_err(&fluke_gpib_pdev->dev, "Could not map I/O memory\n");
10211021
return -ENOMEM;
10221022
}
@@ -1107,7 +1107,7 @@ void fluke_detach(gpib_board_t *board)
11071107
gpib_free_pseudo_irq(board);
11081108
nec_priv = &e_priv->nec7210_priv;
11091109

1110-
if (nec_priv->iobase) {
1110+
if (nec_priv->mmiobase) {
11111111
fluke_paged_write_byte(e_priv, 0, ISR0_IMR0, ISR0_IMR0_PAGE);
11121112
nec7210_board_reset(nec_priv, board);
11131113
}

drivers/staging/gpib/eastwood/fluke_gpib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ static inline uint8_t fluke_read_byte_nolock(struct nec7210_priv *nec_priv,
7272
{
7373
u8 retval;
7474

75-
retval = readl(nec_priv->iobase + register_num * nec_priv->offset);
75+
retval = readl(nec_priv->mmiobase + register_num * nec_priv->offset);
7676
return retval;
7777
}
7878

7979
// don't use without locking nec_priv->register_page_lock
8080
static inline void fluke_write_byte_nolock(struct nec7210_priv *nec_priv, uint8_t data,
8181
int register_num)
8282
{
83-
writel(data, nec_priv->iobase + register_num * nec_priv->offset);
83+
writel(data, nec_priv->mmiobase + register_num * nec_priv->offset);
8484
}
8585

8686
static inline uint8_t fluke_paged_read_byte(struct fluke_priv *e_priv,

drivers/staging/gpib/fmh_gpib/fmh_gpib.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,15 +1421,14 @@ static int fmh_gpib_attach_impl(gpib_board_t *board, const gpib_board_config_t *
14211421
}
14221422
e_priv->gpib_iomem_res = res;
14231423

1424-
nec_priv->iobase = ioremap(e_priv->gpib_iomem_res->start,
1424+
nec_priv->mmiobase = ioremap(e_priv->gpib_iomem_res->start,
14251425
resource_size(e_priv->gpib_iomem_res));
1426-
if (!nec_priv->iobase) {
1426+
if (!nec_priv->mmiobase) {
14271427
dev_err(board->dev, "Could not map I/O memory for gpib\n");
14281428
return -ENOMEM;
14291429
}
1430-
dev_info(board->dev, "iobase 0x%lx remapped to %p, length=%ld\n",
1431-
(unsigned long)e_priv->gpib_iomem_res->start,
1432-
nec_priv->iobase, (unsigned long)resource_size(e_priv->gpib_iomem_res));
1430+
dev_info(board->dev, "iobase %pr remapped to %p\n",
1431+
e_priv->gpib_iomem_res, nec_priv->mmiobase);
14331432

14341433
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma_fifos");
14351434
if (!res) {
@@ -1509,14 +1508,14 @@ void fmh_gpib_detach(gpib_board_t *board)
15091508
free_irq(e_priv->irq, board);
15101509
if (e_priv->fifo_base)
15111510
fifos_write(e_priv, 0, FIFO_CONTROL_STATUS_REG);
1512-
if (nec_priv->iobase) {
1511+
if (nec_priv->mmiobase) {
15131512
write_byte(nec_priv, 0, ISR0_IMR0_REG);
15141513
nec7210_board_reset(nec_priv, board);
15151514
}
15161515
if (e_priv->fifo_base)
15171516
iounmap(e_priv->fifo_base);
1518-
if (nec_priv->iobase)
1519-
iounmap(nec_priv->iobase);
1517+
if (nec_priv->mmiobase)
1518+
iounmap(nec_priv->mmiobase);
15201519
if (e_priv->dma_port_res) {
15211520
release_mem_region(e_priv->dma_port_res->start,
15221521
resource_size(e_priv->dma_port_res));
@@ -1566,12 +1565,12 @@ static int fmh_gpib_pci_attach_impl(gpib_board_t *board, const gpib_board_config
15661565
e_priv->gpib_iomem_res = &pci_device->resource[gpib_control_status_pci_resource_index];
15671566
e_priv->dma_port_res = &pci_device->resource[gpib_fifo_pci_resource_index];
15681567

1569-
nec_priv->iobase = ioremap(pci_resource_start(pci_device,
1568+
nec_priv->mmiobase = ioremap(pci_resource_start(pci_device,
15701569
gpib_control_status_pci_resource_index),
15711570
pci_resource_len(pci_device,
15721571
gpib_control_status_pci_resource_index));
15731572
dev_info(board->dev, "base address for gpib control/status registers remapped to 0x%p\n",
1574-
nec_priv->iobase);
1573+
nec_priv->mmiobase);
15751574

15761575
if (e_priv->dma_port_res->flags & IORESOURCE_MEM) {
15771576
e_priv->fifo_base = ioremap(pci_resource_start(pci_device,
@@ -1634,14 +1633,14 @@ void fmh_gpib_pci_detach(gpib_board_t *board)
16341633
free_irq(e_priv->irq, board);
16351634
if (e_priv->fifo_base)
16361635
fifos_write(e_priv, 0, FIFO_CONTROL_STATUS_REG);
1637-
if (nec_priv->iobase) {
1636+
if (nec_priv->mmiobase) {
16381637
write_byte(nec_priv, 0, ISR0_IMR0_REG);
16391638
nec7210_board_reset(nec_priv, board);
16401639
}
16411640
if (e_priv->fifo_base)
16421641
iounmap(e_priv->fifo_base);
1643-
if (nec_priv->iobase)
1644-
iounmap(nec_priv->iobase);
1642+
if (nec_priv->mmiobase)
1643+
iounmap(nec_priv->mmiobase);
16451644
if (e_priv->dma_port_res || e_priv->gpib_iomem_res)
16461645
pci_release_regions(to_pci_dev(board->dev));
16471646
if (board->dev)

drivers/staging/gpib/fmh_gpib/fmh_gpib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ static const unsigned int fifo_max_burst_length_mask = 0x00ff;
127127
static inline uint8_t gpib_cs_read_byte(struct nec7210_priv *nec_priv,
128128
unsigned int register_num)
129129
{
130-
return readb(nec_priv->iobase + register_num * nec_priv->offset);
130+
return readb(nec_priv->mmiobase + register_num * nec_priv->offset);
131131
}
132132

133133
static inline void gpib_cs_write_byte(struct nec7210_priv *nec_priv, uint8_t data,
134134
unsigned int register_num)
135135
{
136-
writeb(data, nec_priv->iobase + register_num * nec_priv->offset);
136+
writeb(data, nec_priv->mmiobase + register_num * nec_priv->offset);
137137
}
138138

139139
static inline uint16_t fifos_read(struct fmh_priv *fmh_priv, int register_num)

drivers/staging/gpib/hp_82335/hp82335.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "hp82335.h"
12+
#include <linux/io.h>
1213
#include <linux/ioport.h>
1314
#include <linux/sched.h>
1415
#include <linux/module.h>
@@ -233,15 +234,15 @@ static void hp82335_clear_interrupt(struct hp82335_priv *hp_priv)
233234
{
234235
struct tms9914_priv *tms_priv = &hp_priv->tms9914_priv;
235236

236-
writeb(0, tms_priv->iobase + HPREG_INTR_CLEAR);
237+
writeb(0, tms_priv->mmiobase + HPREG_INTR_CLEAR);
237238
}
238239

239240
int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
240241
{
241242
struct hp82335_priv *hp_priv;
242243
struct tms9914_priv *tms_priv;
243244
int retval;
244-
const unsigned long upper_iomem_base = (unsigned long)config->ibbase + hp82335_rom_size;
245+
const unsigned long upper_iomem_base = config->ibbase + hp82335_rom_size;
245246

246247
board->status = 0;
247248

@@ -253,7 +254,7 @@ int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
253254
tms_priv->write_byte = hp82335_write_byte;
254255
tms_priv->offset = 1;
255256

256-
switch ((unsigned long)(config->ibbase)) {
257+
switch (config->ibbase) {
257258
case 0xc4000:
258259
case 0xc8000:
259260
case 0xcc000:
@@ -271,7 +272,7 @@ int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
271272
case 0xfc000:
272273
break;
273274
default:
274-
pr_err("hp82335: invalid base io address 0x%p\n", config->ibbase);
275+
pr_err("hp82335: invalid base io address 0x%u\n", config->ibbase);
275276
return -EINVAL;
276277
}
277278
if (!request_mem_region(upper_iomem_base, hp82335_upper_iomem_size, "hp82335")) {
@@ -280,9 +281,9 @@ int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
280281
return -EBUSY;
281282
}
282283
hp_priv->raw_iobase = upper_iomem_base;
283-
tms_priv->iobase = ioremap(upper_iomem_base, hp82335_upper_iomem_size);
284+
tms_priv->mmiobase = ioremap(upper_iomem_base, hp82335_upper_iomem_size);
284285
pr_info("hp82335: upper half of 82335 iomem region 0x%lx remapped to 0x%p\n",
285-
hp_priv->raw_iobase, tms_priv->iobase);
286+
hp_priv->raw_iobase, tms_priv->mmiobase);
286287

287288
retval = request_irq(config->ibirq, hp82335_interrupt, 0, "hp82335", board);
288289
if (retval) {
@@ -296,7 +297,7 @@ int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
296297

297298
hp82335_clear_interrupt(hp_priv);
298299

299-
writeb(INTR_ENABLE, tms_priv->iobase + HPREG_CCR);
300+
writeb(INTR_ENABLE, tms_priv->mmiobase + HPREG_CCR);
300301

301302
tms9914_online(board, tms_priv);
302303

@@ -312,10 +313,10 @@ void hp82335_detach(gpib_board_t *board)
312313
tms_priv = &hp_priv->tms9914_priv;
313314
if (hp_priv->irq)
314315
free_irq(hp_priv->irq, board);
315-
if (tms_priv->iobase) {
316-
writeb(0, tms_priv->iobase + HPREG_CCR);
316+
if (tms_priv->mmiobase) {
317+
writeb(0, tms_priv->mmiobase + HPREG_CCR);
317318
tms9914_board_reset(tms_priv);
318-
iounmap((void *)tms_priv->iobase);
319+
iounmap(tms_priv->mmiobase);
319320
}
320321
if (hp_priv->raw_iobase)
321322
release_mem_region(hp_priv->raw_iobase, hp82335_upper_iomem_size);

drivers/staging/gpib/hp_82341/hp_82341.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,12 @@ void hp_82341_free_private(gpib_board_t *board)
473473

474474
static uint8_t hp_82341_read_byte(struct tms9914_priv *priv, unsigned int register_num)
475475
{
476-
return inb((unsigned long)(priv->iobase) + register_num);
476+
return inb(priv->iobase + register_num);
477477
}
478478

479479
static void hp_82341_write_byte(struct tms9914_priv *priv, uint8_t data, unsigned int register_num)
480480
{
481-
outb(data, (unsigned long)(priv->iobase) + register_num);
481+
outb(data, priv->iobase + register_num);
482482
}
483483

484484
static int hp_82341_find_isapnp_board(struct pnp_dev **dev)
@@ -682,8 +682,8 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
682682
{
683683
struct hp_82341_priv *hp_priv;
684684
struct tms9914_priv *tms_priv;
685-
unsigned long start_addr;
686-
void *iobase;
685+
u32 start_addr;
686+
u32 iobase;
687687
int irq;
688688
int i;
689689
int retval;
@@ -704,7 +704,7 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
704704
if (retval < 0)
705705
return retval;
706706
hp_priv->pnp_dev = dev;
707-
iobase = (void *)(pnp_port_start(dev, 0));
707+
iobase = pnp_port_start(dev, 0);
708708
irq = pnp_irq(dev, 0);
709709
hp_priv->hw_version = HW_VERSION_82341D;
710710
hp_priv->io_region_offset = 0x8;
@@ -714,9 +714,9 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
714714
hp_priv->hw_version = HW_VERSION_82341C;
715715
hp_priv->io_region_offset = 0x400;
716716
}
717-
pr_info("hp_82341: base io 0x%p\n", iobase);
717+
pr_info("hp_82341: base io 0x%u\n", iobase);
718718
for (i = 0; i < hp_82341_num_io_regions; ++i) {
719-
start_addr = (unsigned long)(iobase) + i * hp_priv->io_region_offset;
719+
start_addr = iobase + i * hp_priv->io_region_offset;
720720
if (!request_region(start_addr, hp_82341_region_iosize, "hp_82341")) {
721721
pr_err("hp_82341: failed to allocate io ports 0x%lx-0x%lx\n",
722722
start_addr,
@@ -725,7 +725,7 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
725725
}
726726
hp_priv->iobase[i] = start_addr;
727727
}
728-
tms_priv->iobase = (void *)(hp_priv->iobase[2]);
728+
tms_priv->iobase = hp_priv->iobase[2];
729729
if (hp_priv->hw_version == HW_VERSION_82341D) {
730730
retval = isapnp_cfg_begin(hp_priv->pnp_dev->card->number,
731731
hp_priv->pnp_dev->number);

drivers/staging/gpib/include/gpib_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ typedef struct {
3131
void *init_data;
3232
int init_data_length;
3333
/* IO base address to use for non-pnp cards (set by core, driver should make local copy) */
34-
void *ibbase;
34+
u32 ibbase;
35+
void __iomem *mmibbase;
3536
/* IRQ to use for non-pnp cards (set by core, driver should make local copy) */
3637
unsigned int ibirq;
3738
/* dma channel to use for non-pnp cards (set by core, driver should make local copy) */

drivers/staging/gpib/include/nec7210.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
/* struct used to provide variables local to a nec7210 chip */
2020
struct nec7210_priv {
21-
void *iobase;
21+
#ifdef CONFIG_HAS_IOPORT
22+
u32 iobase;
23+
#endif
24+
void __iomem *mmiobase;
2225
unsigned int offset; // offset between successive nec7210 io addresses
2326
unsigned int dma_channel;
2427
u8 *dma_buffer;

drivers/staging/gpib/include/tms9914.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ enum tms9914_holdoff_mode {
2020

2121
/* struct used to provide variables local to a tms9914 chip */
2222
struct tms9914_priv {
23-
void *iobase;
23+
#ifdef CONFIG_HAS_IOPORT
24+
u32 iobase;
25+
#endif
26+
void __iomem *mmiobase;
2427
unsigned int offset; // offset between successive tms9914 io addresses
2528
unsigned int dma_channel;
2629
// software copy of bits written to interrupt mask registers

0 commit comments

Comments
 (0)