Commit 03eb6d11 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

[ARCNET]: Fix module refcounting.

parent 71a82136
......@@ -47,7 +47,6 @@ static void arcrimi_command(struct net_device *dev, int command);
static int arcrimi_status(struct net_device *dev);
static void arcrimi_setmask(struct net_device *dev, int mask);
static int arcrimi_reset(struct net_device *dev, int really_reset);
static void arcrimi_openclose(struct net_device *dev, bool open);
static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count);
static void arcrimi_copy_from_card(struct net_device *dev, int bufnum, int offset,
......@@ -179,7 +178,7 @@ static int __init arcrimi_found(struct net_device *dev)
lp->hw.status = arcrimi_status;
lp->hw.intmask = arcrimi_setmask;
lp->hw.reset = arcrimi_reset;
lp->hw.open_close = arcrimi_openclose;
lp->hw.owner = THIS_MODULE;
lp->hw.copy_to_card = arcrimi_copy_to_card;
lp->hw.copy_from_card = arcrimi_copy_from_card;
lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
......@@ -254,15 +253,6 @@ static int arcrimi_reset(struct net_device *dev, int really_reset)
return 0;
}
static void arcrimi_openclose(struct net_device *dev, int open)
{
if (open)
MOD_INC_USE_COUNT;
else
MOD_DEC_USE_COUNT;
}
static void arcrimi_setmask(struct net_device *dev, int mask)
{
struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
......
......@@ -343,7 +343,10 @@ void arcdev_setup(struct net_device *dev)
static int arcnet_open(struct net_device *dev)
{
struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
int count, newmtu;
int count, newmtu, error;
if (!try_module_get(lp->hw.owner))
return -ENODEV;
BUGLVL(D_PROTO) {
int count;
......@@ -360,8 +363,9 @@ static int arcnet_open(struct net_device *dev)
/* try to put the card in a defined state - if it fails the first
* time, actually reset it.
*/
error = -ENODEV;
if (ARCRESET(0) && ARCRESET(1))
return -ENODEV;
goto out_module_put;
newmtu = choose_mtu();
if (newmtu < dev->mtu)
......@@ -391,7 +395,7 @@ static int arcnet_open(struct net_device *dev)
lp->rfc1201.sequence = 1;
/* bring up the hardware driver */
ARCOPEN(1);
lp->hw.open(dev);
if (dev->dev_addr[0] == 0)
BUGMSG(D_NORMAL, "WARNING! Station address 00 is reserved "
......@@ -415,6 +419,10 @@ static int arcnet_open(struct net_device *dev)
netif_start_queue(dev);
return 0;
out_module_put:
module_put(lp->hw.owner);
return error;
}
......@@ -432,8 +440,8 @@ static int arcnet_close(struct net_device *dev)
mdelay(1);
/* shut down the card */
ARCOPEN(0);
lp->hw.close(dev);
module_put(lp->hw.owner);
return 0;
}
......
......@@ -131,14 +131,6 @@ MODULE_PARM(clockp, "i");
MODULE_PARM(clockm, "i");
MODULE_LICENSE("GPL");
static void com20020isa_open_close(struct net_device *dev, bool open)
{
if (open)
MOD_INC_USE_COUNT;
else
MOD_DEC_USE_COUNT;
}
int init_module(void)
{
struct net_device *dev;
......@@ -160,7 +152,7 @@ int init_module(void)
lp->clockp = clockp & 7;
lp->clockm = clockm & 3;
lp->timeout = timeout & 3;
lp->hw.open_close_ll = com20020isa_open_close;
lp->owner = THIS_MODULE;
dev->base_addr = io;
dev->irq = irq;
......
......@@ -60,14 +60,6 @@ MODULE_PARM(clockp, "i");
MODULE_PARM(clockm, "i");
MODULE_LICENSE("GPL");
static void com20020pci_open_close(struct net_device *dev, bool open)
{
if (open)
MOD_INC_USE_COUNT;
else
MOD_DEC_USE_COUNT;
}
static int __devinit com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct net_device *dev;
......@@ -111,7 +103,7 @@ static int __devinit com20020pci_probe(struct pci_dev *pdev, const struct pci_de
lp->clockp = clockp & 7;
lp->clockm = clockm & 3;
lp->timeout = timeout;
lp->hw.open_close_ll = com20020pci_open_close;
lp->hw.owner = THIS_MODULE;
if (check_region(ioaddr, ARCNET_TOTAL_SIZE)) {
BUGMSG(D_INIT, "IO region %xh-%xh already allocated.\n",
......
......@@ -50,13 +50,12 @@ static void com20020_command(struct net_device *dev, int command);
static int com20020_status(struct net_device *dev);
static void com20020_setmask(struct net_device *dev, int mask);
static int com20020_reset(struct net_device *dev, int really_reset);
static void com20020_openclose(struct net_device *dev, bool open);
static void com20020_copy_to_card(struct net_device *dev, int bufnum,
int offset, void *buf, int count);
static void com20020_copy_from_card(struct net_device *dev, int bufnum,
int offset, void *buf, int count);
static void com20020_set_mc_list(struct net_device *dev);
static void com20020_close(struct net_device *, bool);
static void com20020_copy_from_card(struct net_device *dev, int bufnum,
int offset, void *buf, int count)
......@@ -162,13 +161,14 @@ int __devinit com20020_found(struct net_device *dev, int shared)
lp = (struct arcnet_local *) dev->priv;
lp->hw.owner = THIS_MODULE;
lp->hw.command = com20020_command;
lp->hw.status = com20020_status;
lp->hw.intmask = com20020_setmask;
lp->hw.reset = com20020_reset;
lp->hw.open_close = com20020_openclose;
lp->hw.copy_to_card = com20020_copy_to_card;
lp->hw.copy_from_card = com20020_copy_from_card;
lp->hw.close = com20020_close;
dev->set_multicast_list = com20020_set_mc_list;
......@@ -298,25 +298,18 @@ static int com20020_status(struct net_device *dev)
return ASTATUS();
}
static void com20020_openclose(struct net_device *dev, bool open)
static void com20020_close(struct net_device *dev, bool open)
{
struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
int ioaddr = dev->base_addr;
if (open) {
MOD_INC_USE_COUNT;
}
else {
if (!open) {
/* disable transmitter */
lp->config &= ~TXENcfg;
SETCONF;
MOD_DEC_USE_COUNT;
}
lp->hw.open_close_ll(dev, open);
}
/* Set or clear the multicast filter for this adaptor.
* num_addrs == -1 Promiscuous mode, receive all packets
* num_addrs == 0 Normal mode, clear multicast list
......
......@@ -47,7 +47,6 @@ static void com90io_command(struct net_device *dev, int command);
static int com90io_status(struct net_device *dev);
static void com90io_setmask(struct net_device *dev, int mask);
static int com90io_reset(struct net_device *dev, int really_reset);
static void com90io_openclose(struct net_device *dev, bool open);
static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count);
static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
......@@ -257,7 +256,7 @@ static int __init com90io_found(struct net_device *dev)
lp->hw.status = com90io_status;
lp->hw.intmask = com90io_setmask;
lp->hw.reset = com90io_reset;
lp->hw.open_close = com90io_openclose;
lp->hw.owner = THIS_MODULE;
lp->hw.copy_to_card = com90io_copy_to_card;
lp->hw.copy_from_card = com90io_copy_from_card;
......@@ -344,14 +343,6 @@ static void com90io_setmask(struct net_device *dev, int mask)
AINTMASK(mask);
}
static void com90io_openclose(struct net_device *dev, int open)
{
if (open)
MOD_INC_USE_COUNT;
else
MOD_DEC_USE_COUNT;
}
static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count)
{
......
......@@ -58,7 +58,6 @@ static void com90xx_command(struct net_device *dev, int command);
static int com90xx_status(struct net_device *dev);
static void com90xx_setmask(struct net_device *dev, int mask);
static int com90xx_reset(struct net_device *dev, int really_reset);
static void com90xx_openclose(struct net_device *dev, bool open);
static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count);
static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
......@@ -450,7 +449,7 @@ static int __init com90xx_found(struct net_device *dev0, int ioaddr, int airq,
lp->hw.status = com90xx_status;
lp->hw.intmask = com90xx_setmask;
lp->hw.reset = com90xx_reset;
lp->hw.open_close = com90xx_openclose;
lp->hw.owner = THIS_MODULE;
lp->hw.copy_to_card = com90xx_copy_to_card;
lp->hw.copy_from_card = com90xx_copy_from_card;
lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
......@@ -570,16 +569,6 @@ int com90xx_reset(struct net_device *dev, int really_reset)
return 0;
}
static void com90xx_openclose(struct net_device *dev, bool open)
{
if (open)
MOD_INC_USE_COUNT;
else
MOD_DEC_USE_COUNT;
}
static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count)
{
......
......@@ -291,12 +291,13 @@ struct arcnet_local {
/* hardware-specific functions */
struct {
struct module *owner;
void (*command) (struct net_device * dev, int cmd);
int (*status) (struct net_device * dev);
void (*intmask) (struct net_device * dev, int mask);
bool (*reset) (struct net_device * dev, bool really_reset);
void (*open_close) (struct net_device * dev, bool open);
void (*open_close_ll) (struct net_device * dev, bool open);
void (*open) (struct net_device * dev);
void (*close) (struct net_device * dev);
void (*copy_to_card) (struct net_device * dev, int bufnum, int offset,
void *buf, int count);
......@@ -312,7 +313,6 @@ struct arcnet_local {
#define ACOMMAND(x) (lp->hw.command(dev, (x)))
#define ASTATUS() (lp->hw.status(dev))
#define AINTMASK(x) (lp->hw.intmask(dev, (x)))
#define ARCOPEN(x) (lp->hw.open_close(dev, (x)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment