lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 15 Oct 2021 14:48:16 +0100
From:   Jonathan Cameron <Jonathan.Cameron@...wei.com>
To:     Qing Wang <wangqing@...o.com>
CC:     Jiri Kosina <jikos@...nel.org>,
        Benjamin Tissoires <benjamin.tissoires@...hat.com>,
        Bruno Prémont <bonbons@...ux-vserver.org>,
        Stefan Achatz <erazor_de@...rs.sourceforge.net>,
        Jonathan Cameron <jic23@...nel.org>,
        Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
        <linux-input@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <linux-iio@...r.kernel.org>
Subject: Re: [PATCH V2 4/5] hid-sensor: replace snprintf in show functions
 with sysfs_emit

On Fri, 15 Oct 2021 04:07:31 -0700
Qing Wang <wangqing@...o.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@...o.com>
> ---
>  drivers/hid/hid-sensor-custom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
> index 32c2306..a46481d6 100644
> --- a/drivers/hid/hid-sensor-custom.c
> +++ b/drivers/hid/hid-sensor-custom.c
> @@ -371,7 +371,7 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr,
>  				     sizeof(struct hid_custom_usage_desc),
>  				     usage_id_cmp);
>  		if (usage_desc)
> -			return snprintf(buf, PAGE_SIZE, "%s\n",
> +			return sysfs_emit(buf, "%s\n",
>  					usage_desc->desc);

Now easily short enough that this can go on one line.

>  		else
>  			return sprintf(buf, "not-specified\n");
Whilst of course not necessary, it might be nicer to use sysfs_emit here as well for
consistency.

Otherwise looks good to me.

Jonathan

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