[media] lirc: use kfifo_initialized() on lirc_buffer's fifo
authorMartin Kaiser <martin@kaiser.cx>
Tue, 28 Oct 2014 21:51:01 +0000 (18:51 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Mon, 3 Nov 2014 14:53:05 +0000 (12:53 -0200)
We can use kfifo_initialized() to check if the fifo in lirc_buffer is
initialized or not. There's no need to have a dedicated fifo status
variable in lirc_buffer.

[m.chehab@samsung.com: add the same change to lirc_zilog, to avoid
 breaking compilation of staging drivers]
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/staging/media/lirc/lirc_zilog.c
include/media/lirc_dev.h

index 567feba0011c4498bb62fb544fdf52801999a322..1ccf6262ab369d1be3cba7f3c1b996a8872852d7 100644 (file)
@@ -199,7 +199,7 @@ static void release_ir_device(struct kref *ref)
                lirc_unregister_driver(ir->l.minor);
                ir->l.minor = MAX_IRCTL_DEVICES;
        }
-       if (ir->rbuf.fifo_initialized)
+       if (kfifo_initialized(&ir->rbuf.fifo))
                lirc_buffer_free(&ir->rbuf);
        list_del(&ir->list);
        kfree(ir);
index 78f0637ca68d91d1fc45639141bb6f9d39acd82e..05e7ad5d2c8b6650f3f69152c3b38252e2b8921d 100644 (file)
@@ -29,14 +29,13 @@ struct lirc_buffer {
        /* Using chunks instead of bytes pretends to simplify boundary checking
         * And should allow for some performance fine tunning later */
        struct kfifo fifo;
-       u8 fifo_initialized;
 };
 
 static inline void lirc_buffer_clear(struct lirc_buffer *buf)
 {
        unsigned long flags;
 
-       if (buf->fifo_initialized) {
+       if (kfifo_initialized(&buf->fifo)) {
                spin_lock_irqsave(&buf->fifo_lock, flags);
                kfifo_reset(&buf->fifo);
                spin_unlock_irqrestore(&buf->fifo_lock, flags);
@@ -56,17 +55,14 @@ static inline int lirc_buffer_init(struct lirc_buffer *buf,
        buf->chunk_size = chunk_size;
        buf->size = size;
        ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL);
-       if (ret == 0)
-               buf->fifo_initialized = 1;
 
        return ret;
 }
 
 static inline void lirc_buffer_free(struct lirc_buffer *buf)
 {
-       if (buf->fifo_initialized) {
+       if (kfifo_initialized(&buf->fifo)) {
                kfifo_free(&buf->fifo);
-               buf->fifo_initialized = 0;
        } else
                WARN(1, "calling %s on an uninitialized lirc_buffer\n",
                     __func__);