Commit d729376a authored by Dominik Brodowski's avatar Dominik Brodowski Committed by Linus Torvalds

[PATCH] pcmcia: remove single linked list of drivers

Remove the linked list of pcmcia_drivers. It didn't even handle removal of a
driver properly, so it won't be missed all that much.
parent 7fbcee09
......@@ -116,9 +116,6 @@ typedef struct socket_info_t {
/* Device driver ID passed to Card Services */
static dev_info_t dev_info = "Driver Services";
/* Linked list of all registered device drivers */
static struct pcmcia_driver *root_driver = NULL;
static int sockets = 0, major_dev = -1;
static socket_info_t *socket_table = NULL;
......@@ -135,13 +132,9 @@ static void cs_error(client_handle_t handle, int func, int ret)
pcmcia_report_error(handle, &err);
}
/*======================================================================
/*======================================================================*/
Register_pccard_driver() and unregister_pccard_driver() are used
tell Driver Services that a PC Card client driver is available to
be bound to sockets.
======================================================================*/
static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info);
/**
* pcmcia_register_driver - register a PCMCIA driver with the bus core
......@@ -156,8 +149,6 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
driver->use_count = 0;
driver->status = init_status;
driver->drv.bus = &pcmcia_bus_type;
driver->next = root_driver;
root_driver = driver;
return driver_register(&driver->drv);
}
......@@ -194,10 +185,7 @@ int register_pccard_driver(dev_info_t *dev_info,
int i;
DEBUG(0, "ds: register_pccard_driver('%s')\n", (char *)dev_info);
for (driver = root_driver; driver; driver = driver->next)
if (strncmp((char *)dev_info, (char *)driver->drv.name,
DEV_NAME_LEN) == 0)
break;
driver = get_pcmcia_driver(dev_info);
if (!driver) {
driver = kmalloc(sizeof(struct pcmcia_driver), GFP_KERNEL);
if (!driver) return -ENOMEM;
......@@ -227,32 +215,44 @@ int register_pccard_driver(dev_info_t *dev_info,
int unregister_pccard_driver(dev_info_t *dev_info)
{
struct pcmcia_driver **d = &root_driver;
struct pcmcia_driver *driver;
DEBUG(0, "ds: unregister_pccard_driver('%s')\n",
(char *)dev_info);
while ((*d) && (strncmp((*d)->drv.name, (char *)dev_info,
DEV_NAME_LEN) != 0))
d = &(*d)->next;
if (*d == NULL)
driver = get_pcmcia_driver(dev_info);
if (!driver)
return -ENODEV;
pcmcia_unregister_driver(*d);
kfree(*d);
pcmcia_unregister_driver(driver);
kfree(driver);
return 0;
} /* unregister_pccard_driver */
/*====================================================================*/
#ifdef CONFIG_PROC_FS
static int proc_read_drivers_callback(struct device_driver *driver, void *d)
{
char **p = d;
struct pcmcia_driver *p_dev = container_of(driver,
struct pcmcia_driver, drv);
*p += sprintf(*p, "%-24.24s %d %d\n", driver->name, p_dev->status,
p_dev->use_count);
d = (void *) p;
return 0;
}
static int proc_read_drivers(char *buf, char **start, off_t pos,
int count, int *eof, void *data)
{
struct pcmcia_driver *d;
char *p = buf;
for (d = root_driver; d; d = d->next)
p += sprintf(p, "%-24.24s %d %d\n", d->drv.name,
d->status, d->use_count);
bus_for_each_drv(&pcmcia_bus_type, NULL,
(void *) &p, proc_read_drivers_callback);
return (p - buf);
}
#endif
......@@ -405,10 +405,7 @@ static int bind_request(int i, bind_info_t *bind_info)
DEBUG(2, "bind_request(%d, '%s')\n", i,
(char *)bind_info->dev_info);
for (driver = root_driver; driver; driver = driver->next)
if (strcmp((char *)driver->drv.name,
(char *)bind_info->dev_info) == 0)
break;
driver = get_pcmcia_driver(&bind_info->dev_info);
if (driver == NULL) {
driver = kmalloc(sizeof(struct pcmcia_driver), GFP_KERNEL);
if (!driver) return -ENOMEM;
......@@ -555,15 +552,6 @@ static int unbind_request(int i, bind_info_t *bind_info)
if (c->driver->detach) {
if (c->instance)
c->driver->detach(c->instance);
} else {
if (c->driver->use_count == 0) {
struct pcmcia_driver **d;
for (d = &root_driver; *d; d = &((*d)->next))
if (c->driver == *d) break;
*d = (*d)->next;
pcmcia_unregister_driver(c->driver);
kfree(c->driver);
}
}
*b = c->next;
kfree(c);
......@@ -1032,3 +1020,37 @@ late_initcall(init_pcmcia_ds);
#endif
module_exit(exit_pcmcia_ds);
/* helpers for backwards-compatible functions */
/* backwards-compatible accessing of driver --- by name! */
struct cmp_data {
void *dev_info;
struct pcmcia_driver *drv;
};
static int cmp_drv_callback(struct device_driver *drv, void *data)
{
struct cmp_data *cmp = data;
if (strncmp((char *)cmp->dev_info, (char *)drv->name,
DEV_NAME_LEN) == 0) {
cmp->drv = container_of(drv, struct pcmcia_driver, drv);
return -EINVAL;
}
return 0;
}
static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info)
{
int ret;
struct cmp_data cmp = {
.dev_info = dev_info,
};
ret = bus_for_each_drv(&pcmcia_bus_type, NULL, &cmp, cmp_drv_callback);
if (ret)
return cmp.drv;
return NULL;
}
......@@ -152,7 +152,6 @@ struct pcmcia_driver {
void (*detach)(dev_link_t *);
struct module *owner;
struct device_driver drv;
struct pcmcia_driver *next;
};
int pcmcia_register_driver(struct pcmcia_driver *driver);
......
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