Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function annotation description in the simrupt.c file seems to be wrong. #3

Open
pao0626 opened this issue Jun 27, 2024 · 1 comment

Comments

@pao0626
Copy link

pao0626 commented Jun 27, 2024

The comment in the produce_data function mentions "skip oldest element if kfifo buffer is full".

static void produce_data(unsigned char val)
{
    /* Implement a kind of circular FIFO here (skip oldest element if kfifo
     * buffer is full).
     */
    unsigned int len = kfifo_in(&rx_fifo, &val, sizeof(val));
    if (unlikely(len < sizeof(val)) && printk_ratelimit())
        pr_warn("%s: %zu bytes dropped\n", __func__, sizeof(val) - len);

    pr_debug("simrupt: %s: in %u/%u bytes\n", __func__, len,
             kfifo_len(&rx_fifo));
}

But in fact, it seems that when the buffer is full, it will choose not to insert new data, because the implementation of kfifo_in will first confirm whether the size to be put is greater than the remaining size. If it is, the remaining size will be the main one.

[ref: https://elixir.bootlin.com/linux/latest/source/lib/kfifo.c#L113]

unsigned int __kfifo_in(struct __kfifo *fifo,
                        const void *buf, unsigned int len)
{
    unsigned int l;

    l = kfifo_unused(fifo);
    if (len > l)
        len = l;

    kfifo_copy_in(fifo, buf, len, fifo->in);
    fifo->in += len;
    return len;
}
@pao0626 pao0626 changed the title About simrupt.c code comments label:invalid About simrupt.c code comments Jun 27, 2024
@pao0626 pao0626 changed the title label:invalid About simrupt.c code comments About simrupt.c code comments Jun 27, 2024
@jserv
Copy link
Contributor

jserv commented Jun 27, 2024

Refine the subject of this issue to make it more informative. In addition, you should provide some code snippets to emphasize the case you are concerned about.

@pao0626 pao0626 changed the title About simrupt.c code comments The function annotation description in the simrupt.c file seems to be wrong. Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants