Skip to content

Commit 80fc600

Browse files
committed
Merge tag 'coccinelle-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux
Pull coccinelle updates from Julia Lawall: "Updates to the device_attr_show semantic patch to reflect the new guidelines of the Linux kernel documentation. The problem was identified by Li Zhijian <lizhijian@fujitsu.com>, who proposed an initial fix" * tag 'coccinelle-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux: coccinelle: device_attr_show: simplify patch case coccinelle: device_attr_show: Adapt to the latest Documentation/filesystems/sysfs.rst
2 parents 31e97d7 + ff82e84 commit 80fc600

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

scripts/coccinelle/api/device_attr_show.cocci

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
///
33
/// 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.
86
///
97
// Confidence: High
108
// Copyright: (C) 2020 Denis Efremov ISPRAS
@@ -30,26 +28,27 @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
3028

3129
@rp depends on patch@
3230
identifier show, dev, attr, buf;
31+
expression BUF, SZ, FORMAT, STR;
3332
@@
3433

3534
ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
3635
{
3736
<...
3837
return
39-
- snprintf
40-
+ scnprintf
41-
(...);
38+
- snprintf(BUF, SZ, FORMAT
39+
+ sysfs_emit(BUF, FORMAT
40+
,...);
4241
...>
4342
}
4443

4544
@script: python depends on report@
4645
p << r.p;
4746
@@
4847

49-
coccilib.report.print_report(p[0], "WARNING: use scnprintf or sprintf")
48+
coccilib.report.print_report(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at")
5049

5150
@script: python depends on org@
5251
p << r.p;
5352
@@
5453

55-
coccilib.org.print_todo(p[0], "WARNING: use scnprintf or sprintf")
54+
coccilib.org.print_todo(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at")

0 commit comments

Comments
 (0)