Skip to content

Commit

Permalink
staging: gpib: fix address space mixup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Arnd Bergmann authored and Greg Kroah-Hartman committed Dec 20, 2024
1 parent fec866a commit baf8855
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 116 deletions.
4 changes: 2 additions & 2 deletions drivers/staging/gpib/agilent_82350b/agilent_82350b.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static int agilent_82350b_generic_attach(gpib_board_t *board, const gpib_board_c
GPIB_82350A_REGION));
dev_dbg(board->gpib_dev, "%s: gpib base address remapped to 0x%p\n",
driver_name, a_priv->gpib_base);
tms_priv->iobase = a_priv->gpib_base + TMS9914_BASE_REG;
tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;
a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device,
SRAM_82350A_REGION),
pci_resource_len(a_priv->pci_device,
Expand All @@ -724,7 +724,7 @@ static int agilent_82350b_generic_attach(gpib_board_t *board, const gpib_board_c
pci_resource_len(a_priv->pci_device, GPIB_REGION));
dev_dbg(board->gpib_dev, "%s: gpib base address remapped to 0x%p\n",
driver_name, a_priv->gpib_base);
tms_priv->iobase = a_priv->gpib_base + TMS9914_BASE_REG;
tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;
a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device, SRAM_REGION),
pci_resource_len(a_priv->pci_device, SRAM_REGION));
dev_dbg(board->gpib_dev, "%s: sram base address remapped to 0x%p\n",
Expand Down
12 changes: 6 additions & 6 deletions drivers/staging/gpib/cb7210/cb7210.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,12 +971,12 @@ int cb_pci_attach(gpib_board_t *board, const gpib_board_config_t *config)
switch (cb_priv->pci_chip) {
case PCI_CHIP_AMCC_S5933:
cb_priv->amcc_iobase = pci_resource_start(cb_priv->pci_device, 0);
nec_priv->iobase = (void *)(pci_resource_start(cb_priv->pci_device, 1));
nec_priv->iobase = pci_resource_start(cb_priv->pci_device, 1);
cb_priv->fifo_iobase = pci_resource_start(cb_priv->pci_device, 2);
break;
case PCI_CHIP_QUANCOM:
nec_priv->iobase = (void *)(pci_resource_start(cb_priv->pci_device, 0));
cb_priv->fifo_iobase = (unsigned long)nec_priv->iobase;
nec_priv->iobase = pci_resource_start(cb_priv->pci_device, 0);
cb_priv->fifo_iobase = nec_priv->iobase;
break;
default:
pr_err("cb7210: bug! unhandled pci_chip=%i\n", cb_priv->pci_chip);
Expand Down Expand Up @@ -1040,8 +1040,8 @@ int cb_isa_attach(gpib_board_t *board, const gpib_board_config_t *config)
return retval;
cb_priv = board->private_data;
nec_priv = &cb_priv->nec7210_priv;
if (request_region((unsigned long)config->ibbase, cb7210_iosize, "cb7210") == 0) {
pr_err("gpib: ioports starting at 0x%p are already in use\n", config->ibbase);
if (request_region(config->ibbase, cb7210_iosize, "cb7210") == 0) {
pr_err("gpib: ioports starting at 0x%u are already in use\n", config->ibbase);
return -EIO;
}
nec_priv->iobase = config->ibbase;
Expand Down Expand Up @@ -1471,7 +1471,7 @@ int cb_pcmcia_attach(gpib_board_t *board, const gpib_board_config_t *config)
(unsigned long)curr_dev->resource[0]->start);
return -EIO;
}
nec_priv->iobase = (void *)(unsigned long)curr_dev->resource[0]->start;
nec_priv->iobase = curr_dev->resource[0]->start;
cb_priv->fifo_iobase = curr_dev->resource[0]->start;

if (request_irq(curr_dev->irq, cb7210_interrupt, IRQF_SHARED,
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/gpib/cb7210/cb7210.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ enum hs_regs {
HS_STATUS = 0x8, /* HS_STATUS register */
};

static inline unsigned long nec7210_iobase(const struct cb7210_priv *cb_priv)
static inline u32 nec7210_iobase(const struct cb7210_priv *cb_priv)
{
return (unsigned long)(cb_priv->nec7210_priv.iobase);
return cb_priv->nec7210_priv.iobase;
}

static inline int cb7210_page_in_bits(unsigned int page)
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/gpib/cec/cec_gpib.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ int cec_pci_attach(gpib_board_t *board, const gpib_board_config_t *config)

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

isr_flags |= IRQF_SHARED;
if (request_irq(cec_priv->pci_device->irq, cec_interrupt, isr_flags, "pci-gpib", board)) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/gpib/common/gpib_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ static int iobase_ioctl(gpib_board_config_t *config, unsigned long arg)

if (WARN_ON_ONCE(sizeof(void *) > sizeof(base_addr)))
return -EFAULT;
config->ibbase = (void *)(unsigned long)(base_addr);
config->ibbase = base_addr;

return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions drivers/staging/gpib/eastwood/fluke_gpib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,12 +1011,12 @@ static int fluke_attach_impl(gpib_board_t *board, const gpib_board_config_t *con
}
e_priv->gpib_iomem_res = res;

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

if (nec_priv->iobase) {
if (nec_priv->mmiobase) {
fluke_paged_write_byte(e_priv, 0, ISR0_IMR0, ISR0_IMR0_PAGE);
nec7210_board_reset(nec_priv, board);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/gpib/eastwood/fluke_gpib.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ static inline uint8_t fluke_read_byte_nolock(struct nec7210_priv *nec_priv,
{
u8 retval;

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

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

static inline uint8_t fluke_paged_read_byte(struct fluke_priv *e_priv,
Expand Down
25 changes: 12 additions & 13 deletions drivers/staging/gpib/fmh_gpib/fmh_gpib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,15 +1421,14 @@ static int fmh_gpib_attach_impl(gpib_board_t *board, const gpib_board_config_t *
}
e_priv->gpib_iomem_res = res;

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

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma_fifos");
if (!res) {
Expand Down Expand Up @@ -1509,14 +1508,14 @@ void fmh_gpib_detach(gpib_board_t *board)
free_irq(e_priv->irq, board);
if (e_priv->fifo_base)
fifos_write(e_priv, 0, FIFO_CONTROL_STATUS_REG);
if (nec_priv->iobase) {
if (nec_priv->mmiobase) {
write_byte(nec_priv, 0, ISR0_IMR0_REG);
nec7210_board_reset(nec_priv, board);
}
if (e_priv->fifo_base)
iounmap(e_priv->fifo_base);
if (nec_priv->iobase)
iounmap(nec_priv->iobase);
if (nec_priv->mmiobase)
iounmap(nec_priv->mmiobase);
if (e_priv->dma_port_res) {
release_mem_region(e_priv->dma_port_res->start,
resource_size(e_priv->dma_port_res));
Expand Down Expand Up @@ -1566,12 +1565,12 @@ static int fmh_gpib_pci_attach_impl(gpib_board_t *board, const gpib_board_config
e_priv->gpib_iomem_res = &pci_device->resource[gpib_control_status_pci_resource_index];
e_priv->dma_port_res = &pci_device->resource[gpib_fifo_pci_resource_index];

nec_priv->iobase = ioremap(pci_resource_start(pci_device,
nec_priv->mmiobase = ioremap(pci_resource_start(pci_device,
gpib_control_status_pci_resource_index),
pci_resource_len(pci_device,
gpib_control_status_pci_resource_index));
dev_info(board->dev, "base address for gpib control/status registers remapped to 0x%p\n",
nec_priv->iobase);
nec_priv->mmiobase);

if (e_priv->dma_port_res->flags & IORESOURCE_MEM) {
e_priv->fifo_base = ioremap(pci_resource_start(pci_device,
Expand Down Expand Up @@ -1634,14 +1633,14 @@ void fmh_gpib_pci_detach(gpib_board_t *board)
free_irq(e_priv->irq, board);
if (e_priv->fifo_base)
fifos_write(e_priv, 0, FIFO_CONTROL_STATUS_REG);
if (nec_priv->iobase) {
if (nec_priv->mmiobase) {
write_byte(nec_priv, 0, ISR0_IMR0_REG);
nec7210_board_reset(nec_priv, board);
}
if (e_priv->fifo_base)
iounmap(e_priv->fifo_base);
if (nec_priv->iobase)
iounmap(nec_priv->iobase);
if (nec_priv->mmiobase)
iounmap(nec_priv->mmiobase);
if (e_priv->dma_port_res || e_priv->gpib_iomem_res)
pci_release_regions(to_pci_dev(board->dev));
if (board->dev)
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/gpib/fmh_gpib/fmh_gpib.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ static const unsigned int fifo_max_burst_length_mask = 0x00ff;
static inline uint8_t gpib_cs_read_byte(struct nec7210_priv *nec_priv,
unsigned int register_num)
{
return readb(nec_priv->iobase + register_num * nec_priv->offset);
return readb(nec_priv->mmiobase + register_num * nec_priv->offset);
}

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

static inline uint16_t fifos_read(struct fmh_priv *fmh_priv, int register_num)
Expand Down
21 changes: 11 additions & 10 deletions drivers/staging/gpib/hp_82335/hp82335.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "hp82335.h"
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/sched.h>
#include <linux/module.h>
Expand Down Expand Up @@ -233,15 +234,15 @@ static void hp82335_clear_interrupt(struct hp82335_priv *hp_priv)
{
struct tms9914_priv *tms_priv = &hp_priv->tms9914_priv;

writeb(0, tms_priv->iobase + HPREG_INTR_CLEAR);
writeb(0, tms_priv->mmiobase + HPREG_INTR_CLEAR);
}

int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
{
struct hp82335_priv *hp_priv;
struct tms9914_priv *tms_priv;
int retval;
const unsigned long upper_iomem_base = (unsigned long)config->ibbase + hp82335_rom_size;
const unsigned long upper_iomem_base = config->ibbase + hp82335_rom_size;

board->status = 0;

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

switch ((unsigned long)(config->ibbase)) {
switch (config->ibbase) {
case 0xc4000:
case 0xc8000:
case 0xcc000:
Expand All @@ -271,7 +272,7 @@ int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
case 0xfc000:
break;
default:
pr_err("hp82335: invalid base io address 0x%p\n", config->ibbase);
pr_err("hp82335: invalid base io address 0x%u\n", config->ibbase);
return -EINVAL;
}
if (!request_mem_region(upper_iomem_base, hp82335_upper_iomem_size, "hp82335")) {
Expand All @@ -280,9 +281,9 @@ int hp82335_attach(gpib_board_t *board, const gpib_board_config_t *config)
return -EBUSY;
}
hp_priv->raw_iobase = upper_iomem_base;
tms_priv->iobase = ioremap(upper_iomem_base, hp82335_upper_iomem_size);
tms_priv->mmiobase = ioremap(upper_iomem_base, hp82335_upper_iomem_size);
pr_info("hp82335: upper half of 82335 iomem region 0x%lx remapped to 0x%p\n",
hp_priv->raw_iobase, tms_priv->iobase);
hp_priv->raw_iobase, tms_priv->mmiobase);

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

hp82335_clear_interrupt(hp_priv);

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

tms9914_online(board, tms_priv);

Expand All @@ -312,10 +313,10 @@ void hp82335_detach(gpib_board_t *board)
tms_priv = &hp_priv->tms9914_priv;
if (hp_priv->irq)
free_irq(hp_priv->irq, board);
if (tms_priv->iobase) {
writeb(0, tms_priv->iobase + HPREG_CCR);
if (tms_priv->mmiobase) {
writeb(0, tms_priv->mmiobase + HPREG_CCR);
tms9914_board_reset(tms_priv);
iounmap((void *)tms_priv->iobase);
iounmap(tms_priv->mmiobase);
}
if (hp_priv->raw_iobase)
release_mem_region(hp_priv->raw_iobase, hp82335_upper_iomem_size);
Expand Down
16 changes: 8 additions & 8 deletions drivers/staging/gpib/hp_82341/hp_82341.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ void hp_82341_free_private(gpib_board_t *board)

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

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

static int hp_82341_find_isapnp_board(struct pnp_dev **dev)
Expand Down Expand Up @@ -682,8 +682,8 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
{
struct hp_82341_priv *hp_priv;
struct tms9914_priv *tms_priv;
unsigned long start_addr;
void *iobase;
u32 start_addr;
u32 iobase;
int irq;
int i;
int retval;
Expand All @@ -704,7 +704,7 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
if (retval < 0)
return retval;
hp_priv->pnp_dev = dev;
iobase = (void *)(pnp_port_start(dev, 0));
iobase = pnp_port_start(dev, 0);
irq = pnp_irq(dev, 0);
hp_priv->hw_version = HW_VERSION_82341D;
hp_priv->io_region_offset = 0x8;
Expand All @@ -714,9 +714,9 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
hp_priv->hw_version = HW_VERSION_82341C;
hp_priv->io_region_offset = 0x400;
}
pr_info("hp_82341: base io 0x%p\n", iobase);
pr_info("hp_82341: base io 0x%u\n", iobase);
for (i = 0; i < hp_82341_num_io_regions; ++i) {
start_addr = (unsigned long)(iobase) + i * hp_priv->io_region_offset;
start_addr = iobase + i * hp_priv->io_region_offset;
if (!request_region(start_addr, hp_82341_region_iosize, "hp_82341")) {
pr_err("hp_82341: failed to allocate io ports 0x%lx-0x%lx\n",
start_addr,
Expand All @@ -725,7 +725,7 @@ int hp_82341_attach(gpib_board_t *board, const gpib_board_config_t *config)
}
hp_priv->iobase[i] = start_addr;
}
tms_priv->iobase = (void *)(hp_priv->iobase[2]);
tms_priv->iobase = hp_priv->iobase[2];
if (hp_priv->hw_version == HW_VERSION_82341D) {
retval = isapnp_cfg_begin(hp_priv->pnp_dev->card->number,
hp_priv->pnp_dev->number);
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/gpib/include/gpib_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ typedef struct {
void *init_data;
int init_data_length;
/* IO base address to use for non-pnp cards (set by core, driver should make local copy) */
void *ibbase;
u32 ibbase;
void __iomem *mmibbase;
/* IRQ to use for non-pnp cards (set by core, driver should make local copy) */
unsigned int ibirq;
/* dma channel to use for non-pnp cards (set by core, driver should make local copy) */
Expand Down
5 changes: 4 additions & 1 deletion drivers/staging/gpib/include/nec7210.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

/* struct used to provide variables local to a nec7210 chip */
struct nec7210_priv {
void *iobase;
#ifdef CONFIG_HAS_IOPORT
u32 iobase;
#endif
void __iomem *mmiobase;
unsigned int offset; // offset between successive nec7210 io addresses
unsigned int dma_channel;
u8 *dma_buffer;
Expand Down
5 changes: 4 additions & 1 deletion drivers/staging/gpib/include/tms9914.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ enum tms9914_holdoff_mode {

/* struct used to provide variables local to a tms9914 chip */
struct tms9914_priv {
void *iobase;
#ifdef CONFIG_HAS_IOPORT
u32 iobase;
#endif
void __iomem *mmiobase;
unsigned int offset; // offset between successive tms9914 io addresses
unsigned int dma_channel;
// software copy of bits written to interrupt mask registers
Expand Down
Loading

0 comments on commit baf8855

Please sign in to comment.