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>
Showing the changes to include/media/lirc_dev.h (1 of 2 files). Show all
Unified · Split
| @@ -29,14 +29,13 @@ struct lirc_buffer { · 28 unmodified lines | |||
| 29 | /* Using chunks instead of bytes pretends to simplify boundary checking | 29 | /* Using chunks instead of bytes pretends to simplify boundary checking |
| 30 | * And should allow for some performance fine tunning later */ | 30 | * And should allow for some performance fine tunning later */ |
| 31 | struct kfifo fifo; | 31 | struct kfifo fifo; |
| 32 | u8 fifo_initialized; | ||
| 33 | }; | 32 | }; |
| 34 | 33 | ||
| 35 | static inline void lirc_buffer_clear(struct lirc_buffer *buf) | 34 | static inline void lirc_buffer_clear(struct lirc_buffer *buf) |
| 36 | { | 35 | { |
| 37 | unsigned long flags; | 36 | unsigned long flags; |
| 38 | 37 | ||
| 39 | if (buf->fifo_initialized) { | 38 | if (kfifo_initialized(&buf->fifo)) { |
| 40 | spin_lock_irqsave(&buf->fifo_lock, flags); | 39 | spin_lock_irqsave(&buf->fifo_lock, flags); |
| 41 | kfifo_reset(&buf->fifo); | 40 | kfifo_reset(&buf->fifo); |
| 42 | spin_unlock_irqrestore(&buf->fifo_lock, flags); | 41 | spin_unlock_irqrestore(&buf->fifo_lock, flags); |
| @@ -56,17 +55,14 @@ static inline int lirc_buffer_init(struct lirc_buffer *buf, · 13 unmodified lines | |||
| 56 | buf->chunk_size = chunk_size; | 55 | buf->chunk_size = chunk_size; |
| 57 | buf->size = size; | 56 | buf->size = size; |
| 58 | ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL); | 57 | ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL); |
| 59 | if (ret == 0) | ||
| 60 | buf->fifo_initialized = 1; | ||
| 61 | 58 | ||
| 62 | return ret; | 59 | return ret; |
| 63 | } | 60 | } |
| 64 | 61 | ||
| 65 | static inline void lirc_buffer_free(struct lirc_buffer *buf) | 62 | static inline void lirc_buffer_free(struct lirc_buffer *buf) |
| 66 | { | 63 | { |
| 67 | if (buf->fifo_initialized) { | 64 | if (kfifo_initialized(&buf->fifo)) { |
| 68 | kfifo_free(&buf->fifo); | 65 | kfifo_free(&buf->fifo); |
| 69 | buf->fifo_initialized = 0; | ||
| 70 | } else | 66 | } else |
| 71 | WARN(1, "calling %s on an uninitialized lirc_buffer\n", | 67 | WARN(1, "calling %s on an uninitialized lirc_buffer\n", |
| 72 | __func__); | 68 | __func__); |