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>
Signed-off-by: David S. Miller <davem@davemloft.net>
*/
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;
*/
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,