From cdcc02291bea28b85b81230cb9bd328ab7a3cb35 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 25 Jan 2013 14:59:56 -0700 Subject: [PATCH] staging: comedi: quatech_daqp_cs: cleanup daqp_cs_attach() Absorb the code from daqp_cs_config() into this function and properly return the error if the configuration fails. Remove the dev_dbg() function trace messages. Fix the kzalloc(). The preferred form for passing a size of a struct is: p = kzalloc(sizeof(*p), ...); Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../staging/comedi/drivers/quatech_daqp_cs.c | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index b2b755f031b1..8eea8a9ca843 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -944,11 +944,29 @@ static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) return pcmcia_request_io(p_dev); } -static void daqp_cs_config(struct pcmcia_device *link) +static int daqp_cs_attach(struct pcmcia_device *link) { + struct local_info_t *local; int ret; + int i; - dev_dbg(&link->dev, "daqp_cs_config\n"); + for (i = 0; i < MAX_DEV; i++) + if (dev_table[i] == NULL) + break; + if (i == MAX_DEV) { + dev_notice(&link->dev, "no devices available\n"); + return -ENODEV; + } + + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(*local), GFP_KERNEL); + if (!local) + return -ENOMEM; + + local->table_index = i; + dev_table[i] = local; + local->link = link; + link->priv = local; link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; @@ -966,40 +984,11 @@ static void daqp_cs_config(struct pcmcia_device *link) if (ret) goto failed; - return; + return 0; failed: pcmcia_disable_device(link); -} - -static int daqp_cs_attach(struct pcmcia_device *link) -{ - struct local_info_t *local; - int i; - - dev_dbg(&link->dev, "daqp_cs_attach()\n"); - - for (i = 0; i < MAX_DEV; i++) - if (dev_table[i] == NULL) - break; - if (i == MAX_DEV) { - dev_notice(&link->dev, "no devices available\n"); - return -ENODEV; - } - - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); - if (!local) - return -ENOMEM; - - local->table_index = i; - dev_table[i] = local; - local->link = link; - link->priv = local; - - daqp_cs_config(link); - - return 0; + return ret; } static void daqp_cs_detach(struct pcmcia_device *link)