Skip to content

Commit 2b91b81

Browse files
tobluxrafaeljw
authored andcommitted
thermal: intel: int340x: Use sysfs_emit{_at}() in sysfs show functions
Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show functions. sysfs_emit() and sysfs_emit_at() are preferred to format sysfs output as they provide better bounds checking. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> [ rjw: Subject adjustment, changelog edits ] Link: https://patch.msgid.link/20251220223026.125678-1-thorsten.blum@linux.dev Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8190b9e commit 2b91b81

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/kernel.h>
99
#include <linux/module.h>
1010
#include <linux/pci.h>
11+
#include <linux/sysfs.h>
1112
#include <linux/thermal.h>
1213
#include <asm/msr.h>
1314
#include "int340x_thermal_zone.h"
@@ -23,7 +24,7 @@ static ssize_t power_limit_##index##_##suffix##_show(struct device *dev, \
2324
{ \
2425
struct proc_thermal_device *proc_dev = dev_get_drvdata(dev); \
2526
\
26-
return sprintf(buf, "%lu\n",\
27+
return sysfs_emit(buf, "%lu\n",\
2728
(unsigned long)proc_dev->power_limits[index].suffix * 1000); \
2829
}
2930

@@ -143,7 +144,7 @@ static ssize_t tcc_offset_degree_celsius_show(struct device *dev,
143144
if (offset < 0)
144145
return offset;
145146

146-
return sprintf(buf, "%d\n", offset);
147+
return sysfs_emit(buf, "%d\n", offset);
147148
}
148149

149150
static ssize_t tcc_offset_degree_celsius_store(struct device *dev,

drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/kernel.h>
88
#include <linux/module.h>
99
#include <linux/pci.h>
10+
#include <linux/sysfs.h>
1011
#include "processor_thermal_device.h"
1112

1213
MODULE_IMPORT_NS("INT340X_THERMAL");
@@ -211,9 +212,9 @@ static ssize_t suffix##_show(struct device *dev,\
211212
ret = (reg_val >> mmio_regs[ret].shift) & mmio_regs[ret].mask;\
212213
err = get_mapped_string(mapping, attr->attr.name, ret, &str);\
213214
if (!err)\
214-
return sprintf(buf, "%s\n", str);\
215+
return sysfs_emit(buf, "%s\n", str);\
215216
if (err == -EOPNOTSUPP)\
216-
return sprintf(buf, "%u\n", ret);\
217+
return sysfs_emit(buf, "%u\n", ret);\
217218
return err;\
218219
}
219220

@@ -398,7 +399,7 @@ static ssize_t rfi_restriction_show(struct device *dev,
398399
if (ret)
399400
return ret;
400401

401-
return sprintf(buf, "%llu\n", resp);
402+
return sysfs_emit(buf, "%llu\n", resp);
402403
}
403404

404405
static ssize_t ddr_data_rate_show(struct device *dev,
@@ -413,7 +414,7 @@ static ssize_t ddr_data_rate_show(struct device *dev,
413414
if (ret)
414415
return ret;
415416

416-
return sprintf(buf, "%llu\n", resp);
417+
return sysfs_emit(buf, "%llu\n", resp);
417418
}
418419

419420
static DEVICE_ATTR_RW(rfi_restriction);

drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/pci.h>
10+
#include <linux/sysfs.h>
1011
#include "processor_thermal_device.h"
1112

1213
/* List of workload types */
@@ -28,9 +29,9 @@ static ssize_t workload_available_types_show(struct device *dev,
2829
int ret = 0;
2930

3031
while (workload_types[i] != NULL)
31-
ret += sprintf(&buf[ret], "%s ", workload_types[i++]);
32+
ret += sysfs_emit_at(buf, ret, "%s ", workload_types[i++]);
3233

33-
ret += sprintf(&buf[ret], "\n");
34+
ret += sysfs_emit_at(buf, ret, "\n");
3435

3536
return ret;
3637
}
@@ -85,7 +86,7 @@ static ssize_t workload_type_show(struct device *dev,
8586
if (cmd_resp > ARRAY_SIZE(workload_types) - 1)
8687
return -EINVAL;
8788

88-
return sprintf(buf, "%s\n", workload_types[cmd_resp]);
89+
return sysfs_emit(buf, "%s\n", workload_types[cmd_resp]);
8990
}
9091

9192
static DEVICE_ATTR_RW(workload_type);

0 commit comments

Comments
 (0)