* [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
@ 2019-06-04 17:44 Masahiro Yamada
2019-06-04 20:50 ` Rafael J. Wysocki
2019-06-10 17:45 ` Greg Kroah-Hartman
0 siblings, 2 replies; 7+ messages in thread
From: Masahiro Yamada @ 2019-06-04 17:44 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-kernel, Masahiro Yamada, Rafael J. Wysocki
This function never attempts to allocate memory, so returning -ENOMEM
looks weird to me. 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@socionext.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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
2019-06-04 17:44 [PATCH] kobject: return -ENOSPC when add_uevent_var() fails Masahiro Yamada
@ 2019-06-04 20:50 ` Rafael J. Wysocki
2019-06-07 11:53 ` Masahiro Yamada
2019-06-10 17:45 ` Greg Kroah-Hartman
1 sibling, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-06-04 20:50 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Greg Kroah-Hartman, Linux Kernel Mailing List, Rafael J. Wysocki
On Tue, Jun 4, 2019 at 8:00 PM Masahiro Yamada
<yamada.masahiro@socionext.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@socionext.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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
2019-06-04 20:50 ` Rafael J. Wysocki
@ 2019-06-07 11:53 ` Masahiro Yamada
2019-06-07 12:26 ` Rafael J. Wysocki
0 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2019-06-07 11:53 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, Linux Kernel Mailing List
On Wed, Jun 5, 2019 at 5:53 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Tue, Jun 4, 2019 at 8:00 PM Masahiro Yamada
> <yamada.masahiro@socionext.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?
Since the code is read much more than written,
this change eliminates the question of "why -ENOMEM here?"
Masahiro Yamada
> 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@socionext.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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
2019-06-07 11:53 ` Masahiro Yamada
@ 2019-06-07 12:26 ` Rafael J. Wysocki
0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-06-07 12:26 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Rafael J. Wysocki, Greg Kroah-Hartman, Linux Kernel Mailing List
On Fri, Jun 7, 2019 at 2:02 PM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> On Wed, Jun 5, 2019 at 5:53 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Tue, Jun 4, 2019 at 8:00 PM Masahiro Yamada
> > <yamada.masahiro@socionext.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?
>
>
> Since the code is read much more than written,
> this change eliminates the question of "why -ENOMEM here?"
And you are sure that nobody relies on the current return value?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
2019-06-04 17:44 [PATCH] kobject: return -ENOSPC when add_uevent_var() fails Masahiro Yamada
2019-06-04 20:50 ` Rafael J. Wysocki
@ 2019-06-10 17:45 ` Greg Kroah-Hartman
2019-06-10 21:09 ` Masahiro Yamada
1 sibling, 1 reply; 7+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-10 17:45 UTC (permalink / raw)
To: Masahiro Yamada; +Cc: linux-kernel, Rafael J. Wysocki
On Wed, Jun 05, 2019 at 02:44:12AM +0900, Masahiro Yamada wrote:
> This function never attempts to allocate memory, so returning -ENOMEM
> looks weird to me. 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@socionext.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;
As Rafael says, changing this for no good reason is not a good idea,
sorry. Let's live with it as-is unless you can show some place where
this specific error value is causing problems.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
2019-06-10 17:45 ` Greg Kroah-Hartman
@ 2019-06-10 21:09 ` Masahiro Yamada
2019-06-19 17:25 ` Greg Kroah-Hartman
0 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2019-06-10 21:09 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Linux Kernel Mailing List, Rafael J. Wysocki
On Tue, Jun 11, 2019 at 2:47 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Wed, Jun 05, 2019 at 02:44:12AM +0900, Masahiro Yamada wrote:
> > This function never attempts to allocate memory, so returning -ENOMEM
> > looks weird to me. 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@socionext.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;
>
> As Rafael says, changing this for no good reason is not a good idea,
> sorry. Let's live with it as-is unless you can show some place where
> this specific error value is causing problems.
Didn't you see WARN() above the return code?
I rephrased the commit log for clarification in v2.
Thanks.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] kobject: return -ENOSPC when add_uevent_var() fails
2019-06-10 21:09 ` Masahiro Yamada
@ 2019-06-19 17:25 ` Greg Kroah-Hartman
0 siblings, 0 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-19 17:25 UTC (permalink / raw)
To: Masahiro Yamada; +Cc: Linux Kernel Mailing List, Rafael J. Wysocki
On Tue, Jun 11, 2019 at 06:09:55AM +0900, Masahiro Yamada wrote:
> On Tue, Jun 11, 2019 at 2:47 AM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > On Wed, Jun 05, 2019 at 02:44:12AM +0900, Masahiro Yamada wrote:
> > > This function never attempts to allocate memory, so returning -ENOMEM
> > > looks weird to me. 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@socionext.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;
> >
> > As Rafael says, changing this for no good reason is not a good idea,
> > sorry. Let's live with it as-is unless you can show some place where
> > this specific error value is causing problems.
>
>
>
> Didn't you see WARN() above the return code?
Yes.
> I rephrased the commit log for clarification in v2.
It still doesn't matter :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-06-19 17:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04 17:44 [PATCH] kobject: return -ENOSPC when add_uevent_var() fails Masahiro Yamada
2019-06-04 20:50 ` Rafael J. Wysocki
2019-06-07 11:53 ` Masahiro Yamada
2019-06-07 12:26 ` Rafael J. Wysocki
2019-06-10 17:45 ` Greg Kroah-Hartman
2019-06-10 21:09 ` Masahiro Yamada
2019-06-19 17:25 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).