1
1
// SPDX-License-Identifier: GPL-2.0-only
2
2
///
3
3
/// From Documentation/filesystems/sysfs.rst:
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().
4
+ /// show() should only use sysfs_emit() or sysfs_emit_at() when formatting
5
+ /// the value to be returned to user space.
8
6
///
9
7
// Confidence: High
10
8
// Copyright: (C) 2020 Denis Efremov ISPRAS
@@ -30,26 +28,32 @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
30
28
31
29
@rp depends on patch@
32
30
identifier show, dev, attr, buf;
31
+ expression BUF, SZ, FORMAT, STR;
33
32
@@
34
33
35
34
ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
36
35
{
37
36
< ...
37
+ (
38
38
return
39
- - snprintf
40
- + scnprintf
41
- (... );
39
+ - snprintf(BUF, SZ, FORMAT, STR);
40
+ + sysfs_emit(BUF, FORMAT, STR);
41
+ |
42
+ return
43
+ - snprintf(BUF, SZ, STR);
44
+ + sysfs_emit(BUF, STR);
45
+ )
42
46
... >
43
47
}
44
48
45
49
@script: python depends on report@
46
50
p << r.p;
47
51
@@
48
52
49
- coccilib.report.print_report(p[0], "WARNING: use scnprintf or sprintf ")
53
+ coccilib.report.print_report(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at ")
50
54
51
55
@script: python depends on org@
52
56
p << r.p;
53
57
@@
54
58
55
- coccilib.org.print_todo(p[0], "WARNING: use scnprintf or sprintf ")
59
+ coccilib.org.print_todo(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at ")
0 commit comments