All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Efremov <efremov@linux.com>
To: Joe Perches <joe@perches.com>, Julia Lawall <julia.lawall@inria.fr>
Cc: Kees Cook <keescook@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-kernel@vger.kernel.org, Alex Dewar <alex.dewar90@gmail.com>,
	accessrunner-general@lists.sourceforge.net,
	cocci <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs
Date: Fri, 28 Aug 2020 01:38:55 +0300	[thread overview]
Message-ID: <adfca3f2-561a-9d91-c064-cf01c2b573e7@linux.com> (raw)
In-Reply-To: <d6d5836196208d5280cedf5837952096c3518852.camel@perches.com>

> 
> I tried:
> @@
> identifier f_show =~ "^.*_show$";


This will miss this kind of functions:
./drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c:1953:static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version,
./drivers/gpu/drm/amd/amdgpu/df_v3_6.c:266:static DEVICE_ATTR(df_cntr_avail, S_IRUGO, df_v3_6_get_df_cntr_avail, NULL);
./drivers/input/touchscreen/melfas_mip4.c:1348:static DEVICE_ATTR(fw_version, S_IRUGO, mip4_sysfs_read_fw_version, NULL);
./drivers/input/touchscreen/melfas_mip4.c:1373:static DEVICE_ATTR(hw_version, S_IRUGO, mip4_sysfs_read_hw_version, NULL);
./drivers/input/touchscreen/melfas_mip4.c:1392:static DEVICE_ATTR(product_id, S_IRUGO, mip4_sysfs_read_product_id, NULL);
...

