lkml.org 
[lkml]   [2010]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: kfifo has temporarily invalid in pointer?
From
Hi Robert,

On Mon, Mar 15, 2010 at 4:58 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:
>
>  (i am not trying to be annoyingly obsessive about the kernel kfifo,
> i am merely succeeding.)
:P
>  what appears to be a bit of an oddity WRT kfifo:  since a kfifo is
> defined with a fixed buffer size, it obviously enqueues and dequeues
> in a circular fashion.  so, the code to add some data to a kfifo (from
> kernel/kfifo.c):
>
> =====
> unsigned int kfifo_in(struct kfifo *fifo, const void *from,
>                                unsigned int len)
> {
>        len = min(kfifo_avail(fifo), len);
>
>        __kfifo_in_data(fifo, from, len, 0);
>        __kfifo_add_in(fifo, len);
>        return len;
> }
> =====
>
>  fair enough -- that first routine adds the data itself, while the
> second one correspondingly bumps up the pointer, which could
> conceivably wrap around to follow the data, correct?  but from
> include/linux.kfifo.h:len = min(kfifo_avail(fifo), len);

Wrong :). If you notice len is truncated using:
len = min(kfifo_avail(fifo), len);

>
> =====
> static inline void __kfifo_add_in(struct kfifo *fifo,
>                                unsigned int off)
> {
>        smp_wmb();
>        fifo->in += off;
> }
So, fifo->in + min(kfifo_avail(fifo), len) < fifo->size, every time.

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

\
 
 \ /
  Last update: 2010-03-15 17:09    [W:0.019 / U:80.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site