UPSTREAM: staging: gdm72xx: cancel work when driver unloads
[cascardo/linux.git] / drivers / staging / gdm72xx / gdm_sdio.c
index f824290..6ccb41f 100644 (file)
@@ -60,25 +60,20 @@ static void hexdump(char *title, u8 *data, int len)
 
 static struct sdio_tx *alloc_tx_struct(struct tx_cxt *tx)
 {
-       struct sdio_tx *t = NULL;
+       struct sdio_tx *t = kzalloc(sizeof(*t), GFP_ATOMIC);
 
-       t = kzalloc(sizeof(*t), GFP_ATOMIC);
-       if (t == NULL)
-               goto out;
+       if (!t)
+               return NULL;
 
        t->buf = kmalloc(TX_BUF_SIZE, GFP_ATOMIC);
-       if (t->buf == NULL)
-               goto out;
+       if (!t->buf) {
+               kfree(t);
+               return NULL;
+       }
 
        t->tx_cxt = tx;
 
        return t;
-out:
-       if (t) {
-               kfree(t->buf);
-               kfree(t);
-       }
-       return NULL;
 }
 
 static void free_tx_struct(struct sdio_tx *t)
@@ -91,20 +86,12 @@ static void free_tx_struct(struct sdio_tx *t)
 
 static struct sdio_rx *alloc_rx_struct(struct rx_cxt *rx)
 {
-       struct sdio_rx *r = NULL;
-
-       r = kmalloc(sizeof(*r), GFP_ATOMIC);
-       if (r == NULL)
-               goto out;
-
-       memset(r, 0, sizeof(*r));
+       struct sdio_rx *r = kzalloc(sizeof(*r), GFP_ATOMIC);
 
-       r->rx_cxt = rx;
+       if (r)
+               r->rx_cxt = rx;
 
        return r;
-out:
-       kfree(r);
-       return NULL;
 }
 
 static void free_rx_struct(struct sdio_rx *r)
@@ -170,7 +157,7 @@ static int init_sdio(struct sdiowm_dev *sdev)
 
        tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL);
        if (tx->sdu_buf == NULL) {
-               printk(KERN_ERR "Failed to allocate SDU tx buffer.\n");
+               dev_err(&sdev->func->dev, "Failed to allocate SDU tx buffer.\n");
                goto fail;
        }
 
@@ -199,7 +186,7 @@ static int init_sdio(struct sdiowm_dev *sdev)
 
        rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
        if (rx->rx_buf == NULL) {
-               printk(KERN_ERR "Failed to allocate rx buffer.\n");
+               dev_err(&sdev->func->dev, "Failed to allocate rx buffer.\n");
                goto fail;
        }
 
@@ -259,7 +246,8 @@ static void send_sdio_pkt(struct sdio_func *func, u8 *data, int len)
                ret = sdio_memcpy_toio(func, 0, data, n);
                if (ret < 0) {
                        if (ret != -ENOMEDIUM)
-                               printk(KERN_ERR "gdmwms: %s error: ret = %d\n",
+                               dev_err(&func->dev,
+                                       "gdmwms: %s error: ret = %d\n",
                                        __func__, ret);
                        goto end_io;
                }
@@ -272,7 +260,8 @@ static void send_sdio_pkt(struct sdio_func *func, u8 *data, int len)
                ret = sdio_memcpy_toio(func, 0, data + n, remain);
                if (ret < 0) {
                        if (ret != -ENOMEDIUM)
-                               printk(KERN_ERR "gdmwms: %s error: ret = %d\n",
+                               dev_err(&func->dev,
+                                       "gdmwms: %s error: ret = %d\n",
                                        __func__, ret);
                        goto end_io;
                }
@@ -535,13 +524,14 @@ static void gdm_sdio_irq(struct sdio_func *func)
 
        ret = sdio_memcpy_fromio(func, hdr, 0x0, TYPE_A_LOOKAHEAD_SIZE);
        if (ret) {
-               printk(KERN_ERR "Cannot read from function %d\n", func->num);
+               dev_err(&func->dev,
+                       "Cannot read from function %d\n", func->num);
                goto done;
        }
 
        len = (hdr[2] << 16) | (hdr[1] << 8) | hdr[0];
        if (len > (RX_BUF_SIZE - TYPE_A_HEADER_SIZE)) {
-               printk(KERN_ERR "Too big Type-A size: %d\n", len);
+               dev_err(&func->dev, "Too big Type-A size: %d\n", len);
                goto done;
        }
 
@@ -575,8 +565,8 @@ static void gdm_sdio_irq(struct sdio_func *func)
                n = blocks * func->cur_blksize;
                ret = sdio_memcpy_fromio(func, buf, 0x0, n);
                if (ret) {
-                       printk(KERN_ERR "Cannot read from function %d\n",
-                               func->num);
+                       dev_err(&func->dev,
+                               "Cannot read from function %d\n", func->num);
                        goto done;
                }
                buf += n;
@@ -586,8 +576,8 @@ static void gdm_sdio_irq(struct sdio_func *func)
        if (remain) {
                ret = sdio_memcpy_fromio(func, buf, 0x0, remain);
                if (ret) {
-                       printk(KERN_ERR "Cannot read from function %d\n",
-                               func->num);
+                       dev_err(&func->dev,
+                               "Cannot read from function %d\n", func->num);
                        goto done;
                }
        }
@@ -650,9 +640,9 @@ static int sdio_wimax_probe(struct sdio_func *func,
        struct phy_dev *phy_dev = NULL;
        struct sdiowm_dev *sdev = NULL;
 
-       printk(KERN_INFO "Found GDM SDIO VID = 0x%04x PID = 0x%04x...\n",
-                       func->vendor, func->device);
-       printk(KERN_INFO "GCT WiMax driver version %s\n", DRIVER_VERSION);
+       dev_info(&func->dev, "Found GDM SDIO VID = 0x%04x PID = 0x%04x...\n",
+                func->vendor, func->device);
+       dev_info(&func->dev, "GCT WiMax driver version %s\n", DRIVER_VERSION);
 
        sdio_claim_host(func);
        sdio_enable_func(func);
@@ -703,6 +693,7 @@ static void sdio_wimax_remove(struct sdio_func *func)
        struct phy_dev *phy_dev = sdio_get_drvdata(func);
        struct sdiowm_dev *sdev = phy_dev->priv_dev;
 
+       cancel_work_sync(&sdev->ws);
        if (phy_dev->netdev)
                unregister_wimax_device(phy_dev);
        sdio_claim_host(func);