[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <52A8F4E0.5080402@gmail.com>
Date: Thu, 12 Dec 2013 10:27:28 +1100
From: Ryan Mallon <rmallon@...il.com>
To: Joe Perches <joe@...ches.com>,
Alexander Viro <viro@...iv.linux.org.uk>
CC: Kees Cook <keescook@...omium.org>, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH -next 1/3] seq: Add a seq_overflow test.
On 11/12/13 16:12, Joe Perches wrote:
> seq_printf and seq_puts returns are often misused.
>
> Instead of checking the seq_printf or seq_puts return,
> add a new seq_overflow function to test if a seq_file has
> overflowed the available buffer space.
>
> This will eventually allow seq_printf and seq_puts to be
> converted to have a void return instead of the int return
> that is often assumed to have a size_t value instead of an
> error/no-error value.
>
> Signed-off-by: Joe Perches <joe@...ches.com>
> ---
> fs/seq_file.c | 15 ++++++++-------
> include/linux/seq_file.h | 2 ++
> 2 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/fs/seq_file.c b/fs/seq_file.c
> index 1d641bb..aab0736 100644
> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -14,16 +14,17 @@
> #include <asm/uaccess.h>
> #include <asm/page.h>
>
> -
> -/*
> - * seq_files have a buffer which can may overflow. When this happens a larger
> - * buffer is reallocated and all the data will be printed again.
> - * The overflow state is true when m->count == m->size.
> +/**
> + * seq_overflow - test if a seq_file has overflowed the space available
> + * @m: the seq_file handle
> + *
> + * Returns -1 when an overflow has occurred, 0 otherwise.
> */
> -static bool seq_overflow(struct seq_file *m)
> +int seq_overflow(struct seq_file *m)
> {
> - return m->count == m->size;
> + return m->count == m->size ? -1 : 0;
> }
> +EXPORT_SYMBOL(seq_overflow);
What is the reasoning in making this return int instead of bool? Having
it return int encourages people to do:
return seq_overflow(s);
When used in seq_file functions will return -EPERM (-1) to user-space,
which is confusing. It should probably return bool and let the caller
sort out the correct error to return.
~Ryan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists