From: Breno Leitao <leitao@debian.org>
To: Petr Mladek <pmladek@suse.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
sergey.senozhatsky@gmail.com, tj@kernel.org,
stephen@networkplumber.org, Dave Jones <davej@codemonkey.org.uk>,
"open list:NETWORKING [GENERAL]" <netdev@vger.kernel.org>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] netconsole: Append kernel version to message
Date: Fri, 14 Jul 2023 06:49:37 -0700 [thread overview]
Message-ID: <ZLFScfJtt/9ClORF@gmail.com> (raw)
In-Reply-To: <ZLE0g9NXYZvlGcyy@alley>
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@debian.org/
prev parent reply other threads:[~2023-07-14 13:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 13:29 [PATCH v2] netconsole: Append kernel version to message Breno Leitao
2023-07-07 23:10 ` Jakub Kicinski
2023-07-10 8:49 ` Breno Leitao
2023-07-14 11:41 ` Petr Mladek
2023-07-14 13:49 ` Breno Leitao [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZLFScfJtt/9ClORF@gmail.com \
--to=leitao@debian.org \
--cc=corbet@lwn.net \
--cc=davej@codemonkey.org.uk \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pmladek@suse.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=stephen@networkplumber.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).