UPSTREAM: drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
commit aa838896d87af561a33ecefea1caa4c15a68bc47 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> Bug: 182388481 [only the wakeup_stats.c portion - gregkh] (cherry picked from commit aa838896d87af561a33ecefea1caa4c15a68bc47) Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ib6f1e608caae694532cfef2ab43092274630fb54
This commit is contained in:
parent
7d2c060cae
commit
12131b4229
@ -42,7 +42,7 @@ static ssize_t active_time_ms_show(struct device *dev,
|
|||||||
ktime_t active_time =
|
ktime_t active_time =
|
||||||
ws->active ? ktime_sub(ktime_get(), ws->last_time) : 0;
|
ws->active ? ktime_sub(ktime_get(), ws->last_time) : 0;
|
||||||
|
|
||||||
return sprintf(buf, "%lld\n", ktime_to_ms(active_time));
|
return sysfs_emit(buf, "%lld\n", ktime_to_ms(active_time));
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(active_time_ms);
|
static DEVICE_ATTR_RO(active_time_ms);
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ static ssize_t total_time_ms_show(struct device *dev,
|
|||||||
active_time = ktime_sub(ktime_get(), ws->last_time);
|
active_time = ktime_sub(ktime_get(), ws->last_time);
|
||||||
total_time = ktime_add(total_time, active_time);
|
total_time = ktime_add(total_time, active_time);
|
||||||
}
|
}
|
||||||
return sprintf(buf, "%lld\n", ktime_to_ms(total_time));
|
return sysfs_emit(buf, "%lld\n", ktime_to_ms(total_time));
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(total_time_ms);
|
static DEVICE_ATTR_RO(total_time_ms);
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ static ssize_t max_time_ms_show(struct device *dev,
|
|||||||
if (active_time > max_time)
|
if (active_time > max_time)
|
||||||
max_time = active_time;
|
max_time = active_time;
|
||||||
}
|
}
|
||||||
return sprintf(buf, "%lld\n", ktime_to_ms(max_time));
|
return sysfs_emit(buf, "%lld\n", ktime_to_ms(max_time));
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(max_time_ms);
|
static DEVICE_ATTR_RO(max_time_ms);
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ static ssize_t last_change_ms_show(struct device *dev,
|
|||||||
{
|
{
|
||||||
struct wakeup_source *ws = dev_get_drvdata(dev);
|
struct wakeup_source *ws = dev_get_drvdata(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%lld\n", ktime_to_ms(ws->last_time));
|
return sysfs_emit(buf, "%lld\n", ktime_to_ms(ws->last_time));
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(last_change_ms);
|
static DEVICE_ATTR_RO(last_change_ms);
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
|
|||||||
{
|
{
|
||||||
struct wakeup_source *ws = dev_get_drvdata(dev);
|
struct wakeup_source *ws = dev_get_drvdata(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%s\n", ws->name);
|
return sysfs_emit(buf, "%s\n", ws->name);
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(name);
|
static DEVICE_ATTR_RO(name);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ static ssize_t prevent_suspend_time_ms_show(struct device *dev,
|
|||||||
prevent_sleep_time = ktime_add(prevent_sleep_time,
|
prevent_sleep_time = ktime_add(prevent_sleep_time,
|
||||||
ktime_sub(ktime_get(), ws->start_prevent_time));
|
ktime_sub(ktime_get(), ws->start_prevent_time));
|
||||||
}
|
}
|
||||||
return sprintf(buf, "%lld\n", ktime_to_ms(prevent_sleep_time));
|
return sysfs_emit(buf, "%lld\n", ktime_to_ms(prevent_sleep_time));
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(prevent_suspend_time_ms);
|
static DEVICE_ATTR_RO(prevent_suspend_time_ms);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user