public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Mark Pearson <mpearson-lenovo@squebb.ca>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Mark Pearson <markpearson@lenovo.com>,
	Mark Gross <markgross@kernel.org>
Subject: Re: [PATCH v1 2/2] platform/x86: think-lmi: Use strreplace() to replace a character by nul
Date: Fri, 15 Sep 2023 17:57:59 +0300 (EEST)	[thread overview]
Message-ID: <227454d0-e33a-179c-b4df-1f486136ca6@linux.intel.com> (raw)
In-Reply-To: <20230913092701.440959-2-andriy.shevchenko@linux.intel.com>

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

On Wed, 13 Sep 2023, Andy Shevchenko wrote:

> We can replace
> 	p = strchrnul(str, '$OLD');
> 	*p = '\0';
> with
> 	strreplace(str, '$OLD', '\0');
> that does the compatible modification without a need of the temporary variable.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/platform/x86/think-lmi.c | 19 ++++---------------
>  1 file changed, 4 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index 94a3c7a74bc4..2f20fafe7f55 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -198,14 +198,6 @@ static struct think_lmi tlmi_priv;
>  static struct class *fw_attr_class;
>  static DEFINE_MUTEX(tlmi_mutex);
>  
> -/* ------ Utility functions ------------*/
> -/* Strip out CR if one is present */
> -static void strip_cr(char *str)
> -{
> -	char *p = strchrnul(str, '\n');
> -	*p = '\0';
> -}
> -
>  /* Convert BIOS WMI error string to suitable error code */
>  static int tlmi_errstr_to_err(const char *errstr)
>  {
> @@ -411,7 +403,7 @@ static ssize_t current_password_store(struct kobject *kobj,
>  
>  	strscpy(setting->password, buf, setting->maxlen);
>  	/* Strip out CR if one is present, setting password won't work if it is present */
> -	strip_cr(setting->password);
> +	strreplace(setting->password, '\n', '\0');
>  	return count;
>  }
>  
> @@ -921,7 +913,7 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
>  static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>  {
>  	struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> -	char *item, *value, *p;
> +	char *item, *value;
>  	int ret;
>  
>  	ret = tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID);
> @@ -934,8 +926,7 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a
>  		ret = -EINVAL;
>  	else {
>  		/* On Workstations remove the Options part after the value */
> -		p = strchrnul(value, ';');
> -		*p = '\0';
> +		strreplace(value, ';', '\0');
>  		ret = sysfs_emit(buf, "%s\n", value + 1);
>  	}
>  	kfree(item);
> @@ -1418,7 +1409,6 @@ static int tlmi_analyze(void)
>  	for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
>  		struct tlmi_attr_setting *setting;
>  		char *item = NULL;
> -		char *p;
>  
>  		tlmi_priv.setting[i] = NULL;
>  		ret = tlmi_setting(i, &item, LENOVO_BIOS_SETTING_GUID);
> @@ -1435,8 +1425,7 @@ static int tlmi_analyze(void)
>  		strreplace(item, '/', '\\');
>  
>  		/* Remove the value part */
> -		p = strchrnul(item, ',');
> -		*p = '\0';
> +		strreplace(item, ',', '\0');
>  
>  		/* Create a setting entry */
>  		setting = kzalloc(sizeof(*setting), GFP_KERNEL);
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

  parent reply	other threads:[~2023-09-15 14:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  9:27 [PATCH v1 1/2] platform/x86: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace() Andy Shevchenko
2023-09-13  9:27 ` [PATCH v1 2/2] platform/x86: think-lmi: Use strreplace() to replace a character by nul Andy Shevchenko
2023-09-13 13:17   ` Mark Pearson
2023-09-15 14:57   ` Ilpo Järvinen [this message]
2023-09-18 14:48   ` Rasmus Villemoes
2023-09-18 15:38     ` Andy Shevchenko
2023-09-13 13:15 ` [PATCH v1 1/2] platform/x86: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace() Mark Pearson
2023-09-15 14:57 ` Ilpo Järvinen
2023-09-18 12:30 ` Hans de Goede
2023-09-18 13:50   ` Andy Shevchenko

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=227454d0-e33a-179c-b4df-1f486136ca6@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=markpearson@lenovo.com \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=platform-driver-x86@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox