Skip to content

Commit

Permalink
Merge tag 'coccinelle-for-6.8' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…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 <[email protected]>, 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
  • Loading branch information
torvalds committed Jan 20, 2024
2 parents 31e97d7 + ff82e84 commit 80fc600
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions scripts/coccinelle/api/device_attr_show.cocci
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-only
///
/// From Documentation/filesystems/sysfs.rst:
/// show() must not use snprintf() when formatting the value to be
/// returned to user space. If you can guarantee that an overflow
/// will never happen you can use sprintf() otherwise you must use
/// scnprintf().
/// show() should only use sysfs_emit() or sysfs_emit_at() when formatting
/// the value to be returned to user space.
///
// Confidence: High
// Copyright: (C) 2020 Denis Efremov ISPRAS
Expand All @@ -30,26 +28,27 @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)

@rp depends on patch@
identifier show, dev, attr, buf;
expression BUF, SZ, FORMAT, STR;
@@

ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf
+ scnprintf
(...);
- snprintf(BUF, SZ, FORMAT
+ sysfs_emit(BUF, FORMAT
,...);
...>
}

@script: python depends on report@
p << r.p;
@@

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

@script: python depends on org@
p << r.p;
@@

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

0 comments on commit 80fc600

Please sign in to comment.