xref: /linux/scripts/coccinelle/api/device_attr_show.cocci (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1// SPDX-License-Identifier: GPL-2.0-only
2///
3/// From Documentation/filesystems/sysfs.rst:
4///  show() should only use sysfs_emit() or sysfs_emit_at() when formatting
5///  the value to be returned to user space.
6///
7// Confidence: High
8// Copyright: (C) 2020 Denis Efremov ISPRAS
9// Options: --no-includes --include-headers
10//
11
12virtual report
13virtual org
14virtual context
15virtual patch
16
17@r depends on !patch@
18identifier show, dev, attr, buf;
19position p;
20@@
21
22ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
23{
24	<...
25*	return snprintf@p(...);
26	...>
27}
28
29@rp depends on patch@
30identifier show, dev, attr, buf;
31expression BUF, SZ, FORMAT;
32@@
33
34ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
35{
36	<...
37	return
38-		snprintf(BUF, SZ, FORMAT
39+		sysfs_emit(BUF, FORMAT
40				,...);
41	...>
42}
43
44@script: python depends on report@
45p << r.p;
46@@
47
48coccilib.report.print_report(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at")
49
50@script: python depends on org@
51p << r.p;
52@@
53
54coccilib.org.print_todo(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at")
55