> identifier dev, attr, buf;
> const char *chr;
> @@
> ssize_t f_show(struct device *dev, struct device_attribute *attr, char
> *buf)
> {
> 	<...
> (
> -	sprintf
> +	sysfs_sprintf
> 	(...);
> |
> -	snprintf(buf, PAGE_SIZE,
> +	sysfs_sprintf(buf,
> 	...);
> |
> -	scnprintf(buf, PAGE_SIZE,
> +	sysfs_sprintf(buf,
> 	...);
> |
> 	strcpy(buf, chr);
> 	sysfs_strcpy(buf, chr);
> )
> 	...>
> }
> 
> which finds direct statements without an assign
> but that doesn't find
> 
> arch/arm/common/dmabounce.c:static ssize_t dmabounce_show(struct device *dev, struct device_attribute *attr, char *buf)
> arch/arm/common/dmabounce.c-{
> arch/arm/common/dmabounce.c-    struct dmabounce_device_info *device_info = dev->archdata.dmabounce;
> arch/arm/common/dmabounce.c-    return sprintf(buf, "%lu %lu %lu %lu %lu %lu\n",
> arch/arm/common/dmabounce.c-            device_info->small.allocs,
> arch/arm/common/dmabounce.c-            device_info->large.allocs,
> arch/arm/common/dmabounce.c-            device_info->total_allocs - device_info->small.allocs -
> arch/arm/common/dmabounce.c-                    device_info->large.allocs,
> arch/arm/common/dmabounce.c-            device_info->total_allocs,
> arch/arm/common/dmabounce.c-            device_info->map_op_count,
> arch/arm/common/dmabounce.c-            device_info->bounce_count);
> arch/arm/common/dmabounce.c-}
>

This will match it (the difference is in the ';'):
@@
identifier f_show =~ "^.*_show$";
identifier dev, attr, buf;
@@

ssize_t f_show(struct device *dev, struct device_attribute *attr, char *buf)

{

	<...
-	sprintf
+	sysfs_sprintf
	(...)
	...>
}

Regards,
Denis
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

WARNING: multiple messages have this Message-ID (diff)
From: Denis Efremov <efremov@linux.com>
To: Joe Perches <joe@perches.com>, Julia Lawall <julia.lawall@inria.fr>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-kernel@vger.kernel.org, cocci <cocci@systeme.lip6.fr>,
	accessrunner-general@lists.sourceforge.net,
	Alex Dewar <alex.dewar90@gmail.com>
Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs
Date: Fri, 28 Aug 2020 01:38:55 +0300	[thread overview]
Message-ID: <adfca3f2-561a-9d91-c064-cf01c2b573e7@linux.com> (raw)
In-Reply-To: <d6d5836196208d5280cedf5837952096c3518852.camel@perches.com>

> 
> I tried:
> @@
> identifier f_show =~ "^.*_show$";


This will miss this kind of functions:
./drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c:1953:static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version,
./drivers/gpu/drm/amd/amdgpu/df_v3_6.c:266:static DEVICE_ATTR(df_cntr_avail, S_IRUGO, df_v3_6_get_df_cntr_avail, NULL);
./drivers/input/touchscreen/melfas_mip4.c:1348:static DEVICE_ATTR(fw_version, S_IRUGO, mip4_sysfs_read_fw_version, NULL);
./drivers/input/touchscreen/melfas_mip4.c:1373:static DEVICE_ATTR(hw_version, S_IRUGO, mip4_sysfs_read_hw_version, NULL);
./drivers/input/touchscreen/melfas_mip4.c:1392:static DEVICE_ATTR(product_id, S_IRUGO, mip4_sysfs_read_product_id, NULL);
...

> identifier dev, attr, buf;
> const char *chr;
> @@
> ssize_t f_show(struct device *dev, struct device_attribute *attr, char
> *buf)
> {
> 	<...
> (
> -	sprintf
> +	sysfs_sprintf
> 	(...);
> |
> -	snprintf(buf, PAGE_SIZE,
> +	sysfs_sprintf(buf,
> 	...);
> |
> -	scnprintf(buf, PAGE_SIZE,
> +	sysfs_sprintf(buf,
> 	...);
> |
> 	strcpy(buf, chr);
> 	sysfs_strcpy(buf, chr);
> )
> 	...>
> }
> 
> which finds direct statements without an assign
> but that doesn't find
> 
> arch/arm/common/dmabounce.c:static ssize_t dmabounce_show(struct device *dev, struct device_attribute *attr, char *buf)
> arch/arm/common/dmabounce.c-{
> arch/arm/common/dmabounce.c-    struct dmabounce_device_info *device_info = dev->archdata.dmabounce;
> arch/arm/common/dmabounce.c-    return sprintf(buf, "%lu %lu %lu %lu %lu %lu\n",
> arch/arm/common/dmabounce.c-            device_info->small.allocs,
> arch/arm/common/dmabounce.c-            device_info->large.allocs,
> arch/arm/common/dmabounce.c-            device_info->total_allocs - device_info->small.allocs -
> arch/arm/common/dmabounce.c-                    device_info->large.allocs,
> arch/arm/common/dmabounce.c-            device_info->total_allocs,
> arch/arm/common/dmabounce.c-            device_info->map_op_count,
> arch/arm/common/dmabounce.c-            device_info->bounce_count);
> arch/arm/common/dmabounce.c-}
>

This will match it (the difference is in the ';'):
@@
identifier f_show =~ "^.*_show$";
identifier dev, attr, buf;
@@

ssize_t f_show(struct device *dev, struct device_attribute *attr, char *buf)

{

	<...
-	sprintf
+	sysfs_sprintf
	(...)
	...>
}

Regards,
Denis

  reply	other threads:[~2020-08-27 22:39 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 22:23 [PATCH] usb: atm: don't use snprintf() for sysfs attrs Alex Dewar
2020-08-25  8:12 ` David Laight
2020-08-25  8:17   ` Alex Dewar
2020-08-25  9:07     ` David Laight
2020-08-25  8:24   ` Greg Kroah-Hartman
2020-08-27 16:49     ` Kees Cook
2020-08-27 17:45       ` Greg Kroah-Hartman
2020-08-27  6:42 ` Rasmus Villemoes
2020-08-27  7:15   ` Greg Kroah-Hartman
2020-08-27 13:18     ` Alex Dewar
2020-08-27 13:41       ` Rasmus Villemoes
2020-08-27 14:48         ` Alex Dewar
2020-08-27 16:58           ` [Cocci] " Joe Perches
2020-08-27 16:58             ` Joe Perches
2020-08-27 19:42             ` [Cocci] " Julia Lawall
2020-08-27 19:42               ` Julia Lawall
2020-08-27 20:29               ` Joe Perches
2020-08-27 20:29                 ` Joe Perches
2020-08-27 21:00                 ` Joe Perches
2020-08-27 21:00                   ` Joe Perches
2020-08-27 21:29                 ` Julia Lawall
2020-08-27 21:29                   ` Julia Lawall
2020-08-27 22:03                 ` David Laight
2020-08-27 22:03                   ` David Laight
2020-08-27 22:11                   ` Joe Perches
2020-08-27 22:11                     ` Joe Perches
2020-08-27 22:16                     ` Kees Cook
2020-08-27 22:16                       ` Kees Cook
2020-08-27 21:01               ` Denis Efremov
2020-08-27 21:01                 ` Denis Efremov
2020-08-27 21:36                 ` Julia Lawall
2020-08-27 21:36                   ` Julia Lawall
2020-08-27 21:44                   ` Joe Perches
2020-08-27 21:44                     ` Joe Perches
2020-08-27 22:38                     ` Denis Efremov [this message]
2020-08-27 22:38                       ` Denis Efremov
2020-08-27 22:48                       ` Joe Perches
2020-08-27 22:48                         ` Joe Perches
2020-08-27 22:20                 ` Kees Cook
2020-08-27 22:20                   ` Kees Cook
2020-08-27 22:45                   ` Joe Perches
2020-08-27 22:45                     ` Joe Perches
2020-08-28  4:12                     ` Joe Perches
2020-08-28  4:12                       ` Joe Perches
2020-08-28  7:58                       ` Kees Cook
2020-08-28  7:58                         ` Kees Cook
2020-08-28  8:10                         ` Joe Perches
2020-08-28  8:10                           ` Joe Perches
2020-08-28  8:22                           ` Joe Perches
2020-08-28  8:22                             ` Joe Perches
2020-08-28  7:39                   ` David Laight
2020-08-28  7:39                     ` David Laight
2020-08-27 21:54             ` David Laight
2020-08-27 21:54               ` David Laight

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=adfca3f2-561a-9d91-c064-cf01c2b573e7@linux.com \
    --to=efremov@linux.com \
    --cc=accessrunner-general@lists.sourceforge.net \
    --cc=alex.dewar90@gmail.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavoars@kernel.org \
    --cc=joe@perches.com \
    --cc=julia.lawall@inria.fr \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /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.