[PATCH 4/5] kfifo: remove kfifo_init

From: Yuanhan Liu
Date: Tue Jan 08 2013 - 09:57:06 EST


kfifo_init is buggy, we should never use that. Instead, we should use
kfifo_alloc.

Cc: Stefani Seibold <stefani@xxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Yuanhan Liu <yuanhan.liu@xxxxxxxxxxxxxxx>
---
include/linux/kfifo.h | 27 ++-------------------------
kernel/kfifo.c | 23 -----------------------
2 files changed, 2 insertions(+), 48 deletions(-)

diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 7a18245..4bf984e 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -27,14 +27,14 @@
*
* - Modify the declaration of the "struct kfifo *" object into a
* in-place "struct kfifo" object
- * - Init the in-place object with kfifo_alloc() or kfifo_init()
+ * - Init the in-place object with kfifo_alloc()
* Note: The address of the in-place "struct kfifo" object must be
* passed as the first argument to this functions
* - Replace the use of __kfifo_put into kfifo_in and __kfifo_get
* into kfifo_out
* - Replace the use of kfifo_put into kfifo_in_spinlocked and kfifo_get
* into kfifo_out_spinlocked
- * Note: the spinlock pointer formerly passed to kfifo_init/kfifo_alloc
+ * Note: the spinlock pointer formerly passed to kfifo_alloc
* must be passed now to the kfifo_in_spinlocked and kfifo_out_spinlocked
* as the last parameter
* - The formerly __kfifo_* functions are renamed into kfifo_*
@@ -350,26 +350,6 @@ __kfifo_int_must_check_helper( \
})

/**
- * kfifo_init - initialize a fifo using a preallocated buffer
- * @fifo: the fifo to assign the buffer
- * @buffer: the preallocated buffer to be used
- * @size: the size of the internal buffer, this have to be a power of 2
- *
- * This macro initialize a fifo using a preallocated buffer.
- *
- * The numer of elements will be rounded-up to a power of 2.
- * Return 0 if no error, otherwise an error code.
- */
-#define kfifo_init(fifo, buffer, size) \
-({ \
- typeof((fifo) + 1) __tmp = (fifo); \
- struct __kfifo *__kfifo = &__tmp->kfifo; \
- __is_kfifo_ptr(__tmp) ? \
- __kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \
- -EINVAL; \
-})
-
-/**
* kfifo_put - put data into the fifo
* @fifo: address of the fifo to be used
* @val: the data to be added
@@ -770,9 +750,6 @@ extern int __kfifo_alloc(struct __kfifo *fifo, unsigned int size,

extern void __kfifo_free(struct __kfifo *fifo);

-extern int __kfifo_init(struct __kfifo *fifo, void *buffer,
- unsigned int size, size_t esize);
-
extern unsigned int __kfifo_in(struct __kfifo *fifo,
const void *buf, unsigned int len);

diff --git a/kernel/kfifo.c b/kernel/kfifo.c
index 59dcf5b..d07f480 100644
--- a/kernel/kfifo.c
+++ b/kernel/kfifo.c
@@ -78,29 +78,6 @@ void __kfifo_free(struct __kfifo *fifo)
}
EXPORT_SYMBOL(__kfifo_free);

-int __kfifo_init(struct __kfifo *fifo, void *buffer,
- unsigned int size, size_t esize)
-{
- size /= esize;
-
- if (!is_power_of_2(size))
- size = rounddown_pow_of_two(size);
-
- fifo->in = 0;
- fifo->out = 0;
- fifo->esize = esize;
- fifo->data = buffer;
-
- if (size < 2) {
- fifo->mask = 0;
- return -EINVAL;
- }
- fifo->mask = size - 1;
-
- return 0;
-}
-EXPORT_SYMBOL(__kfifo_init);
-
static void kfifo_copy_in(struct __kfifo *fifo, const void *src,
unsigned int len, unsigned int off)
{
--
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/