Skip to contentSkip to conversation

fix INIT_KFIFO in include/linux/kfifo.h - part 2

PATCH In review David Härdeman 2 participants 2 messages Mar 23, 2010 – Mar 24, 2010 Kfifo

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix INIT_KFIFO in include/linux/kfifo.h - part 2

DECLARE_KFIFO creates a union with a struct kfifo and a buffer array with size [size + sizeof(struct kfifo)].

INIT_KFIFO then sets the buffer pointer in struct kfifo to point to the beginning of the buffer array which means that the first call to kfifo_in will overwrite members of the struct kfifo.

This patch was the least invasive fix I could come up with...

---
 include/linux/kfifo.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
include/linux/kfifo.h +2 -1
index ece0b1c..e117b1a 100644
@@ -86,7 +86,8 @@ union { \
  */
 #define INIT_KFIFO(name) \
 	name = __kfifo_initializer(sizeof(name##kfifo_buffer) - \
-				sizeof(struct kfifo), name##kfifo_buffer)
+				sizeof(struct kfifo), \
+				name##kfifo_buffer + sizeof(struct kfifo))
 
 /**
  * DEFINE_KFIFO - macro to define and initialize a kfifo
Signature · 1 line
1.7.0.3
maintainer Acked-by on v1 1/1
#1 lore raw

DECLARE_KFIFO creates a union with a struct kfifo and a buffer array with size [size + sizeof(struct kfifo)].

INIT_KFIFO then sets the buffer pointer in struct kfifo to point to the beginning of the buffer array which means that the first call to kfifo_in will overwrite members of the struct kfifo.

This patch was the least invasive fix I could come up with...

---
 include/linux/kfifo.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
include/linux/kfifo.h +2 -1
index ece0b1c..e117b1a 100644
@@ -86,7 +86,8 @@ union { \
  */
 #define INIT_KFIFO(name) \
 	name = __kfifo_initializer(sizeof(name##kfifo_buffer) - \
-				sizeof(struct kfifo), name##kfifo_buffer)
+				sizeof(struct kfifo), \
+				name##kfifo_buffer + sizeof(struct kfifo))
 
 /**
  * DEFINE_KFIFO - macro to define and initialize a kfifo