kfifo: fix warn_unused_result
authorStefani Seibold <stefani@seibold.net>
Mon, 21 Dec 2009 22:37:29 +0000 (14:37 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 22 Dec 2009 22:17:56 +0000 (14:17 -0800)
Fix the "ignoring return value of '...', declared with attribute
warn_unused_result" compiler warning in several users of the new kfifo
API.

It removes the __must_check attribute from kfifo_in() and
kfifo_in_locked() which must not necessary performed.

Fix the allocation bug in the nozomi driver file, by moving out the
kfifo_alloc from the interrupt handler into the probe function.

Fix the kfifo_out() and kfifo_out_locked() users to handle a unexpected
end of fifo.

Signed-off-by: Stefani Seibold <stefani@seibold.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/char/nozomi.c
drivers/infiniband/hw/cxgb3/cxio_resource.c
drivers/media/video/meye.c
drivers/net/wireless/libertas/main.c
drivers/scsi/libiscsi_tcp.c
drivers/scsi/libsrp.c
include/linux/kfifo.h

index 9ef243429014533db1a1ac14b48995b4f9d303da..7d73cd430340c4926343af47c2247d7e8dadceeb 100644 (file)
@@ -685,8 +685,6 @@ static int nozomi_read_config_table(struct nozomi *dc)
                dump_table(dc);
 
                for (i = PORT_MDM; i < MAX_PORT; i++) {
-                       kfifo_alloc(&dc->port[i].fifo_ul,
-                               FIFO_BUFFER_SIZE_UL, GFP_ATOMIC);
                        memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
                        memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
                }
@@ -1433,6 +1431,16 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
                goto err_free_sbuf;
        }
 
+       for (i = PORT_MDM; i < MAX_PORT; i++) {
+               if (kfifo_alloc(&dc->port[i].fifo_ul,
+                     FIFO_BUFFER_SIZE_UL, GFP_ATOMIC)) {
+                       dev_err(&pdev->dev,
+                                       "Could not allocate kfifo buffer\n");
+                       ret = -ENOMEM;
+                       goto err_free_kfifo;
+               }
+       }
+
        spin_lock_init(&dc->spin_mutex);
 
        nozomi_setup_private_data(dc);
@@ -1445,7 +1453,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
                        NOZOMI_NAME, dc);
        if (unlikely(ret)) {
                dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
-               goto err_free_sbuf;
+               goto err_free_kfifo;
        }
 
        DBG1("base_addr: %p", dc->base_addr);
@@ -1464,13 +1472,28 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
        dc->state = NOZOMI_STATE_ENABLED;
 
        for (i = 0; i < MAX_PORT; i++) {
+               struct device *tty_dev;
+
                mutex_init(&dc->port[i].tty_sem);
                tty_port_init(&dc->port[i].port);
-               tty_register_device(ntty_driver, dc->index_start + i,
+               tty_dev = tty_register_device(ntty_driver, dc->index_start + i,
                                                        &pdev->dev);
+
+               if (IS_ERR(tty_dev)) {
+                       ret = PTR_ERR(tty_dev);
+                       dev_err(&pdev->dev, "Could not allocate tty?\n");
+                       goto err_free_tty;
+               }
        }
+
        return 0;
 
+err_free_tty:
+       for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
+               tty_unregister_device(ntty_driver, i);
+err_free_kfifo:
+       for (i = 0; i < MAX_PORT; i++)
+               kfifo_free(&dc->port[i].fifo_ul);
 err_free_sbuf:
        kfree(dc->send_buf);
        iounmap(dc->base_addr);
index dcbf2606c438ac3cc68c2efdbe57a1113b36c4f1..31f9201b29809512ae5a4140456e0b457fa5e9cc 100644 (file)
@@ -86,8 +86,9 @@ static int __cxio_init_resource_fifo(struct kfifo *fifo,
                        kfifo_in(fifo, (unsigned char *) &i, sizeof(u32));
 
        for (i = 0; i < skip_low + skip_high; i++)
-               kfifo_out_locked(fifo, (unsigned char *) &entry,
-                               sizeof(u32), fifo_lock);
+               if (kfifo_out_locked(fifo, (unsigned char *) &entry,
+                               sizeof(u32), fifo_lock) != sizeof(u32))
+                                       break;
        return 0;
 }
 
index 884a569d60a28d46b3b4dfe1ea21faa3f335b74c..b421858ccf907f8fe6a9cc06c62782b11d026ec1 100644 (file)
@@ -968,8 +968,9 @@ static int meyeioc_sync(struct file *file, void *fh, int *i)
                /* fall through */
        case MEYE_BUF_DONE:
                meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
-               kfifo_out_locked(&meye.doneq, (unsigned char *)&unused,
-                               sizeof(int), &meye.doneq_lock);
+               if (kfifo_out_locked(&meye.doneq, (unsigned char *)&unused,
+                               sizeof(int), &meye.doneq_lock) != sizeof(int))
+                                       break;
        }
        *i = meye.grab_buffer[*i].size;
        mutex_unlock(&meye.lock);
