mbox series

[v5,0/2] pinctrl: pinmux: Add pinmux-select debugfs file

Message ID 20210212223015.727608-1-drew@beagleboard.org
Headers show
Series pinctrl: pinmux: Add pinmux-select debugfs file | expand

Message

Drew Fustini Feb. 12, 2021, 10:30 p.m. UTC
This series first converts the debugfs files in the pinctrl subsystem to
octal permissions and then adds a new debugfs file "pinmux-select".

Function name and group name can be written to "pinmux-select" which
will cause the function and group to be activated on the pin controller.

Notes for PATCH v5:
- convert permissions from symbolic to octal for debugfs_create_file()
  calls in core.c that Joe Perches pointed out I had missed
- Linus W: please let me know if I should break this series apart as you
  already applied an earlier version of octal conversion patch today [1]
- switch from sscanf() to just pointing to function name and group name
  inside of the buffer. This also avoids having to allocate additional
  buffers for fname and gname. Geert and Andy highlighted this security
  issue and Andy suggested code to use instead of sscanf().
- switch from devm_kfree() to kfree() after Dan Carpenter warned me
- remove .read from pinmux_select_ops per Geert since it is write only
- add usage format to error when unable find fname or gname in buffer

Notes for PATCH v4:
- correct the commit message in the second patch to reference function
  and group name instead of integer selectors. Apologies for not fixing
  that in v3
- fix typos in cover letter

Notes for PATCH v3:
- add Suggested-by: Andy Shevchenko to the "pinctrl: use to octal
  permissions for debugfs files" patch
- change the octal permissions from 0400 to 0444 to correctly match the
  symbolic permissions (thanks to Joe Perches and Geert Uytterhoeven)
- note that S_IFREG flag is added to the mode in __debugfs_create_file()
  (thanks to Andy for highlighting this and Joe for suggesting I should
  add a note to the commit message)
- fix order of the goto labels so that the buffers are freed correctly
  as suggested by Dan Carpenter
- move from devm_kzalloc() to kzalloc() as the buffers are only used
  inside the pinmux_select() function and not related to the lifetime
  of the pin controller device (thanks to Andy for pointing this out)
- correct the pinmux-select example in commit message to use the
  function and group name instead of selector (thanks to Geert)

Notes for PATCH v2:
- create patch series that includes patch to switch all the debugfs
  files in pinctrl subsystem over to octal permission
- write function name and group name, instead of error-prone selector
  numbers, to the 'pinmux-select' file
- switch from static to dynamic allocation for the kernel buffer filled
  by strncpy_from_user()
- look up function selector from function name using
  pinmux_func_name_to_selector()
- validate group name with get_function_groups() and match_string()
- look up selector for group name with pinctrl_get_group_selector()

Notes for PATCH v1:
- posted seperate patch to switch all the debugfs files in pinctrl
  subsystem over to octal permission
- there is no existing documentation for any of the debugfs enteries for
  pinctrl, so it seemed to have a bigger scope than just this patch. I
  also noticed that rst documentation is confusingly named "pinctl" (no
  'r') and started thread about that [2]. Linus suggested chaning that
  to 'pin-control'. Thus I am planning a seperate documentation patch
  series where the file is renamed, references changed and a section on
  the pinctrl debugfs files is added.

Notes for RFC v2 [3]:
- rename debugfs file "pinmux-set" to "pinmux-select"
- renmae pinmux_set_write() to pinmux_select()
- switch from memdup_user_nul() to strncpy_from_user()
- switch from pr_warn() to dev_err()

[1] https://lore.kernel.org/linux-gpio/20210126044742.87602-1-drew@beagleboard.org/
[2] https://lore.kernel.org/linux-gpio/20210126050817.GA187797@x1/
[3] https://lore.kernel.org/linux-gpio/20210123064909.466225-1-drew@beagleboard.org/

