Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1434212 > unrolled thread

[PATCH net-next V3 1/6] ptr_ring: support zero length ring

Started byJason Wang <jasowang@redhat.com>
First post2016-06-30 06:10 +0200
Last post2016-06-30 06:10 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH net-next V3 1/6] ptr_ring: support zero length ring Jason Wang <jasowang@redhat.com> - 2016-06-30 06:10 +0200

#1434212 — [PATCH net-next V3 1/6] ptr_ring: support zero length ring

FromJason Wang <jasowang@redhat.com>
Date2016-06-30 06:10 +0200
Subject[PATCH net-next V3 1/6] ptr_ring: support zero length ring
Message-ID<rPBsB-4Qn-3@gated-at.bofh.it>
Sometimes, we need zero length ring. But current code will crash since
we don't do any check before accessing the ring. This patch fixes this.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 include/linux/ptr_ring.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
index 562a65e..d78b8b8 100644
--- a/include/linux/ptr_ring.h
+++ b/include/linux/ptr_ring.h
@@ -102,7 +102,7 @@ static inline bool ptr_ring_full_bh(struct ptr_ring *r)
  */
 static inline int __ptr_ring_produce(struct ptr_ring *r, void *ptr)
 {
-	if (r->queue[r->producer])
+	if (unlikely(!r->size) || r->queue[r->producer])
 		return -ENOSPC;
 
 	r->queue[r->producer++] = ptr;
@@ -164,7 +164,9 @@ static inline int ptr_ring_produce_bh(struct ptr_ring *r, void *ptr)
  */
 static inline void *__ptr_ring_peek(struct ptr_ring *r)
 {
-	return r->queue[r->consumer];
+	if (likely(r->size))
+		return r->queue[r->consumer];
+	return NULL;
 }
 
 /* Note: callers invoking this in a loop must use a compiler barrier,
-- 
2.7.4

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web