index 2bcfa745524a68197c4139f7bcc3f4a8fb9d840c..c2975c8e2f211ff2f9cb64ac61db3e26f7d93862 100644 (file)
@@ -514,8 +514,10 @@ static int lbs_thread(void *data)
                while (kfifo_len(&priv->event_fifo)) {
                        u32 event;
 
-                       kfifo_out(&priv->event_fifo, (unsigned char *) &event,
-                               sizeof(event));
+                       if (kfifo_out(&priv->event_fifo,
+                               (unsigned char *) &event, sizeof(event)) !=
+                               sizeof(event))
+                                       break;
                        spin_unlock_irq(&priv->driver_lock);
                        lbs_process_event(priv, event);
                        spin_lock_irq(&priv->driver_lock);
index d51ffeca2ec99a542cc5e284a4415bd78364f2bf..db6856c138fcd9d28af1c422bc2c0333540de328 100644 (file)
@@ -990,8 +990,13 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)
                }
 
                if (r2t == NULL) {
-                       kfifo_out(&tcp_task->r2tqueue,
-                                   (void *)&tcp_task->r2t, sizeof(void *));
+                       if (kfifo_out(&tcp_task->r2tqueue,
+                           (void *)&tcp_task->r2t, sizeof(void *)) !=
+                           sizeof(void *)) {
+                               WARN_ONCE(1, "unexpected fifo state");
+                               r2t = NULL;
+                       }
+
                        r2t = tcp_task->r2t;
                }
                spin_unlock_bh(&session->lock);
index 8424b8606efb69d7697df5e5220cbece703c4beb..ab19b3b4be524a679774601f2193da98bfa369d9 100644 (file)
@@ -163,8 +163,11 @@ struct iu_entry *srp_iu_get(struct srp_target *target)
 {
        struct iu_entry *iue = NULL;
 
-       kfifo_out_locked(&target->iu_queue.queue, (void *) &iue,
-                       sizeof(void *), &target->iu_queue.lock);
+       if (kfifo_out_locked(&target->iu_queue.queue, (void *) &iue,
+               sizeof(void *), &target->iu_queue.lock) != sizeof(void *)) {
+                       WARN_ONCE(1, "unexpected fifo state");
+                       return NULL;
+       }
        if (!iue)
                return iue;
        iue->target = target;
index 1b59c4a0e85feeccfb705949fef9c8bee21725da..5ed2565c89b6c094b027764a128e532dd00363cb 100644 (file)
@@ -56,7 +56,7 @@ extern void kfifo_init(struct kfifo *fifo, unsigned char *buffer,
 extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size,
                        gfp_t gfp_mask);
 extern void kfifo_free(struct kfifo *fifo);
-extern __must_check unsigned int kfifo_in(struct kfifo *fifo,
+extern unsigned int kfifo_in(struct kfifo *fifo,
                                const unsigned char *from, unsigned int len);
 extern __must_check unsigned int kfifo_out(struct kfifo *fifo,
                                unsigned char *to, unsigned int len);
@@ -94,7 +94,7 @@ static inline unsigned int kfifo_len(struct kfifo *fifo)
  * the FIFO depending on the free space, and returns the number of
  * bytes copied.
  */
-static inline __must_check unsigned int kfifo_in_locked(struct kfifo *fifo,
+static inline unsigned int kfifo_in_locked(struct kfifo *fifo,
                const unsigned char *from, unsigned int n, spinlock_t *lock)
 {
        unsigned long flags;