[PATCH 3/9] pcmcia: remove client_t usage

Dominik Brodowski linux at dominikbrodowski.net
Sun Jul 3 06:57:53 EDT 2005


Reduce the occurences of "client_handle_t" which is nothing else than a
pointer to struct pcmcia_device by now.

Signed-off-by: Dominik Brodowski <linux at dominikbrodowski.net>

---

 drivers/pcmcia/cs_internal.h     |   13 ++-----------
 drivers/pcmcia/ds.c              |   35 +++++++++++++----------------------
 drivers/pcmcia/pcmcia_compat.c   |   19 ++++---------------
 drivers/pcmcia/pcmcia_resource.c |   31 ++++++++-----------------------
 include/pcmcia/cs_types.h        |    4 ++--
 include/pcmcia/ds.h              |   12 +++---------
 6 files changed, 32 insertions(+), 82 deletions(-)

Index: 2.6.12-git10/drivers/pcmcia/ds.c
===================================================================
--- 2.6.12-git10.orig/drivers/pcmcia/ds.c
+++ 2.6.12-git10/drivers/pcmcia/ds.c
@@ -163,7 +163,7 @@ static int pcmcia_report_error(client_ha
 	int i;
 	char *serv;
 
-	if (CHECK_HANDLE(handle))
+	if (!handle)
 		printk(KERN_NOTICE);
 	else {
 		struct pcmcia_device *p_dev = handle_to_pdev(handle);
@@ -380,7 +380,7 @@ static int pcmcia_device_probe(struct de
 
 	if (p_drv->attach) {
 		p_dev->instance = p_drv->attach();
-		if ((!p_dev->instance) || (p_dev->client.state & CLIENT_UNBOUND)) {
+		if ((!p_dev->instance) || (p_dev->state & CLIENT_UNBOUND)) {
 			printk(KERN_NOTICE "ds: unable to create instance "
 			       "of '%s'!\n", p_drv->drv.name);
 			ret = -EINVAL;
@@ -520,10 +520,7 @@ struct pcmcia_device * pcmcia_device_add
 	sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
 
 	/* compat */
-	p_dev->client.client_magic = CLIENT_MAGIC;
-	p_dev->client.Socket = s;
-	p_dev->client.Function = function;
-	p_dev->client.state = CLIENT_UNBOUND;
+	p_dev->state = CLIENT_UNBOUND;
 
 	/* Add to the list in pcmcia_bus_socket */
 	spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
@@ -930,7 +927,7 @@ static int send_event_callback(struct de
 	if (!p_drv)
 		return 0;
 
-	if (p_dev->client.state & (CLIENT_UNBOUND|CLIENT_STALE))
+	if (p_dev->state & (CLIENT_UNBOUND|CLIENT_STALE))
 		return 0;
 
 	if (p_drv->event)
@@ -999,7 +996,7 @@ static int ds_event(struct pcmcia_socket
 
 int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
 {
-	client_t *client = NULL;
+	struct pcmcia_device *client = NULL;
 	struct pcmcia_socket *s = NULL;
 	struct pcmcia_device *p_dev = NULL;
 	struct pcmcia_driver *p_drv = NULL;
@@ -1020,14 +1017,14 @@ int pcmcia_register_client(client_handle
 			p_dev = pcmcia_get_dev(p_dev);
 			if (!p_dev)
 				continue;
-			if (!(p_dev->client.state & CLIENT_UNBOUND) ||
+			if (!(p_dev->state & CLIENT_UNBOUND) ||
 			    (!p_dev->dev.driver)) {
 				pcmcia_put_dev(p_dev);
 				continue;
 			}
 			p_drv = to_pcmcia_drv(p_dev->dev.driver);
 			if (!strncmp(p_drv->drv.name, (char *)req->dev_info, DEV_NAME_LEN)) {
-				client = &p_dev->client;
+				client = p_dev;
 				spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
 				goto found;
 			}
@@ -1043,20 +1040,18 @@ int pcmcia_register_client(client_handle
 
 	pcmcia_put_socket(s); /* safe, as we already hold a reference from bind_device */
 
-	*handle = client;
-	client->state &= ~CLIENT_UNBOUND;
-	client->Socket = s;
+	*handle = p_dev;
+	p_dev->state &= ~CLIENT_UNBOUND;
 	p_dev->event_callback_args = req->event_callback_args;
-	p_dev->event_callback_args.client_handle = client;
+	p_dev->event_callback_args.client_handle = p_dev;
 
 
 	if (s->state & SOCKET_CARDBUS)
 		client->state |= CLIENT_CARDBUS;
 
-	if ((!(s->state & SOCKET_CARDBUS)) && (s->functions == 0) &&
-	    (client->Function != BIND_FN_ALL)) {
+	if ((!(s->state & SOCKET_CARDBUS)) && (s->functions == 0)) {
 		cistpl_longlink_mfc_t mfc;
-		if (pccard_read_tuple(s, client->Function, CISTPL_LONGLINK_MFC, &mfc)
+		if (pccard_read_tuple(s, client->func, CISTPL_LONGLINK_MFC, &mfc)
 		    == CS_SUCCESS)
 			s->functions = mfc.nfn;
 		else
@@ -1108,7 +1103,7 @@ static int unbind_request(struct pcmcia_
 		}
 		p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list);
 		list_del(&p_dev->socket_device_list);
-		p_dev->client.state |= CLIENT_STALE;
+		p_dev->state |= CLIENT_STALE;
 		spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
 
 		device_unregister(&p_dev->dev);
@@ -1123,9 +1118,6 @@ int pcmcia_deregister_client(client_hand
 	int i;
 	struct pcmcia_device *p_dev = handle_to_pdev(handle);
 
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
-
 	s = SOCKET(handle);
 	ds_dbg(1, "deregister_client(%p)\n", handle);
 
@@ -1136,7 +1128,6 @@ int pcmcia_deregister_client(client_hand
 			goto warn_out;
 
 	if (handle->state & CLIENT_STALE) {
-		handle->client_magic = 0;
 		handle->state &= ~CLIENT_STALE;
 		pcmcia_put_dev(p_dev);
 	} else {
Index: 2.6.12-git10/include/pcmcia/cs_types.h
===================================================================
--- 2.6.12-git10.orig/include/pcmcia/cs_types.h
+++ 2.6.12-git10/include/pcmcia/cs_types.h
@@ -34,8 +34,8 @@ typedef u_int	event_t;
 typedef u_char	cisdata_t;
 typedef u_short	page_t;
 
-struct client_t;
-typedef struct client_t *client_handle_t;
+struct pcmcia_device;
+typedef struct pcmcia_device *client_handle_t;
 
 struct window_t;
 typedef struct window_t *window_handle_t;
Index: 2.6.12-git10/drivers/pcmcia/cs_internal.h
===================================================================
--- 2.6.12-git10.orig/drivers/pcmcia/cs_internal.h
+++ 2.6.12-git10/drivers/pcmcia/cs_internal.h
@@ -99,20 +99,11 @@ static inline void cs_socket_put(struct 
 	}
 }
 
-#define CHECK_HANDLE(h) \
-    (((h) == NULL) || ((h)->client_magic != CLIENT_MAGIC))
-
 #define CHECK_SOCKET(s) \
     (((s) >= sockets) || (socket_table[s]->ops == NULL))
 
-#define SOCKET(h) (h->Socket)
-#define CONFIG(h) (&SOCKET(h)->config[(h)->Function])
-
-#define CHECK_REGION(r) \
-    (((r) == NULL) || ((r)->region_magic != REGION_MAGIC))
-
-#define CHECK_ERASEQ(q) \
-    (((q) == NULL) || ((q)->eraseq_magic != ERASEQ_MAGIC))
+#define SOCKET(h) (h->socket)
+#define CONFIG(h) (&SOCKET(h)->config[(h)->func])
 
 /* In cardbus.c */
 int cb_alloc(struct pcmcia_socket *s);
Index: 2.6.12-git10/include/pcmcia/ds.h
===================================================================
--- 2.6.12-git10.orig/include/pcmcia/ds.h
+++ 2.6.12-git10/include/pcmcia/ds.h
@@ -162,13 +162,7 @@ struct pcmcia_device {
 	   struct soon */
 	dev_link_t		*instance;
 	event_callback_args_t 	event_callback_args;
-
-	struct client_t {
-		u_short			client_magic;
-		struct pcmcia_socket	*Socket;
-		u_char			Function;
-		u_int			state;
-	}			client;
+	u_int			state;
 
 	/* information about this device */
 	u8			has_manf_id:1;
@@ -193,8 +187,8 @@ struct pcmcia_device {
 #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
 #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
 
-#define handle_to_pdev(handle) container_of(handle, struct pcmcia_device, client);
-#define handle_to_dev(handle) ((container_of(handle, struct pcmcia_device, client))->dev)
+#define handle_to_pdev(handle) (handle)
+#define handle_to_dev(handle) (handle->dev)
 
 /* error reporting */
 void cs_error(client_handle_t handle, int func, int ret);
Index: 2.6.12-git10/drivers/pcmcia/pcmcia_resource.c
===================================================================
--- 2.6.12-git10.orig/drivers/pcmcia/pcmcia_resource.c
+++ 2.6.12-git10/drivers/pcmcia/pcmcia_resource.c
@@ -206,10 +206,8 @@ int pcmcia_access_configuration_register
 					 conf_reg_t *reg)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
-	return pccard_access_configuration_register(s, handle->Function, reg);
+	return pccard_access_configuration_register(s, handle->func, reg);
 }
 EXPORT_SYMBOL(pcmcia_access_configuration_register);
 
@@ -276,12 +274,12 @@ int pcmcia_get_configuration_info(client
 {
 	struct pcmcia_socket *s;
 
-	if ((CHECK_HANDLE(handle)) || !config)
+	if (!config)
 		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
 	if (!s)
 		return CS_BAD_HANDLE;
-	return pccard_get_configuration_info(s, handle->Function, config);
+	return pccard_get_configuration_info(s, handle->func, config);
 }
 EXPORT_SYMBOL(pcmcia_get_configuration_info);
 
@@ -382,10 +380,8 @@ int pccard_get_status(struct pcmcia_sock
 int pcmcia_get_status(client_handle_t handle, cs_status_t *status)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
-	return pccard_get_status(s, handle->Function, status);
+	return pccard_get_status(s, handle->func, status);
 }
 EXPORT_SYMBOL(pcmcia_get_status);
 
@@ -432,8 +428,6 @@ int pcmcia_modify_configuration(client_h
 	struct pcmcia_socket *s;
 	config_t *c;
 
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
 	c = CONFIG(handle);
 	if (!(s->state & SOCKET_PRESENT))
@@ -478,8 +472,7 @@ int pcmcia_release_configuration(client_
 	struct pcmcia_socket *s;
 	int i;
 
-	if (CHECK_HANDLE(handle) ||
-	    !(handle->state & CLIENT_CONFIG_LOCKED))
+	if (!(handle->state & CLIENT_CONFIG_LOCKED))
 		return CS_BAD_HANDLE;
 	handle->state &= ~CLIENT_CONFIG_LOCKED;
 	s = SOCKET(handle);
@@ -527,7 +520,7 @@ int pcmcia_release_io(client_handle_t ha
 {
 	struct pcmcia_socket *s;
 
-	if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ))
+	if (!(handle->state & CLIENT_IO_REQ))
 		return CS_BAD_HANDLE;
 	handle->state &= ~CLIENT_IO_REQ;
 	s = SOCKET(handle);
@@ -561,7 +554,7 @@ EXPORT_SYMBOL(pcmcia_release_io);
 int pcmcia_release_irq(client_handle_t handle, irq_req_t *req)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ))
+	if (!(handle->state & CLIENT_IRQ_REQ))
 		return CS_BAD_HANDLE;
 	handle->state &= ~CLIENT_IRQ_REQ;
 	s = SOCKET(handle);
@@ -632,8 +625,6 @@ int pcmcia_request_configuration(client_
 	config_t *c;
 	pccard_io_map iomap;
 
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
 	if (!(s->state & SOCKET_PRESENT))
 		return CS_NO_CARD;
@@ -762,8 +753,6 @@ int pcmcia_request_io(client_handle_t ha
 	struct pcmcia_socket *s;
 	config_t *c;
 
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
 	if (!(s->state & SOCKET_PRESENT))
 		return CS_NO_CARD;
@@ -834,8 +823,6 @@ int pcmcia_request_irq(client_handle_t h
 	int ret = CS_IN_USE, irq = 0;
 	struct pcmcia_device *p_dev = handle_to_pdev(handle);
 
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
 	if (!(s->state & SOCKET_PRESENT))
 		return CS_NO_CARD;
@@ -926,9 +913,7 @@ int pcmcia_request_window(client_handle_
 	u_long align;
 	int w;
 
-	if (CHECK_HANDLE(*handle))
-		return CS_BAD_HANDLE;
-	s = (*handle)->Socket;
+	s = (*handle)->socket;
 	if (!(s->state & SOCKET_PRESENT))
 		return CS_NO_CARD;
 	if (req->Attributes & (WIN_PAGED | WIN_SHARED))
Index: 2.6.12-git10/drivers/pcmcia/pcmcia_compat.c
===================================================================
--- 2.6.12-git10.orig/drivers/pcmcia/pcmcia_compat.c
+++ 2.6.12-git10/drivers/pcmcia/pcmcia_compat.c
@@ -31,28 +31,22 @@
 int pcmcia_get_first_tuple(client_handle_t handle, tuple_t *tuple)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
-	return pccard_get_first_tuple(s, handle->Function, tuple);
+	return pccard_get_first_tuple(s, handle->func, tuple);
 }
 EXPORT_SYMBOL(pcmcia_get_first_tuple);
 
 int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
-	return pccard_get_next_tuple(s, handle->Function, tuple);
+	return pccard_get_next_tuple(s, handle->func, tuple);
 }
 EXPORT_SYMBOL(pcmcia_get_next_tuple);
 
 int pcmcia_get_tuple_data(client_handle_t handle, tuple_t *tuple)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
 	return pccard_get_tuple_data(s, tuple);
 }
@@ -67,10 +61,8 @@ EXPORT_SYMBOL(pcmcia_parse_tuple);
 int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info)
 {
 	struct pcmcia_socket *s;
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
 	s = SOCKET(handle);
-	return pccard_validate_cis(s, handle->Function, info);
+	return pccard_validate_cis(s, handle->func, info);
 }
 EXPORT_SYMBOL(pcmcia_validate_cis);
 
@@ -78,9 +70,7 @@ EXPORT_SYMBOL(pcmcia_validate_cis);
 int pcmcia_reset_card(client_handle_t handle, client_req_t *req)
 {
 	struct pcmcia_socket *skt;
-    
-	if (CHECK_HANDLE(handle))
-		return CS_BAD_HANDLE;
+
 	skt = SOCKET(handle);
 	if (!skt)
 		return CS_BAD_HANDLE;
@@ -88,4 +78,3 @@ int pcmcia_reset_card(client_handle_t ha
 	return pccard_reset_card(skt);
 }
 EXPORT_SYMBOL(pcmcia_reset_card);
-



More information about the linux-pcmcia mailing list