Re: [PATCH v2] netconsole: Append kernel version to message

From: Breno Leitao
Date: Fri Jul 14 2023 - 09:49:47 EST


On Fri, Jul 14, 2023 at 01:41:55PM +0200, Petr Mladek wrote:
> On Fri 2023-07-07 06:29:11, Breno Leitao wrote:
> > @@ -254,6 +267,11 @@ static ssize_t extended_show(struct config_item *item, char *buf)
> > return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended);
> > }
> >
> > +static ssize_t release_show(struct config_item *item, char *buf)
> > +{
> > + return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->release);
>
> I have learned recently that sysfs_emit() was preferred over snprintf() in the
> _show() callbacks.

I didn't know either, I just read about it in the thread. Thanks for the
heads up. We probably want to change it for the other _show() structs.

> > +}
> > +
> > static ssize_t dev_name_show(struct config_item *item, char *buf)
> > {
> > return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name);
> > @@ -366,6 +389,38 @@ static ssize_t enabled_store(struct config_item *item,
> > return err;
> > }
> >
> > +static ssize_t release_store(struct config_item *item, const char *buf,
> > + size_t count)
> > +{
> > + struct netconsole_target *nt = to_target(item);
> > + int release;
> > + int err;
> > +
> > + mutex_lock(&dynamic_netconsole_mutex);
> > + if (nt->enabled) {
> > + pr_err("target (%s) is enabled, disable to update parameters\n",
> > + config_item_name(&nt->item));
> > + err = -EINVAL;
> > + goto out_unlock;
> > + }
> > +
> > + err = kstrtoint(buf, 10, &release);
> > + if (err < 0)
> > + goto out_unlock;
> > + if (release < 0 || release > 1) {
> > + err = -EINVAL;
> > + goto out_unlock;
> > + }
>
> You might consider using:
>
> bool enabled;
>
> err = kstrtobool(buf, &enabled);
> if (err)
> goto unlock;
>
>
> It accepts more input values, for example, 1/0, y/n, Y/N, ...
>
> Well, I see that kstrtoint() is used also in enabled_store().
> It might be confusing when "/enabled" supports only "1/0"
> and "/release" supports more variants.

Right. we probably want to move a few _stores to kstrtobool(). Here is
what I have in mind:
* enabled_store()
* release_store()
* extended_store()

That said, there are two ways moving forward:

1) I forward fix it. I've send v3 earlier today[1], I can send a patch
on top of it.
2) I fix this in a v4 patch. Probably a patchset of 3 patches:
a) Move the current snprintf to emit_sysfs()
b) Move kstrtoint() to kstrtobool()
c) This new feature using emit_sysfs() and kstrtobool().

What is the best way moving forward?


Thanks for the review!
[1] Link: https://lore.kernel.org/all/20230714111330.3069605-1-leitao@xxxxxxxxxx/