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

[PATCH] pcmcia: unfiy bind_device and pcmcia_bind_device

Unify bind_device and pcmcia_bind_device. Also, change bind_device so
that it conforms to CodingStyle.
Signed-off-by: default avatarDominik Brodowski <linux@brodo.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 32363bfb
...@@ -128,49 +128,12 @@ struct pcmcia_bus_socket { ...@@ -128,49 +128,12 @@ struct pcmcia_bus_socket {
/*====================================================================*/ /*====================================================================*/
/* Device driver ID passed to Card Services */
static dev_info_t dev_info = "Driver Services";
static int major_dev = -1; static int major_dev = -1;
/*====================================================================*/ /*====================================================================*/
/* code which was in cs.c before */ /* code which was in cs.c before */
/*======================================================================
Bind_device() associates a device driver with a particular socket.
It is normally called by Driver Services after it has identified
a newly inserted card. An instance of that driver will then be
eligible to register as a client of this socket.
======================================================================*/
static int pcmcia_bind_device(bind_req_t *req)
{
client_t *client;
struct pcmcia_socket *s;
s = req->Socket;
if (!s)
return CS_BAD_SOCKET;
client = (client_t *) kmalloc(sizeof(client_t), GFP_KERNEL);
if (!client)
return CS_OUT_OF_RESOURCE;
memset(client, '\0', sizeof(client_t));
client->client_magic = CLIENT_MAGIC;
strlcpy(client->dev_info, (char *)req->dev_info, DEV_NAME_LEN);
client->Socket = s;
client->Function = req->Function;
client->state = CLIENT_UNBOUND;
client->next = s->clients;
s->clients = client;
ds_dbg(1, "%s: bind_device(): client 0x%p, dev %s\n",
cs_socket_name(client->Socket), client, client->dev_info);
return CS_SUCCESS;
} /* bind_device */
/* String tables for error messages */ /* String tables for error messages */
typedef struct lookup_t { typedef struct lookup_t {
...@@ -528,79 +491,89 @@ static int bind_mtd(struct pcmcia_bus_socket *bus_sock, mtd_info_t *mtd_info) ...@@ -528,79 +491,89 @@ static int bind_mtd(struct pcmcia_bus_socket *bus_sock, mtd_info_t *mtd_info)
/*====================================================================== /*======================================================================
bind_request() and bind_device() are merged by now. Individual
descriptions:
bind_request() connects a socket to a particular client driver. bind_request() connects a socket to a particular client driver.
It looks up the specified device ID in the list of registered It looks up the specified device ID in the list of registered
drivers, binds it to the socket, and tries to create an instance drivers, binds it to the socket, and tries to create an instance
of the device. unbind_request() deletes a driver instance. of the device. unbind_request() deletes a driver instance.
Bind_device() associates a device driver with a particular socket.
It is normally called by Driver Services after it has identified
a newly inserted card. An instance of that driver will then be
eligible to register as a client of this socket.
======================================================================*/ ======================================================================*/
static int bind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info) static int bind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info)
{ {
struct pcmcia_driver *driver; struct pcmcia_driver *driver;
socket_bind_t *b; socket_bind_t *b;
bind_req_t bind_req; client_t *client;
int ret;
if (!s) if (!s)
return -EINVAL; return -EINVAL;
ds_dbg(2, "bind_request(%d, '%s')\n", s->parent->sock, ds_dbg(2, "bind_request(%d, '%s')\n", s->parent->sock,
(char *)bind_info->dev_info); (char *)bind_info->dev_info);
driver = get_pcmcia_driver(&bind_info->dev_info); driver = get_pcmcia_driver(&bind_info->dev_info);
if (!driver) if (!driver)
return -EINVAL; return -EINVAL;
for (b = s->bind; b; b = b->next) for (b = s->bind; b; b = b->next)
if ((driver == b->driver) && if ((driver == b->driver) &&
(bind_info->function == b->function)) (bind_info->function == b->function))
break; break;
if (b != NULL) { if (b != NULL) {
bind_info->instance = b->instance; bind_info->instance = b->instance;
return -EBUSY; return -EBUSY;
} }
if (!try_module_get(driver->owner)) if (!try_module_get(driver->owner))
return -EINVAL; return -EINVAL;
bind_req.Socket = s->parent;
bind_req.Function = bind_info->function;
bind_req.dev_info = (dev_info_t *) driver->drv.name;
ret = pcmcia_bind_device(&bind_req);
if (ret != CS_SUCCESS) {
cs_error(NULL, BindDevice, ret);
printk(KERN_NOTICE "ds: unable to bind '%s' to socket %d\n",
(char *)dev_info, s->parent->sock);
module_put(driver->owner);
return -ENODEV;
}
/* Add binding to list for this socket */ client = (client_t *) kmalloc(sizeof(client_t), GFP_KERNEL);
driver->use_count++; if (!client) {
b = kmalloc(sizeof(socket_bind_t), GFP_KERNEL); module_put(driver->owner);
if (!b) return -ENOMEM;
{ }
driver->use_count--; memset(client, 0, sizeof(client_t));
module_put(driver->owner);
return -ENOMEM; client->client_magic = CLIENT_MAGIC;
} client->Socket = s->parent;
b->driver = driver; client->Function = bind_info->function;
b->function = bind_info->function; client->state = CLIENT_UNBOUND;
b->instance = NULL; client->next = s->parent->clients;
b->next = s->bind; strlcpy(client->dev_info, driver->drv.name, DEV_NAME_LEN);
s->bind = b; s->parent->clients = client;
if (driver->attach) { /* Add binding to list for this socket */
b->instance = driver->attach(); b = kmalloc(sizeof(socket_bind_t), GFP_KERNEL);
if (b->instance == NULL) { if (!b)
printk(KERN_NOTICE "ds: unable to create instance " {
"of '%s'!\n", (char *)bind_info->dev_info); module_put(driver->owner);
module_put(driver->owner); return -ENOMEM;
return -ENODEV; }
b->driver = driver;
b->function = bind_info->function;
b->instance = NULL;
b->next = s->bind;
s->bind = b;
driver->use_count++;
if (driver->attach) {
b->instance = driver->attach();
if (b->instance == NULL) {
printk(KERN_NOTICE "ds: unable to create instance "
"of '%s'!\n", (char *)bind_info->dev_info);
module_put(driver->owner);
/* FIXME: client isn't freed here */
return -ENODEV;
}
} }
}
return 0; return 0;
} /* bind_request */ } /* bind_request */
/*====================================================================*/ /*====================================================================*/
......
...@@ -315,13 +315,6 @@ typedef struct error_info_t { ...@@ -315,13 +315,6 @@ typedef struct error_info_t {
int retcode; int retcode;
} error_info_t; } error_info_t;
/* Special stuff for binding drivers to sockets */
typedef struct bind_req_t {
struct pcmcia_socket *Socket;
u_char Function;
dev_info_t *dev_info;
} bind_req_t;
/* Flag to bind to all functions */ /* Flag to bind to all functions */
#define BIND_FN_ALL 0xff #define BIND_FN_ALL 0xff
...@@ -413,6 +406,8 @@ enum service { ...@@ -413,6 +406,8 @@ enum service {
GetFirstWindow, GetNextWindow, GetMemPage GetFirstWindow, GetNextWindow, GetMemPage
}; };
struct pcmcia_socket;
int pcmcia_access_configuration_register(client_handle_t handle, conf_reg_t *reg); int pcmcia_access_configuration_register(client_handle_t handle, conf_reg_t *reg);
int pcmcia_deregister_client(client_handle_t handle); int pcmcia_deregister_client(client_handle_t handle);
int pcmcia_get_configuration_info(client_handle_t handle, config_info_t *config); int pcmcia_get_configuration_info(client_handle_t handle, config_info_t *config);
......
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