[PATCH 2/2] gpib: tnt4882: fix nec7210 register access on PCMCIA cards
Tommaso Perondi <[email protected]>
| Newsgroups | org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
ni_pcmcia_attach() has the same omission as the ISA attach path. It sets
nec_priv->read_byte and nec_priv->write_byte to the ioport accessors and
maps the card window with ioport_map(), but never assigns
nec_priv->iobase, so every nec7210 register access goes to 0x00..0x0e,
the first ISA DMA controller, instead of the card's window. The
assignment added here is the same one cb7210 and ines already do in their
own PCMCIA attach paths; tnt4882 is the only nec7210 based driver that
does not set nec_priv->iobase at all.
ni_pcmcia_detach() needs the same treatment as ni_isa_detach(): with
iobase left at zero it never releases the region, and it calls
tnt4882_board_reset() from under the iobase test, after ioport_unmap()
has already run. Once iobase is assigned that reset would go through an
unmapped cookie, so move it above the unmap and guard it on mmiobase,
matching ni_isa_detach().
No release_region() is added to the attach error paths on purpose:
ibonline() calls detach() when attach fails, and that is where the region
is released.
I have no GPIB-PCMCIA card. This was found by inspection while fixing
the ISA path and is compile tested only; a test report from anyone with
the hardware would be welcome.
Fixes: baf8855c9160 ("staging: gpib: fix address space mixup")
Cc: [email protected]
Signed-off-by: Tommaso Perondi <[email protected]>
---
Notes:
Unrelated to this patch, but noticed while reading the same function:
ni_pcmcia_detach() releases pcmcia_gpib_iosize bytes, while the attach
requests and maps resource_size(curr_dev->resource[0]), which comes from
the card's CIS through pcmcia_loop_config(). Nothing seems to guarantee
that the two are equal.
drivers/gpib/tnt4882/tnt4882_gpib.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/gpib/tnt4882/tnt4882_gpib.c b/drivers/gpib/tnt4882/tnt4882_gpib.c
index b94af5c584f1..713ba5a954ba 100644
--- a/drivers/gpib/tnt4882/tnt4882_gpib.c
+++ b/drivers/gpib/tnt4882/tnt4882_gpib.c
@@ -1741,6 +1741,7 @@ static int ni_pcmcia_attach(struct gpib_board *board, const struct gpib_board_co
if (!request_region(curr_dev->resource[0]->start, resource_size(curr_dev->resource[0]),
DRV_NAME))
return -ENOMEM;
+ nec_priv->iobase = curr_dev->resource[0]->start;
nec_priv->mmiobase = ioport_map(curr_dev->resource[0]->start,
resource_size(curr_dev->resource[0]));
@@ -1767,14 +1768,14 @@ static void ni_pcmcia_detach(struct gpib_board *board)
if (tnt_priv) {
nec_priv = &tnt_priv->nec7210_priv;
+ if (nec_priv->mmiobase)
+ tnt4882_board_reset(tnt_priv, board);
if (tnt_priv->irq)
free_irq(tnt_priv->irq, board);
if (nec_priv->mmiobase)
ioport_unmap(nec_priv->mmiobase);
- if (nec_priv->iobase) {
- tnt4882_board_reset(tnt_priv, board);
+ if (nec_priv->iobase)
release_region(nec_priv->iobase, pcmcia_gpib_iosize);
- }
}
tnt4882_free_private(board);
}
--
2.55.0