linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dario Binacchi <dariobin@libero.it>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Drew Fustini <drew@beagleboard.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [PATCH 1/2] pinctrl: core: configure pinmux from pins debug file
Date: Tue, 18 May 2021 15:57:42 +0200 (CEST)	[thread overview]
Message-ID: <1735504854.166374.1621346262270@mail1.libero.it> (raw)
In-Reply-To: <CAHp75Vd8875hRNk1JK6gkmfxjqxBSu4cRNE1zJt9TyEW7TvsMg@mail.gmail.com>

Hi,

> Il 17/05/2021 22:02 Andy Shevchenko <andy.shevchenko@gmail.com> ha scritto:
> 
>  
> On Sun, May 16, 2021 at 7:43 PM Dario Binacchi <dariobin@libero.it> wrote:
> >
> > The MPUs of some architectures (e.g AM335x) must be in privileged
> > operating mode to write on the pinmux
> 
> pinmux is not pin configuration. You need to rethink the approach.
> 
> > registers. In such cases, where
> > writes will not work from user space, now it can be done from the pins
> > debug file if the platform driver exports the pin_dbg_set() helper among
> > the registered operations.
> 
> Drew, is it similar to what you are trying to achieve?
> 
> ...
> 
> > +static ssize_t pinctrl_pins_write(struct file *file,
> > +                                 const char __user *user_buf, size_t count,
> > +                                 loff_t *ppos)
> > +{
> > +       struct seq_file *s = file->private_data;
> > +       struct pinctrl_dev *pctldev = s->private;
> > +       const struct pinctrl_ops *ops = pctldev->desc->pctlops;
> > +       char buf[32];
> > +       char *c = &buf[0];
> > +       char *token;
> > +       int ret, buf_size;
> > +       unsigned int i, pin;
> > +
> > +       if (!ops->pin_dbg_set)
> > +               return -EFAULT;
> > +
> > +       /* Get userspace string and assure termination */
> > +       buf_size = min(count, sizeof(buf) - 1);
> > +       if (copy_from_user(buf, user_buf, buf_size))
> > +               return -EFAULT;
> > +
> > +       buf[buf_size] = 0;
> 
> Can't you use strncpy_from_user() ?

Ok, I'll use strncpy_from_user() in the next version of the patch

> 
> 
> > +       token = strsep(&c, " ");
> 
> > +       if (kstrtouint(token, 0, &pin))
> > +               return -EINVAL;
> 
> Don't shadow an error code.

You are right

> 
> > +       for (i = 0; i < pctldev->desc->npins; i++) {
> > +               if (pin != pctldev->desc->pins[i].number)
> > +                       continue;
> 
> Hmm... I don't get this. Why is it needed?

I want to make sure the pin is managed

Thanks and regards,
Dario
> 
> > +               ret = ops->pin_dbg_set(pctldev, pin, c);
> > +               if (ret)
> > +                       return ret;
> > +
> > +               return count;
> > +       }
> > +
> > +       return -EINVAL;
> > +}
> 
> ...
> 
> > -       debugfs_create_file("pins", 0444,
> > +       debugfs_create_file("pins", 0644,
> >                             device_root, pctldev, &pinctrl_pins_fops);
> 
> Why is it in this file?
> 
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko

  parent reply	other threads:[~2021-05-18 13:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-16 13:55 [PATCH 0/2] am335x: set pinmux registers from pins debug file Dario Binacchi
2021-05-16 13:55 ` [PATCH 1/2] pinctrl: core: configure pinmux " Dario Binacchi
2021-05-17 20:02   ` Andy Shevchenko
2021-05-17 22:57     ` Drew Fustini
2021-05-18  9:38       ` Dario Binacchi
2021-05-18 10:21         ` Drew Fustini
2021-05-18 10:41           ` Andy Shevchenko
2021-05-18 13:57     ` Dario Binacchi [this message]
2021-05-18 14:01       ` Andy Shevchenko
2021-05-19 10:02         ` Drew Fustini
2021-05-19 11:27           ` Andy Shevchenko
2021-05-20  4:17             ` Drew Fustini
2021-05-20  8:10               ` Andy Shevchenko
2021-05-16 13:55 ` [PATCH 2/2] pinctrl: single: set " Dario Binacchi
2021-05-17  5:57   ` Tony Lindgren

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=1735504854.166374.1621346262270@mail1.libero.it \
    --to=dariobin@libero.it \
    --cc=andy.shevchenko@gmail.com \
    --cc=drew@beagleboard.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.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).