Skip to content

Commit

Permalink
[PATCH] Char: correct pci_get_device changes
Browse files Browse the repository at this point in the history
Commits 881a8c1 and
efe1ec2 corrects pci device matching in
only one way; it no longer oopses/crashes, despite hotplug is not solved
in these changes.

Whenever pci_find_device -> pci_get_device change is performed, also
pci_dev_get and pci_dev_put should be in most cases called to properly
handle hotplug.  This patch does exactly this thing -- increase refcount
to let kernel know, that we are using this piece of HW just now.

It affects moxa and rio char drivers.

Cc: <R.E.Wolff@BitWizard.nl>
Acked-by: Amit Gud <gud@eth.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Jiri Slaby authored and Linus Torvalds committed Oct 21, 2006
1 parent 7b7fc70 commit 86fbf14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/char/moxa.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static moxa_isa_board_conf moxa_isa_boards[] =
typedef struct _moxa_pci_devinfo {
ushort busNum;
ushort devNum;
struct pci_dev *pdev;
} moxa_pci_devinfo;

typedef struct _moxa_board_conf {
Expand Down Expand Up @@ -324,6 +325,9 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf
board->busType = MOXA_BUS_TYPE_PCI;
board->pciInfo.busNum = p->bus->number;
board->pciInfo.devNum = p->devfn >> 3;
board->pciInfo.pdev = p;
/* don't lose the reference in the next pci_get_device iteration */
pci_dev_get(p);

return (0);
}
Expand Down Expand Up @@ -493,6 +497,11 @@ static void __exit moxa_exit(void)
if (tty_unregister_driver(moxaDriver))
printk("Couldn't unregister MOXA Intellio family serial driver\n");
put_tty_driver(moxaDriver);

for (i = 0; i < MAX_BOARDS; i++)
if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI)
pci_dev_put(moxa_boards[i].pciInfo.pdev);

if (verbose)
printk("Done\n");
}
Expand Down
1 change: 1 addition & 0 deletions drivers/char/rio/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
** the host.
*/
struct Host {
struct pci_dev *pdev;
unsigned char Type; /* RIO_EISA, RIO_MCA, ... */
unsigned char Ivec; /* POLLED or ivec number */
unsigned char Mode; /* Control stuff */
Expand Down
9 changes: 9 additions & 0 deletions drivers/char/rio/rio_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,10 @@ static int __init rio_init(void)
rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);

fix_rio_pci(pdev);

p->RIOHosts[p->RIONumHosts].pdev = pdev;
pci_dev_get(pdev);

p->RIOLastPCISearch = 0;
p->RIONumHosts++;
found++;
Expand Down Expand Up @@ -1066,6 +1070,9 @@ static int __init rio_init(void)
((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);

p->RIOHosts[p->RIONumHosts].pdev = pdev;
pci_dev_get(pdev);

p->RIOLastPCISearch = 0;
p->RIONumHosts++;
found++;
Expand Down Expand Up @@ -1181,6 +1188,8 @@ static void __exit rio_exit(void)
}
/* It is safe/allowed to del_timer a non-active timer */
del_timer(&hp->timer);
if (hp->Type == RIO_PCI)
pci_dev_put(hp->pdev);
}

if (misc_deregister(&rio_fw_device) < 0) {
Expand Down

0 comments on commit 86fbf14

Please sign in to comment.