All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] pinctrl: pinmux: Add pinmux-select debugfs file
@ 2021-02-10 22:28 Drew Fustini
  2021-02-10 22:28 ` [PATCH v4 1/2] pinctrl: use to octal permissions for debugfs files Drew Fustini
  2021-02-10 22:28 ` [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
  0 siblings, 2 replies; 17+ messages in thread
From: Drew Fustini @ 2021-02-10 22:28 UTC (permalink / raw)
  To: Linus Walleij, linux-gpio, linux-kernel, Tony Lindgren,
	Andy Shevchenko, Alexandre Belloni, Geert Uytterhoeven,
	Pantelis Antoniou, Jason Kridner, Robert Nelson, Joe Perches,
	Dan Carpenter
  Cc: Drew Fustini

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 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 [1]
- 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    |   6 +--
 drivers/pinctrl/pinconf.c |   4 +-
 drivers/pinctrl/pinmux.c  | 111 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 114 insertions(+), 7 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file
@ 2021-02-11  4:32 kernel test robot
  0 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2021-02-11  4:32 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 8258 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210210222851.232374-3-drew@beagleboard.org>
References: <20210210222851.232374-3-drew@beagleboard.org>
TO: Drew Fustini <drew@beagleboard.org>
TO: Linus Walleij <linus.walleij@linaro.org>
TO: linux-gpio(a)vger.kernel.org
TO: linux-kernel(a)vger.kernel.org
TO: Tony Lindgren <tony@atomide.com>
TO: Andy Shevchenko <andy.shevchenko@gmail.com>
TO: Alexandre Belloni <alexandre.belloni@bootlin.com>
TO: Geert Uytterhoeven <geert@linux-m68k.org>
TO: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
TO: Jason Kridner <jkridner@beagleboard.org>
TO: Robert Nelson <robertcnelson@beagleboard.org>

Hi Drew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on pinctrl/devel]
[also build test WARNING on v5.11-rc7 next-20210125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Drew-Fustini/pinctrl-pinmux-Add-pinmux-select-debugfs-file/20210211-063617
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago
config: x86_64-randconfig-m001-20210211 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/pinctrl/pinmux.c:764 pinmux_select() warn: possible memory leak of 'gname'

vim +/gname +764 drivers/pinctrl/pinmux.c

2744e8afb3b763 Linus Walleij 2011-05-02  675  
f878efc17642ce Drew Fustini  2021-02-10  676  #define PINMUX_MAX_NAME 64
f878efc17642ce Drew Fustini  2021-02-10  677  static ssize_t pinmux_select(struct file *file, const char __user *user_buf,
f878efc17642ce Drew Fustini  2021-02-10  678  				   size_t len, loff_t *ppos)
f878efc17642ce Drew Fustini  2021-02-10  679  {
f878efc17642ce Drew Fustini  2021-02-10  680  	struct seq_file *sfile = file->private_data;
f878efc17642ce Drew Fustini  2021-02-10  681  	struct pinctrl_dev *pctldev = sfile->private;
f878efc17642ce Drew Fustini  2021-02-10  682  	const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
f878efc17642ce Drew Fustini  2021-02-10  683  	const char *const *groups;
f878efc17642ce Drew Fustini  2021-02-10  684  	char *buf, *fname, *gname;
f878efc17642ce Drew Fustini  2021-02-10  685  	unsigned int num_groups;
f878efc17642ce Drew Fustini  2021-02-10  686  	int fsel, gsel, ret;
f878efc17642ce Drew Fustini  2021-02-10  687  
f878efc17642ce Drew Fustini  2021-02-10  688  	if (len > (PINMUX_MAX_NAME * 2)) {
f878efc17642ce Drew Fustini  2021-02-10  689  		dev_err(pctldev->dev, "write too big for buffer");
f878efc17642ce Drew Fustini  2021-02-10  690  		return -EINVAL;
f878efc17642ce Drew Fustini  2021-02-10  691  	}
f878efc17642ce Drew Fustini  2021-02-10  692  
f878efc17642ce Drew Fustini  2021-02-10  693  	buf = kzalloc(PINMUX_MAX_NAME * 2, GFP_KERNEL);
f878efc17642ce Drew Fustini  2021-02-10  694  	if (!buf)
f878efc17642ce Drew Fustini  2021-02-10  695  		return -ENOMEM;
f878efc17642ce Drew Fustini  2021-02-10  696  
f878efc17642ce Drew Fustini  2021-02-10  697  	fname = kzalloc(PINMUX_MAX_NAME, GFP_KERNEL);
f878efc17642ce Drew Fustini  2021-02-10  698  	if (!fname) {
f878efc17642ce Drew Fustini  2021-02-10  699  		ret = -ENOMEM;
f878efc17642ce Drew Fustini  2021-02-10  700  		goto free_buf;
f878efc17642ce Drew Fustini  2021-02-10  701  	}
f878efc17642ce Drew Fustini  2021-02-10  702  
f878efc17642ce Drew Fustini  2021-02-10  703  	gname = kzalloc(PINMUX_MAX_NAME, GFP_KERNEL);
f878efc17642ce Drew Fustini  2021-02-10  704  	if (!buf) {
f878efc17642ce Drew Fustini  2021-02-10  705  		ret = -ENOMEM;
f878efc17642ce Drew Fustini  2021-02-10  706  		goto free_fname;
f878efc17642ce Drew Fustini  2021-02-10  707  	}
f878efc17642ce Drew Fustini  2021-02-10  708  
f878efc17642ce Drew Fustini  2021-02-10  709  	ret = strncpy_from_user(buf, user_buf, PINMUX_MAX_NAME * 2);
f878efc17642ce Drew Fustini  2021-02-10  710  	if (ret < 0) {
f878efc17642ce Drew Fustini  2021-02-10  711  		dev_err(pctldev->dev, "failed to copy buffer from userspace");
f878efc17642ce Drew Fustini  2021-02-10  712  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  713  	}
f878efc17642ce Drew Fustini  2021-02-10  714  	buf[len-1] = '\0';
f878efc17642ce Drew Fustini  2021-02-10  715  
f878efc17642ce Drew Fustini  2021-02-10  716  	ret = sscanf(buf, "%s %s", fname, gname);
f878efc17642ce Drew Fustini  2021-02-10  717  	if (ret != 2) {
f878efc17642ce Drew Fustini  2021-02-10  718  		dev_err(pctldev->dev, "expected format: <function-name> <group-name>");
f878efc17642ce Drew Fustini  2021-02-10  719  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  720  	}
f878efc17642ce Drew Fustini  2021-02-10  721  
f878efc17642ce Drew Fustini  2021-02-10  722  	fsel = pinmux_func_name_to_selector(pctldev, fname);
f878efc17642ce Drew Fustini  2021-02-10  723  	if (fsel < 0) {
f878efc17642ce Drew Fustini  2021-02-10  724  		dev_err(pctldev->dev, "invalid function %s in map table\n", fname);
f878efc17642ce Drew Fustini  2021-02-10  725  		ret = -EINVAL;
f878efc17642ce Drew Fustini  2021-02-10  726  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  727  	}
f878efc17642ce Drew Fustini  2021-02-10  728  
f878efc17642ce Drew Fustini  2021-02-10  729  	ret = pmxops->get_function_groups(pctldev, fsel, &groups, &num_groups);
f878efc17642ce Drew Fustini  2021-02-10  730  	if (ret) {
f878efc17642ce Drew Fustini  2021-02-10  731  		dev_err(pctldev->dev, "no groups for function %d (%s)", fsel, fname);
f878efc17642ce Drew Fustini  2021-02-10  732  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  733  
f878efc17642ce Drew Fustini  2021-02-10  734  	}
f878efc17642ce Drew Fustini  2021-02-10  735  
f878efc17642ce Drew Fustini  2021-02-10  736  	ret = match_string(groups, num_groups, gname);
f878efc17642ce Drew Fustini  2021-02-10  737  	if (ret < 0) {
f878efc17642ce Drew Fustini  2021-02-10  738  		dev_err(pctldev->dev, "invalid group %s", gname);
f878efc17642ce Drew Fustini  2021-02-10  739  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  740  	}
f878efc17642ce Drew Fustini  2021-02-10  741  
f878efc17642ce Drew Fustini  2021-02-10  742  	ret = pinctrl_get_group_selector(pctldev, gname);
f878efc17642ce Drew Fustini  2021-02-10  743  	if (ret < 0) {
f878efc17642ce Drew Fustini  2021-02-10  744  		dev_err(pctldev->dev, "failed to get group selectorL %s", gname);
f878efc17642ce Drew Fustini  2021-02-10  745  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  746  	}
f878efc17642ce Drew Fustini  2021-02-10  747  	gsel = ret;
f878efc17642ce Drew Fustini  2021-02-10  748  
f878efc17642ce Drew Fustini  2021-02-10  749  	ret = pmxops->set_mux(pctldev, fsel, gsel);
f878efc17642ce Drew Fustini  2021-02-10  750  	if (ret) {
f878efc17642ce Drew Fustini  2021-02-10  751  		dev_err(pctldev->dev, "set_mux() failed: %d", ret);
f878efc17642ce Drew Fustini  2021-02-10  752  		goto free_gname;
f878efc17642ce Drew Fustini  2021-02-10  753  	}
f878efc17642ce Drew Fustini  2021-02-10  754  
f878efc17642ce Drew Fustini  2021-02-10  755  	return len;
f878efc17642ce Drew Fustini  2021-02-10  756  
f878efc17642ce Drew Fustini  2021-02-10  757  free_gname:
f878efc17642ce Drew Fustini  2021-02-10  758  	devm_kfree(pctldev->dev, gname);
f878efc17642ce Drew Fustini  2021-02-10  759  free_fname:
f878efc17642ce Drew Fustini  2021-02-10  760  	devm_kfree(pctldev->dev, fname);
f878efc17642ce Drew Fustini  2021-02-10  761  free_buf:
f878efc17642ce Drew Fustini  2021-02-10  762  	devm_kfree(pctldev->dev, buf);
f878efc17642ce Drew Fustini  2021-02-10  763  
f878efc17642ce Drew Fustini  2021-02-10 @764  	return ret;
f878efc17642ce Drew Fustini  2021-02-10  765  }
f878efc17642ce Drew Fustini  2021-02-10  766  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37886 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-02-17  8:20 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 22:28 [PATCH v4 0/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
2021-02-10 22:28 ` [PATCH v4 1/2] pinctrl: use to octal permissions for debugfs files Drew Fustini
2021-02-11  7:36   ` Joe Perches
2021-02-11  7:52     ` Drew Fustini
2021-02-10 22:28 ` [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
2021-02-11  7:11   ` Dan Carpenter
2021-02-11  7:24     ` Joe Perches
2021-02-11  7:39       ` Dan Carpenter
2021-02-12  3:35         ` Drew Fustini
2021-02-17  8:18           ` Dan Carpenter
2021-02-11  8:09   ` Geert Uytterhoeven
2021-02-11  9:53     ` Andy Shevchenko
2021-02-12  3:39       ` Drew Fustini
2021-02-12  3:37     ` Drew Fustini
2021-02-11 12:00   ` Dan Carpenter
2021-02-12  3:41     ` Drew Fustini
2021-02-11  4:32 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.