cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] [PATCH] coccinelle: api: add sprintf() support to device_attr_show
@ 2020-08-13 22:49 Denis Efremov
  0 siblings, 0 replies; 17+ messages in thread
From: Denis Efremov @ 2020-08-13 22:49 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci, linux-kernel

It's safe to use sprintf() for simple cases in device_attr_show
type of functions. Add support for sprintf() in patch mode to
the device_attr_show.cocci script to print numbers and pointers.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
Interesting enough that with this patch coccinelle starts to skip
patch generation in some cases. For example, it skips patch for
drivers/base/core.c This is an unexpected result for me.

 scripts/coccinelle/api/device_attr_show.cocci | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/scripts/coccinelle/api/device_attr_show.cocci b/scripts/coccinelle/api/device_attr_show.cocci
index d8ec4bb8ac41..1248b8c76cfe 100644
--- a/scripts/coccinelle/api/device_attr_show.cocci
+++ b/scripts/coccinelle/api/device_attr_show.cocci
@@ -30,15 +30,45 @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
 
 @rp depends on patch@
 identifier show, dev, attr, buf;
+constant str;
 @@
 
 ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	<...
+(
+	return
+-		snprintf
++		sprintf
+			(buf,
+-			\(PAGE_SIZE\|PAGE_SIZE - 1\),
+			str);
+|
+	return
+-		snprintf
++		sprintf
+			(buf,
+-			\(PAGE_SIZE\|PAGE_SIZE - 1\),
+			\("%i"\|"%i\n"\|"%li"\|"%li\n"\|"%lli"\|"%lli\n"\|
+			  "%d"\|"%d\n"\|"%ld"\|"%ld\n"\|"%lld"\|"%lld\n"\|
+			  "%u"\|"%u\n"\|"%lu"\|"%lu\n"\|"%llu"\|"%llu\n"\|
+			  "%x"\|"%x\n"\|"%lx"\|"%lx\n"\|"%llx"\|"%llx\n"\|
+			  "%X"\|"%X\n"\|"%lX"\|"%lX\n"\|"%llX"\|"%llX\n"\|
+			  "0x%x"\|"0x%x\n"\|"0x%lx"\|"0x%lx\n"\|"0x%llx"\|"0x%llx\n"\|
+			  "0x%X"\|"0x%X\n"\|"0x%lX"\|"0x%lX\n"\|"0x%llX"\|"0x%llX\n"\|
+			  "%02x\n"\|"%03x\n"\|"%04x\n"\|"%08x\n"\|
+			  "%02X\n"\|"%03X\n"\|"%04X\n"\|"%08X\n"\|
+			  "0x%02x\n"\|"0x%03x\n"\|"0x%04x\n"\|"0x%08x\n"\|
+			  "0x%02X\n"\|"0x%03X\n"\|"0x%04X\n"\|"0x%08X\n"\|
+			  "%zd"\|"%zd\n"\|"%zu"\|"%zu\n"\|"%zx"\|"%zx\n"\|
+			  "%c"\|"%c\n"\|"%p"\|"%p\n"\|"%pU\n"\|"%pUl\n"\|"%hu\n"\),
+			...);
+|
 	return
 -		snprintf
 +		scnprintf
 			(...);
+)
 	...>
 }
 
-- 
2.26.2

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

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-09-05 11:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <ed9a8046-4c21-e849-f68b-9e08991b701d@web.de>
2020-08-14  8:50 ` [Cocci] [PATCH] coccinelle: api: add sprintf() support to device_attr_show Denis Efremov
     [not found]   ` <48ffa436-6e73-88b2-07bc-89942f3c6d8e@web.de>
2020-08-14 14:36     ` Denis Efremov
     [not found]       ` <047eaa85-20cf-800d-7087-a980f53572de@web.de>
2020-08-16  8:37         ` [Cocci] Searching for format strings with SmPL disjunctions Markus Elfring
2020-08-16  8:43           ` Julia Lawall
2020-08-16  8:48             ` Markus Elfring
2020-08-16 11:00             ` Markus Elfring
2020-08-15 10:32   ` [Cocci] [PATCH] coccinelle: api: add sprintf() support to device_attr_show Julia Lawall
2020-08-17  7:00     ` [Cocci] " Markus Elfring
2020-08-17  7:42       ` Julia Lawall
2020-08-17  7:57         ` Markus Elfring
2020-08-17  8:02           ` Julia Lawall
     [not found]             ` <cad4141c-8cba-3705-a502-0620ae3df027@web.de>
2020-08-17  8:24               ` Julia Lawall
     [not found]                 ` <1e60d36d-7f2b-98eb-5fe3-9729b97ba360@web.de>
2020-08-17 16:29                   ` Julia Lawall
     [not found]                     ` <afbbc6f1-ca60-e780-0139-d944165e456f@web.de>
2020-09-05  7:39                       ` Julia Lawall
     [not found]                         ` <26349832-57a8-4c6e-efc9-0febd5650922@web.de>
2020-09-05  9:53                           ` Julia Lawall
2020-09-05 11:08                           ` Julia Lawall
2020-08-13 22:49 [Cocci] [PATCH] " Denis Efremov

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).