All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] hwmon: Add "label" attribute v2
@ 2022-01-05 15:15 Paul Cercueil
  2022-01-05 15:15 ` [PATCH v2 1/2] ABI: hwmon: Document "label" sysfs attribute Paul Cercueil
  2022-01-05 15:15 ` [PATCH v2 2/2] hwmon: Add "label" attribute Paul Cercueil
  0 siblings, 2 replies; 10+ messages in thread
From: Paul Cercueil @ 2022-01-05 15:15 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Jonathan Corbet
  Cc: linux-hwmon, linux-kernel, linux-doc, list, Paul Cercueil

Hi Jean, Guenter,

A V2 of my patchset which allows specifying a hwmon device's label from
Device Tree. When the "label" device property is present, its value is
exported to the userspace via the "label" sysfs attribute.

This is useful for userspace to be able to identify an individual device
when multiple individual chips are present in the system.

Note that this mechanism already exists in IIO.

Patch [1/2] documents the ABI change.
Patch [2/2] adds the change to the core drivers/hwmon/hwmon.c file.

Changes from v1:
- The label is cached into the hwmon_device structure
- hwmon_dev_name_is_visible() renamed to hwmon_dev_attr_is_visible()
- Add missing <linux/property.h> include
- The DT binding documentation of the "label" property has been dropped,
  and the "label" property is now supported directly in dtschema.

Cheers,
-Paul


Paul Cercueil (2):
  ABI: hwmon: Document "label" sysfs attribute
  hwmon: Add "label" attribute

 Documentation/ABI/testing/sysfs-class-hwmon |  8 +++++
 Documentation/hwmon/sysfs-interface.rst     |  4 +++
 drivers/hwmon/hwmon.c                       | 34 +++++++++++++++++++--
 3 files changed, 43 insertions(+), 3 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] hwmon: Add "label" attribute
  2022-01-05 15:15 ` [PATCH v2 2/2] hwmon: Add "label" attribute Paul Cercueil
  2022-01-05 22:27     ` kernel test robot
