Skip to content

Commit 847e338

Browse files
tiwaigregkh
authored andcommitted
drivers/base/cpu: Simplify s*nprintf() usages
Use the simpler sprintf() instead of snprintf() or scnprintf() in a single-shot sysfs output callbacks where you are very sure that it won't go over PAGE_SIZE buffer limit. Signed-off-by: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4636a04 commit 847e338

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

drivers/base/cpu.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ static struct cpu_attr cpu_attrs[] = {
231231
static ssize_t print_cpus_kernel_max(struct device *dev,
232232
struct device_attribute *attr, char *buf)
233233
{
234-
int n = snprintf(buf, PAGE_SIZE-2, "%d\n", NR_CPUS - 1);
235-
return n;
234+
return sprintf(buf, "%d\n", NR_CPUS - 1);
236235
}
237236
static DEVICE_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL);
238237

@@ -272,15 +271,15 @@ static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);
272271
static ssize_t print_cpus_isolated(struct device *dev,
273272
struct device_attribute *attr, char *buf)
274273
{
275-
int n = 0, len = PAGE_SIZE-2;
274+
int n;
276275
cpumask_var_t isolated;
277276

278277
if (!alloc_cpumask_var(&isolated, GFP_KERNEL))
279278
return -ENOMEM;
280279

281280
cpumask_andnot(isolated, cpu_possible_mask,
282281
housekeeping_cpumask(HK_FLAG_DOMAIN));
283-
n = scnprintf(buf, len, "%*pbl\n", cpumask_pr_args(isolated));
282+
n = sprintf(buf, "%*pbl\n", cpumask_pr_args(isolated));
284283

285284
free_cpumask_var(isolated);
286285

@@ -292,11 +291,7 @@ static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
292291
static ssize_t print_cpus_nohz_full(struct device *dev,
293292
struct device_attribute *attr, char *buf)
294293
{
295-
int n = 0, len = PAGE_SIZE-2;
296-
297-
n = scnprintf(buf, len, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
298-
299-
return n;
294+
return sprintf(buf, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
300295
}
301296
static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);
302297
#endif

0 commit comments

Comments
 (0)