Loading...
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, STR;
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")
1// SPDX-License-Identifier: GPL-2.0-only
2///
3/// From Documentation/filesystems/sysfs.txt:
4/// show() must not use snprintf() when formatting the value to be
5/// returned to user space. If you can guarantee that an overflow
6/// will never happen you can use sprintf() otherwise you must use
7/// scnprintf().
8///
9// Confidence: High
10// Copyright: (C) 2020 Denis Efremov ISPRAS
11// Options: --no-includes --include-headers
12//
13
14virtual report
15virtual org
16virtual context
17virtual patch
18
19@r depends on !patch@
20identifier show, dev, attr, buf;
21position p;
22@@
23
24ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
25{
26 <...
27* return snprintf@p(...);
28 ...>
29}
30
31@rp depends on patch@
32identifier show, dev, attr, buf;
33@@
34
35ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
36{
37 <...
38 return
39- snprintf
40+ scnprintf
41 (...);
42 ...>
43}
44
45@script: python depends on report@
46p << r.p;
47@@
48
49coccilib.report.print_report(p[0], "WARNING: use scnprintf or sprintf")
50
51@script: python depends on org@
52p << r.p;
53@@
54
55coccilib.org.print_todo(p[0], "WARNING: use scnprintf or sprintf")