@ 2022-01-10  6:44 ` Dan Carpenter
  1 sibling, 0 replies; 10+ messages in thread
From: kernel test robot @ 2022-01-08  9:11 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220105151551.20285-3-paul@crapouillou.net>
References: <20220105151551.20285-3-paul@crapouillou.net>
TO: Paul Cercueil <paul@crapouillou.net>
TO: Jean Delvare <jdelvare@suse.com>
TO: Guenter Roeck <linux@roeck-us.net>
TO: Jonathan Corbet <corbet@lwn.net>
CC: linux-hwmon(a)vger.kernel.org
CC: linux-kernel(a)vger.kernel.org
CC: linux-doc(a)vger.kernel.org
CC: list(a)opendingux.net
CC: Paul Cercueil <paul@crapouillou.net>
CC: Cosmin Tanislav <cosmin.tanislav@analog.com>

Hi Paul,

I love your patch! Perhaps something to improve:

[auto build test WARNING on groeck-staging/hwmon-next]
[also build test WARNING on v5.16-rc8 next-20220107]
[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/Paul-Cercueil/hwmon-Add-label-attribute-v2/20220105-231930
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: i386-randconfig-m021-20220105 (https://download.01.org/0day-ci/archive/20220108/202201081730.TlHZabuC-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 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/hwmon/hwmon.c:851 __hwmon_device_register() error: uninitialized symbol 'hdev'.
drivers/hwmon/hwmon.c:854 __hwmon_device_register() warn: possible memory leak of 'hwdev'

vim +/hdev +851 drivers/hwmon/hwmon.c

d560168b5d0fb4 Guenter Roeck    2015-08-26  744  
d560168b5d0fb4 Guenter Roeck    2015-08-26  745  static struct device *
d560168b5d0fb4 Guenter Roeck    2015-08-26  746  __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
d560168b5d0fb4 Guenter Roeck    2015-08-26  747  			const struct hwmon_chip_info *chip,
bab2243ce18978 Guenter Roeck    2013-07-06  748  			const struct attribute_group **groups)
1236441f38b6a9 Mark M. Hoffman  2005-07-15  749  {
bab2243ce18978 Guenter Roeck    2013-07-06  750  	struct hwmon_device *hwdev;
57dab49995d01d Paul Cercueil    2022-01-05  751  	const char *label;
d560168b5d0fb4 Guenter Roeck    2015-08-26  752  	struct device *hdev;
44e3ad882bb268 Akinobu Mita     2020-05-04  753  	int i, err, id;
ded2b666156130 Mark M. Hoffman  2006-03-05  754  
74d3b6419772e4 Guenter Roeck    2017-01-27  755  	/* Complain about invalid characters in hwmon name attribute */
648cd48c9e566f Guenter Roeck    2014-02-28  756  	if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
74d3b6419772e4 Guenter Roeck    2017-01-27  757  		dev_warn(dev,
74d3b6419772e4 Guenter Roeck    2017-01-27  758  			 "hwmon: '%s' is not a valid name attribute, please fix\n",
74d3b6419772e4 Guenter Roeck    2017-01-27  759  			 name);
648cd48c9e566f Guenter Roeck    2014-02-28  760  
4ca5f468cc2a0b Jonathan Cameron 2011-10-31  761  	id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
4ca5f468cc2a0b Jonathan Cameron 2011-10-31  762  	if (id < 0)
4ca5f468cc2a0b Jonathan Cameron 2011-10-31  763  		return ERR_PTR(id);
1236441f38b6a9 Mark M. Hoffman  2005-07-15  764  
bab2243ce18978 Guenter Roeck    2013-07-06  765  	hwdev = kzalloc(sizeof(*hwdev), GFP_KERNEL);
bab2243ce18978 Guenter Roeck    2013-07-06  766  	if (hwdev == NULL) {
bab2243ce18978 Guenter Roeck    2013-07-06  767  		err = -ENOMEM;
bab2243ce18978 Guenter Roeck    2013-07-06  768  		goto ida_remove;
bab2243ce18978 Guenter Roeck    2013-07-06  769  	}
1236441f38b6a9 Mark M. Hoffman  2005-07-15  770  
57dab49995d01d Paul Cercueil    2022-01-05  771  	if (device_property_present(dev, "label")) {
57dab49995d01d Paul Cercueil    2022-01-05  772  		err = device_property_read_string(dev, "label", &label);
57dab49995d01d Paul Cercueil    2022-01-05  773  		if (err < 0)
57dab49995d01d Paul Cercueil    2022-01-05  774  			goto free_hwmon;
57dab49995d01d Paul Cercueil    2022-01-05  775  
57dab49995d01d Paul Cercueil    2022-01-05  776  		hwdev->label = kstrdup(label, GFP_KERNEL);
57dab49995d01d Paul Cercueil    2022-01-05  777  		if (hwdev->label == NULL) {
57dab49995d01d Paul Cercueil    2022-01-05  778  			err = -ENOMEM;
57dab49995d01d Paul Cercueil    2022-01-05  779  			goto free_hwmon;
57dab49995d01d Paul Cercueil    2022-01-05  780  		}
57dab49995d01d Paul Cercueil    2022-01-05  781  	}
57dab49995d01d Paul Cercueil    2022-01-05  782  
d560168b5d0fb4 Guenter Roeck    2015-08-26  783  	hdev = &hwdev->dev;
d560168b5d0fb4 Guenter Roeck    2015-08-26  784  
239552f495b91f Guenter Roeck    2016-10-16  785  	if (chip) {
d560168b5d0fb4 Guenter Roeck    2015-08-26  786  		struct attribute **attrs;
b2a4cc3a060da0 Guenter Roeck    2016-10-16  787  		int ngroups = 2; /* terminating NULL plus &hwdev->groups */
d560168b5d0fb4 Guenter Roeck    2015-08-26  788  
d560168b5d0fb4 Guenter Roeck    2015-08-26  789  		if (groups)
d560168b5d0fb4 Guenter Roeck    2015-08-26  790  			for (i = 0; groups[i]; i++)
d560168b5d0fb4 Guenter Roeck    2015-08-26  791  				ngroups++;
d560168b5d0fb4 Guenter Roeck    2015-08-26  792  
3bf8bdcf3bada7 Guenter Roeck    2020-01-16  793  		hwdev->groups = kcalloc(ngroups, sizeof(*groups), GFP_KERNEL);
38d8ed65092ed2 Colin Ian King   2016-10-23  794  		if (!hwdev->groups) {
38d8ed65092ed2 Colin Ian King   2016-10-23  795  			err = -ENOMEM;
38d8ed65092ed2 Colin Ian King   2016-10-23  796  			goto free_hwmon;
38d8ed65092ed2 Colin Ian King   2016-10-23  797  		}
d560168b5d0fb4 Guenter Roeck    2015-08-26  798  
3bf8bdcf3bada7 Guenter Roeck    2020-01-16  799  		attrs = __hwmon_create_attrs(drvdata, chip);
d560168b5d0fb4 Guenter Roeck    2015-08-26  800  		if (IS_ERR(attrs)) {
d560168b5d0fb4 Guenter Roeck    2015-08-26  801  			err = PTR_ERR(attrs);
d560168b5d0fb4 Guenter Roeck    2015-08-26  802  			goto free_hwmon;
d560168b5d0fb4 Guenter Roeck    2015-08-26  803  		}
d560168b5d0fb4 Guenter Roeck    2015-08-26  804  
d560168b5d0fb4 Guenter Roeck    2015-08-26  805  		hwdev->group.attrs = attrs;
d560168b5d0fb4 Guenter Roeck    2015-08-26  806  		ngroups = 0;
d560168b5d0fb4 Guenter Roeck    2015-08-26  807  		hwdev->groups[ngroups++] = &hwdev->group;
d560168b5d0fb4 Guenter Roeck    2015-08-26  808  
d560168b5d0fb4 Guenter Roeck    2015-08-26  809  		if (groups) {
d560168b5d0fb4 Guenter Roeck    2015-08-26  810  			for (i = 0; groups[i]; i++)
d560168b5d0fb4 Guenter Roeck    2015-08-26  811  				hwdev->groups[ngroups++] = groups[i];
d560168b5d0fb4 Guenter Roeck    2015-08-26  812  		}
d560168b5d0fb4 Guenter Roeck    2015-08-26  813  
d560168b5d0fb4 Guenter Roeck    2015-08-26  814  		hdev->groups = hwdev->groups;
d560168b5d0fb4 Guenter Roeck    2015-08-26  815  	} else {
d560168b5d0fb4 Guenter Roeck    2015-08-26  816  		hdev->groups = groups;
d560168b5d0fb4 Guenter Roeck    2015-08-26  817  	}
d560168b5d0fb4 Guenter Roeck    2015-08-26  818  
bab2243ce18978 Guenter Roeck    2013-07-06  819  	hwdev->name = name;
d560168b5d0fb4 Guenter Roeck    2015-08-26  820  	hdev->class = &hwmon_class;
d560168b5d0fb4 Guenter Roeck    2015-08-26  821  	hdev->parent = dev;
d560168b5d0fb4 Guenter Roeck    2015-08-26  822  	hdev->of_node = dev ? dev->of_node : NULL;
d560168b5d0fb4 Guenter Roeck    2015-08-26  823  	hwdev->chip = chip;
d560168b5d0fb4 Guenter Roeck    2015-08-26  824  	dev_set_drvdata(hdev, drvdata);
d560168b5d0fb4 Guenter Roeck    2015-08-26  825  	dev_set_name(hdev, HWMON_ID_FORMAT, id);
d560168b5d0fb4 Guenter Roeck    2015-08-26  826  	err = device_register(hdev);
ada61aa0b1184a Yang Yingliang   2021-10-12  827  	if (err) {
ada61aa0b1184a Yang Yingliang   2021-10-12  828  		put_device(hdev);
ada61aa0b1184a Yang Yingliang   2021-10-12  829  		goto ida_remove;
ada61aa0b1184a Yang Yingliang   2021-10-12  830  	}
d560168b5d0fb4 Guenter Roeck    2015-08-26  831  
1597b374af2226 Guenter Roeck    2020-05-28  832  	INIT_LIST_HEAD(&hwdev->tzdata);
1597b374af2226 Guenter Roeck    2020-05-28  833  
c41dd48e21fae3 Eduardo Valentin 2019-05-29  834  	if (dev && dev->of_node && chip && chip->ops->read &&
d560168b5d0fb4 Guenter Roeck    2015-08-26  835  	    chip->info[0]->type == hwmon_chip &&
d560168b5d0fb4 Guenter Roeck    2015-08-26  836  	    (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
44e3ad882bb268 Akinobu Mita     2020-05-04  837  		err = hwmon_thermal_register_sensors(hdev);
74e3512731bd5c Dmitry Osipenko  2018-10-24  838  		if (err) {
74e3512731bd5c Dmitry Osipenko  2018-10-24  839  			device_unregister(hdev);
792eac18431967 Guenter Roeck    2019-06-06  840  			/*
44e3ad882bb268 Akinobu Mita     2020-05-04  841  			 * Don't worry about hwdev; hwmon_dev_release(), called
44e3ad882bb268 Akinobu Mita     2020-05-04  842  			 * from device_unregister(), will free it.
792eac18431967 Guenter Roeck    2019-06-06  843  			 */
74e3512731bd5c Dmitry Osipenko  2018-10-24  844  			goto ida_remove;
74e3512731bd5c Dmitry Osipenko  2018-10-24  845  		}
47c332deb8e89f Linus Walleij    2017-12-05  846  	}
bab2243ce18978 Guenter Roeck    2013-07-06  847  
d560168b5d0fb4 Guenter Roeck    2015-08-26  848  	return hdev;
bab2243ce18978 Guenter Roeck    2013-07-06  849  
d560168b5d0fb4 Guenter Roeck    2015-08-26  850  free_hwmon:
3bf8bdcf3bada7 Guenter Roeck    2020-01-16 @851  	hwmon_dev_release(hdev);
bab2243ce18978 Guenter Roeck    2013-07-06  852  ida_remove:
4ca5f468cc2a0b Jonathan Cameron 2011-10-31  853  	ida_simple_remove(&hwmon_ida, id);
bab2243ce18978 Guenter Roeck    2013-07-06 @854  	return ERR_PTR(err);
bab2243ce18978 Guenter Roeck    2013-07-06  855  }
d560168b5d0fb4 Guenter Roeck    2015-08-26  856  

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

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

end of thread, other threads:[~2022-01-10 10:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-05 15:15 [PATCH v2 0/2] hwmon: Add "label" attribute v2 Paul Cercueil
2022-01-05 15:15 ` [PATCH v2 1/2] ABI: hwmon: Document "label" sysfs attribute Paul Cercueil
2022-01-05 15:15 ` [PATCH v2 2/2] hwmon: Add "label" attribute Paul Cercueil
2022-01-05 22:27   ` kernel test robot
2022-01-05 22:27     ` kernel test robot
2022-01-10  1:29   ` Guenter Roeck
2022-01-10 10:48     ` Paul Cercueil
  -- strict thread matches above, loose matches on Subject: below --
2022-01-08  9:11 kernel test robot
2022-01-10  6:44 ` Dan Carpenter
2022-01-10  6:44 ` Dan Carpenter

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.