From: Drew Fustini <drew@beagleboard.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
Jason Kridner <jkridner@beagleboard.org>,
Robert Nelson <robertcnelson@beagleboard.org>,
Linus Walleij <linus.walleij@linaro.org>,
Tony Lindgren <tony@atomide.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: [RFC PATCH] pinctrl: pinmux: Add pinmux-set debugfs file
Date: Fri, 22 Jan 2021 15:16:08 -0800 [thread overview]
Message-ID: <20210122231608.GA13062@x1> (raw)
In-Reply-To: <CAHp75Vejt3mN4SBTVnRkyLkDA+jnh3Y4pC5bOGdKAdUZGCPFWw@mail.gmail.com>
On Fri, Jan 22, 2021 at 11:50:52AM +0200, Andy Shevchenko wrote:
> On Fri, Jan 22, 2021 at 1:26 AM Drew Fustini <drew@beagleboard.org> wrote:
> > On Thu, Jan 21, 2021 at 01:18:58PM +0200, Andy Shevchenko wrote:
> > > On Thu, Jan 21, 2021 at 7:18 AM Drew Fustini <drew@beagleboard.org> wrote:
>
> ...
>
> > > > RFC question: should pinmux-set take function name and group name
> > > > instead of the selector numbers?
> > >
> > > I would prefer names and integers (but from user p.o.v. names are
> > > easier to understand, while numbers are good for scripting).
> >
> > I don't actually see any example of looking up the function name in the
> > existing pinctrl code. There is pin_function_tree in struct pinctrl_dev.
> > pinmux_generic_get_function_name() does radix_tree_lookup() with the
> > selector integer as the key, but there is no corresponding "get function
> > selector by name" function.
> >
> > I think I would need to go through all the nodes in the radix tree to
> > find the name that matches. Although, I am just learning now about the
> > radix implementation in Linux so there might be a simpler way that I am
> > missing.
>
> I probably have to revive my work towards gluing ACPI with pin control
> where AFAIR I have created some kind of radix / rbtree for something
> (not sure it's exactly what you need here, so consider this just as a
> side note).
>
> ...
>
> > > The following is better to include in documentation and remove from
> > > the commit message.
>
> > > Shorter is better, what about simply
> > >
> > > # cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pinmux-functions
> > > ?
> > >
> > > Btw in reST format you may create a nice citation of this. And yes,
> > > this should also go to the documentation.
> >
> > Good point, I'll shorten the example lines in v2.
>
> Even better to tell that we operate on the level of mount point of
> debugfs and use
>
> # cat pinctrl/44e10800.pinmux-pinctrl-single/pinmux-functions
>
> > > This and above is still part of documentation, and not a commit message thingy.
> >
> > Is something I should add to Documentation/driver-api/pinctl.rst in a
> > seperate patch?
>
> Not sure, I think more about as a part of this very path you change
> code and documentation. But usually it's a preference of the certain
> subsystem.
>
> ...
>
> > > > + if (cnt == 0)
> > > > + return 0;
> > >
> > > Has it ever happened here?
> >
> > Good point, I guess there is no reason for userspace to write 0 bytes.
>
> My point is that this check is done somewhere in the guts of kernfs.
> When in doubt I recommend to look around in the kernel and check most
> recent code with similar code pieces.
>
> ...
>
> > > > + buf = memdup_user_nul(user_buf, cnt);
> > > > + if (IS_ERR(buf))
> > > > + return PTR_ERR(buf);
> > > > +
> > > > + if (buf[cnt - 1] == '\n')
> > > > + buf[cnt - 1] = '\0';
> > >
> > > Shouldn't you rather use strndup_from_user() (or how is it called?)
>
> Any comments?
Sorry, I had meant to comment on that. I tried strndup_user() but had
difficulty in using it as 'length > n' was always true and thus returned
an error. There are not that many users of it either.
I've switched to this based on how armada_debugfs_crtc_reg_write() in
armada_debugfs.c handles the user writing multiple integers:
char buf[16];
if (cnt > sizeof(buf) - 1)
cnt = sizeof(buf) - 1;
ret = strncpy_from_user(buf, user_buf, cnt);
if (ret < 0)
return ret;
buf[cnt] = '\0';
if (buf[cnt - 1] == '\n')
buf[cnt - 1] = '\0';
// the parse with sscanf()
I choose 16 for buf as two integer numbers seperated by a space should
never be more than 16. I suppose the downside is that it is allocated
on the stack but it is a small buffer.
I'll post v2 so it can be evaluated in the full patch context.
>
> ...
>
> > > Can be simply
> > >
> > > err_freebuf:
> > > kfree(buf);
> > > return err ?: cnt;
> >
> > Thanks, I didn't really like the duplication but was having trouble
> > thinking of a cleaner way to write it. That is good to know it is ok to
> > use the ternary operator in a return statement.
>
> Again, depends on certain subsystem maintainer's preferences.
>
>
> > > > + debugfs_create_file("pinmux-set", S_IFREG | S_IWUSR,
> > > > + devroot, pctldev, &pinmux_set_ops);
>
> One more thing, as a preparatory patch please move from S_I* to plain
> octal numbers as it's preferable.
>
>
> --
> With Best Regards,
> Andy Shevchenko
prev parent reply other threads:[~2021-01-22 23:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-21 5:18 [RFC PATCH] pinctrl: pinmux: Add pinmux-set debugfs file Drew Fustini
2021-01-21 11:18 ` Andy Shevchenko
2021-01-21 23:26 ` Drew Fustini
2021-01-22 9:50 ` Andy Shevchenko
2021-01-22 23:16 ` Drew Fustini [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=20210122231608.GA13062@x1 \
--to=drew@beagleboard.org \
--cc=alexandre.belloni@bootlin.com \
--cc=andy.shevchenko@gmail.com \
--cc=geert@linux-m68k.org \
--cc=jkridner@beagleboard.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=pantelis.antoniou@konsulko.com \
--cc=robertcnelson@beagleboard.org \
--cc=tony@atomide.com \
/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).