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 <arnd@arndb.de> Link: https://lore.kernel.org/all/f10e976e-7a04-4454-b38d-39cd18f142da@roeck-us.net/ Link: https://lore.kernel.org/r/20241213064959.1045243-3-arnd@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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);

0 commit comments

Comments
 (0)