Drew Fustini (2):
  pinctrl: use to octal permissions for debugfs files
  pinctrl: pinmux: Add pinmux-select debugfs file

 drivers/pinctrl/core.c    |  12 ++---
 drivers/pinctrl/pinconf.c |   4 +-
 drivers/pinctrl/pinmux.c  | 103 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 109 insertions(+), 10 deletions(-)

Comments

Andy Shevchenko Feb. 13, 2021, 12:56 p.m. UTC | #1
On Sat, Feb 13, 2021 at 12:30 AM Drew Fustini <drew@beagleboard.org> wrote:
>

> Switch over pinctrl debugfs files to use octal permissions as they are

> preferred over symbolic permissions. Refer to commit f90774e1fd27

> ("checkpatch: look for symbolic permissions and suggest octal instead").

>

> Note: S_IFREG flag is added to the mode by __debugfs_create_file()

> in fs/debugfs/inode.c


I guess it also needs Suggested-by: Joe (IIRC he proposed to convert the rest).
Nevertheless,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

Thanks!


> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Drew Fustini <drew@beagleboard.org>

> ---

>  drivers/pinctrl/core.c    | 12 ++++++------

>  drivers/pinctrl/pinconf.c |  4 ++--

>  drivers/pinctrl/pinmux.c  |  4 ++--

>  3 files changed, 10 insertions(+), 10 deletions(-)

>

> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c

> index 3663d87f51a0..07458742bc0f 100644

> --- a/drivers/pinctrl/core.c

> +++ b/drivers/pinctrl/core.c

> @@ -1888,11 +1888,11 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)

>                         dev_name(pctldev->dev));

>                 return;

>         }

> -       debugfs_create_file("pins", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pins", 0444,

>                             device_root, pctldev, &pinctrl_pins_fops);

> -       debugfs_create_file("pingroups", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pingroups", 0444,

>                             device_root, pctldev, &pinctrl_groups_fops);

> -       debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,

> +       debugfs_create_file("gpio-ranges", 0444,

>                             device_root, pctldev, &pinctrl_gpioranges_fops);

>         if (pctldev->desc->pmxops)

>                 pinmux_init_device_debugfs(device_root, pctldev);

> @@ -1914,11 +1914,11 @@ static void pinctrl_init_debugfs(void)

>                 return;

>         }

>

> -       debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinctrl-devices", 0444,

>                             debugfs_root, NULL, &pinctrl_devices_fops);

> -       debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinctrl-maps", 0444,

>                             debugfs_root, NULL, &pinctrl_maps_fops);

> -       debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinctrl-handles", 0444,

>                             debugfs_root, NULL, &pinctrl_fops);

>  }

>

> diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c

> index 02c075cc010b..d9d54065472e 100644

> --- a/drivers/pinctrl/pinconf.c

> +++ b/drivers/pinctrl/pinconf.c

> @@ -370,9 +370,9 @@ DEFINE_SHOW_ATTRIBUTE(pinconf_groups);

>  void pinconf_init_device_debugfs(struct dentry *devroot,

>                          struct pinctrl_dev *pctldev)

>  {

> -       debugfs_create_file("pinconf-pins", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinconf-pins", 0444,

>                             devroot, pctldev, &pinconf_pins_fops);

> -       debugfs_create_file("pinconf-groups", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinconf-groups", 0444,

>                             devroot, pctldev, &pinconf_groups_fops);

>  }

>

> diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c

> index bab888fe3f8e..c651b2db0925 100644

> --- a/drivers/pinctrl/pinmux.c

> +++ b/drivers/pinctrl/pinmux.c

> @@ -676,9 +676,9 @@ DEFINE_SHOW_ATTRIBUTE(pinmux_pins);

>  void pinmux_init_device_debugfs(struct dentry *devroot,

>                          struct pinctrl_dev *pctldev)

>  {

> -       debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinmux-functions", 0444,

>                             devroot, pctldev, &pinmux_functions_fops);

> -       debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO,

> +       debugfs_create_file("pinmux-pins", 0444,

>                             devroot, pctldev, &pinmux_pins_fops);

>  }

>

> --

> 2.25.1

>



-- 
With Best Regards,
Andy Shevchenko