All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rix <trix@redhat.com>
To: Michael Walle <michael@walle.cc>, Xu Yilun <yilun.xu@intel.com>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH v1 1/2] hwmon: introduce hwmon_sanitize_name()
Date: Mon, 28 Mar 2022 05:25:30 -0700	[thread overview]
Message-ID: <a1f71681-0eb0-c67f-53e0-dfce9d2fdea9@redhat.com> (raw)
In-Reply-To: <20220328115226.3042322-2-michael@walle.cc>


On 3/28/22 4:52 AM, Michael Walle wrote:
> More and more drivers will check for bad characters in the hwmon name
> and all are using the same code snippet. Consolidate that code by adding
> a new hwmon_sanitize_name() function.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>   drivers/hwmon/intel-m10-bmc-hwmon.c |  5 +----
>   include/linux/hwmon.h               | 16 ++++++++++++++++
>   2 files changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/intel-m10-bmc-hwmon.c b/drivers/hwmon/intel-m10-bmc-hwmon.c
> index 7a08e4c44a4b..e6e55fc30153 100644
> --- a/drivers/hwmon/intel-m10-bmc-hwmon.c
> +++ b/drivers/hwmon/intel-m10-bmc-hwmon.c
> @@ -515,7 +515,6 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev)
>   	struct intel_m10bmc *m10bmc = dev_get_drvdata(pdev->dev.parent);
>   	struct device *hwmon_dev, *dev = &pdev->dev;
>   	struct m10bmc_hwmon *hw;
> -	int i;
>   
>   	hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
>   	if (!hw)
> @@ -532,9 +531,7 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev)
>   	if (!hw->hw_name)
>   		return -ENOMEM;
>   
> -	for (i = 0; hw->hw_name[i]; i++)
> -		if (hwmon_is_bad_char(hw->hw_name[i]))
> -			hw->hw_name[i] = '_';
> +	hwmon_sanitize_name(hw->hw_name);
>   
>   	hwmon_dev = devm_hwmon_device_register_with_info(dev, hw->hw_name,
>   							 hw, &hw->chip, NULL);
> diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
> index eba380b76d15..210b8c0b2827 100644
> --- a/include/linux/hwmon.h
> +++ b/include/linux/hwmon.h
> @@ -484,4 +484,20 @@ static inline bool hwmon_is_bad_char(const char ch)
>   	}
>   }

hwmon_is_bad_char is now only used by hwmon_sanitize_name.

as patch 3, consolidate into only hwmon_sanitize_name.

Tom

>   
> +/**
> + * hwmon_sanitize_name - Replaces invalid characters in a hwmon name
> + * @name: NUL-terminated name
> + *
> + * Invalid characters in the name will be overwritten in-place by an
> + * underscore.
> + */
> +static inline void hwmon_sanitize_name(char *name)
> +{
> +	while (*name) {
> +		if (hwmon_is_bad_char(*name))
> +			*name = '_';
> +		name++;
> +	};
> +}
> +
>   #endif


  reply	other threads:[~2022-03-28 12:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28 11:52 [PATCH v1 0/2] hwmon: introduce hwmon_sanitize() Michael Walle
2022-03-28 11:52 ` [PATCH v1 1/2] hwmon: introduce hwmon_sanitize_name() Michael Walle
2022-03-28 12:25   ` Tom Rix [this message]
2022-03-28 16:42     ` Guenter Roeck
2022-03-28 16:29   ` Guenter Roeck
2022-03-28 11:52 ` [PATCH v1 2/2] net: phy: use hwmon_sanitize_name() Michael Walle
2022-03-28 22:46   ` Michael Walle
2022-03-28 12:56 ` [PATCH v1 0/2] hwmon: introduce hwmon_sanitize() Andrew Lunn
2022-03-28 16:27   ` Guenter Roeck
2022-03-28 22:50     ` Michael Walle
2022-03-28 23:00       ` Jakub Kicinski
2022-03-29 13:52       ` Guenter Roeck

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=a1f71681-0eb0-c67f-53e0-dfce9d2fdea9@redhat.com \
    --to=trix@redhat.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=kuba@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@roeck-us.net \
    --cc=michael@walle.cc \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yilun.xu@intel.com \
    /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 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.