linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Qing Wang <wangqing@vivo.com>
Cc: "Jiri Kosina" <jikos@kernel.org>,
	"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
	"Bruno Prémont" <bonbons@linux-vserver.org>,
	"Stefan Achatz" <erazor_de@users.sourceforge.net>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH V2 1/5] hid-lenovo: replace snprintf in show functions with sysfs_emit
Date: Fri, 15 Oct 2021 14:51:50 +0100	[thread overview]
Message-ID: <20211015145150.0000006e@Huawei.com> (raw)
In-Reply-To: <1634296054-6971-2-git-send-email-wangqing@vivo.com>

On Fri, 15 Oct 2021 04:07:28 -0700
Qing Wang <wangqing@vivo.com> wrote:

> show() should not use snprintf() when formatting the value to be returned 
> to user space, snprintf() returns the length the resulting string and 
> scnprintf() returns the number of bytes printed into the buffer.
> 
> Fix the coccicheck warnings:
> WARNING: use scnprintf or sprintf.
> 
> Use sysfs_emit() instead of scnprintf() makes more sense.
> 
> Signed-off-by: Qing Wang <wangqing@vivo.com>

Hi,

A few places where it makes sense to tidy up the line breaks.

The benefit of the change in general is fairly minor given none
of the cases here can cause problems, but I guess it is worthwhile
as warning suppression and general tidiness improvement.

Jonathan

> ---
>  drivers/hid/hid-lenovo.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
> index 93b1f93..086a7ae 100644
> --- a/drivers/hid/hid-lenovo.c
> +++ b/drivers/hid/hid-lenovo.c
> @@ -400,7 +400,7 @@ static ssize_t attr_fn_lock_show(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data->fn_lock);
> +	return sysfs_emit(buf, "%u\n", data->fn_lock);
>  }
>  
>  static ssize_t attr_fn_lock_store(struct device *dev,
> @@ -442,7 +442,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  		cptkbd_data->sensitivity);

As below, whilst here tidy this up to be one line.

>  }
>  
> @@ -603,7 +603,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
> +	return sysfs_emit(buf, "%u\n", data_pointer->press_to_select);
>  }
>  
>  static ssize_t attr_press_to_select_store_tpkbd(struct device *dev,
> @@ -633,7 +633,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
> +	return sysfs_emit(buf, "%u\n", data_pointer->dragging);
>  }
>  
>  static ssize_t attr_dragging_store_tpkbd(struct device *dev,
> @@ -663,7 +663,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
> +	return sysfs_emit(buf, "%u\n", data_pointer->release_to_select);
>  }
>  
>  static ssize_t attr_release_to_select_store_tpkbd(struct device *dev,
> @@ -693,7 +693,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
> +	return sysfs_emit(buf, "%u\n", data_pointer->select_right);
>  }
>  
>  static ssize_t attr_select_right_store_tpkbd(struct device *dev,
> @@ -723,7 +723,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  		data_pointer->sensitivity);
Perhaps put this on one line?  It fit before the change of course, but
as you are touching the code, might as well tidy that up.

>  }
>  
> @@ -752,7 +752,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  		data_pointer->press_speed);
Same here.

Thanks,

Jonathan

>  }
>  


  reply	other threads:[~2021-10-15 13:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-15 11:07 ` [PATCH V2 1/5] hid-lenovo: " Qing Wang
2021-10-15 13:51   ` Jonathan Cameron [this message]
2021-10-15 11:07 ` [PATCH V2 2/5] hid-picolcd: " Qing Wang
2021-10-15 11:07 ` [PATCH V2 3/5] hid-roccat: " Qing Wang
2021-10-15 11:07 ` [PATCH V2 4/5] hid-sensor: " Qing Wang
2021-10-15 13:48   ` Jonathan Cameron
2021-10-15 11:07 ` [PATCH V2 5/5] hid-sony: " Qing Wang

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=20211015145150.0000006e@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=bonbons@linux-vserver.org \
    --cc=erazor_de@users.sourceforge.net \
    --cc=jic23@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=wangqing@vivo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).