[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0jXKNr3_W9B_raetj42UOdphA3GEE_Qh7nBSwDzwXfA1Q@mail.gmail.com>
Date: Tue, 4 Jun 2019 22:50:54 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Masahiro Yamada <yamada.masahiro@...ionext.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>
Subject: Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
On Tue, Jun 4, 2019 at 8:00 PM Masahiro Yamada
<yamada.masahiro@...ionext.com> wrote:
>
> This function never attempts to allocate memory, so returning -ENOMEM
> looks weird to me.
And why is the "looks weird to me" a good enough reason for making
changes like this?
The existing behavior is known and documented AFAICS and is it really
so confusing?
> The reason of the failure is there is no more space
> in the given kobj_uevent_env structure.
>
> No caller of this function relies on this functing returning a specific
> error code, so just change it to return -ENOSPC. The intended change,
> if any, is the error number displayed in log messages.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@...ionext.com>
> ---
>
> lib/kobject_uevent.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
> index 7998affa45d4..5ffd44bf4aad 100644
> --- a/lib/kobject_uevent.c
> +++ b/lib/kobject_uevent.c
> @@ -647,7 +647,7 @@ EXPORT_SYMBOL_GPL(kobject_uevent);
> * @env: environment buffer structure
> * @format: printf format for the key=value pair
> *
> - * Returns 0 if environment variable was added successfully or -ENOMEM
> + * Returns 0 if environment variable was added successfully or -ENOSPC
> * if no space was available.
> */
> int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
> @@ -657,7 +657,7 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
>
> if (env->envp_idx >= ARRAY_SIZE(env->envp)) {
> WARN(1, KERN_ERR "add_uevent_var: too many keys\n");
> - return -ENOMEM;
> + return -ENOSPC;
> }
>
> va_start(args, format);
> @@ -668,7 +668,7 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
>
> if (len >= (sizeof(env->buf) - env->buflen)) {
> WARN(1, KERN_ERR "add_uevent_var: buffer size too small\n");
> - return -ENOMEM;
> + return -ENOSPC;
> }
>
> env->envp[env->envp_idx++] = &env->buf[env->buflen];
> --
> 2.17.1
>
Powered by blists - more mailing lists