From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752721AbcBPFG1 (ORCPT ); Tue, 16 Feb 2016 00:06:27 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:36002 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751009AbcBPFGR (ORCPT ); Tue, 16 Feb 2016 00:06:17 -0500 From: Sanchayan Maity To: linux@roeck-us.net, shawnguo@kernel.org Cc: jdelvare@suse.com, stefan@agner.ch, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org, Sanchayan Maity Subject: [PATCH v3 1/3] hwmon: iio_hwmon: Allow the driver to accept hypen in device tree node names Date: Tue, 16 Feb 2016 10:30:53 +0530 Message-Id: X-Mailer: git-send-email 2.7.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the driver calls hwmon_device_register_with_groups which does not accept hypen in node name and returns EINVAL. Use of hypen in device tree node name results in probe failure., however use of hypen in device tree node name is perfectly acceptable. Change this by allocating a duplicate managed string, replacing hypen with underscore and then calling hwmon_device_register_with_groups. This allows the use of hypen in device tree node name while maintaining backwards compatibility and preventing any possible regressions with user space. Signed-off-by: Sanchayan Maity --- drivers/hwmon/iio_hwmon.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c index 17ae2eb..b550ba5 100644 --- a/drivers/hwmon/iio_hwmon.c +++ b/drivers/hwmon/iio_hwmon.c @@ -67,6 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) enum iio_chan_type type; struct iio_channel *channels; const char *name = "iio_hwmon"; + char *sname; if (dev->of_node && dev->of_node->name) name = dev->of_node->name; @@ -144,7 +145,15 @@ static int iio_hwmon_probe(struct platform_device *pdev) st->attr_group.attrs = st->attrs; st->groups[0] = &st->attr_group; - st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st, + + sname = devm_kstrdup(dev, name, GFP_KERNEL); + if (!sname) { + ret = -ENOMEM; + goto error_release_channels; + } + + strreplace(sname, '-', '_'); + st->hwmon_dev = hwmon_device_register_with_groups(dev, sname, st, st->groups); if (IS_ERR(st->hwmon_dev)) { ret = PTR_ERR(st->hwmon_dev); -- 2.7.1