linux-stable/drivers/base/power
Joe Perches 9e9241d334 drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
commit aa838896d8 upstream.

Convert the various sprintf fmaily calls in sysfs device show functions
to sysfs_emit and sysfs_emit_at for PAGE_SIZE buffer safety.

Done with:

$ spatch -sp-file sysfs_emit_dev.cocci --in-place --max-width=80 .

And cocci script:

$ cat sysfs_emit_dev.cocci
@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	sprintf(buf,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	snprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	scnprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	strcpy(buf, chr);
+	sysfs_emit(buf, chr);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	sprintf(buf,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	snprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	scnprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
-	len += scnprintf(buf + len, PAGE_SIZE - len,
+	len += sysfs_emit_at(buf, len,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	...
-	strcpy(buf, chr);
-	return strlen(buf);
+	return sysfs_emit(buf, chr);
}

Signed-off-by: Joe Perches <joe@perches.com>
Link: https://lore.kernel.org/r/3d033c33056d88bbe34d4ddb62afd05ee166ab9a.1600285923.git.joe@perches.com
Cc: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-01-16 09:15:38 +01:00
..
clock_ops.c PM / clk: Remove error message on out-of-memory condition 2019-05-28 19:40:21 +02:00
common.c drivers: base: power: add proper SPDX identifiers on files that did not have them. 2019-04-04 20:03:40 +02:00
domain.c PM / Domains: Allow no domain-idle-states DT property in genpd when parsing 2020-04-17 10:50:12 +02:00
domain_governor.c PM / QOS: Pass request type to dev_pm_qos_read_value() 2019-07-04 10:40:54 +02:00
generic_ops.c drivers: base: power: add proper SPDX identifiers on files that did not have them. 2019-04-04 20:03:40 +02:00
main.c PM: sleep: core: Fix the handling of pending runtime resume requests 2020-09-03 11:27:05 +02:00
Makefile PM / wakeup: Show wakeup sources stats in sysfs 2019-08-21 00:20:40 +02:00
power.h PM / wakeup: Register wakeup class kobj after device is added 2019-08-21 00:25:16 +02:00
qos.c PM: QoS: Drop frequency QoS types from device PM QoS 2019-10-21 02:05:21 +02:00
runtime.c PM: runtime: Fix unpaired parent child_count for force_resume 2021-05-19 10:08:20 +02:00
sysfs.c drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions 2022-01-16 09:15:38 +01:00
trace.c PM: base: power: don't try to use non-existing RTC for storing data 2021-09-22 12:26:39 +02:00
wakeirq.c drivers: base: power: add proper SPDX identifiers on files that did not have them. 2019-04-04 20:03:40 +02:00
wakeup.c PM: wakeup: Show statistics for deleted wakeup sources again 2020-07-31 18:39:32 +02:00
wakeup_stats.c drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions 2022-01-16 09:15:38 +01:00