mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:24:47 +01:00
ACPI: sysfs: Replace sprintf() with sysfs_emit()
Replace all sprintf() calls with sysfs_emit() in sysfs show functions. sysfs_emit() is preferred to sprintf() for formatting sysfs output as it provides better bounds checking and prevents potential buffer overflows. Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com> [ rjw: Subject and changelog edits ] Link: https://patch.msgid.link/20260126093949.8910-1-sumeet4linux@gmail.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
2aa1e46250
commit
785632d826
2 changed files with 25 additions and 25 deletions
|
|
@ -27,7 +27,7 @@ static ssize_t acpi_object_path(acpi_handle handle, char *buf)
|
|||
if (result)
|
||||
return result;
|
||||
|
||||
result = sprintf(buf, "%s\n", (char *)path.pointer);
|
||||
result = sysfs_emit(buf, "%s\n", (char *)path.pointer);
|
||||
kfree(path.pointer);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -347,7 +347,7 @@ static ssize_t real_power_state_show(struct device *dev,
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
return sprintf(buf, "%s\n", acpi_power_state_string(state));
|
||||
return sysfs_emit(buf, "%s\n", acpi_power_state_string(state));
|
||||
}
|
||||
|
||||
static DEVICE_ATTR_RO(real_power_state);
|
||||
|
|
@ -357,7 +357,7 @@ static ssize_t power_state_show(struct device *dev,
|
|||
{
|
||||
struct acpi_device *adev = to_acpi_device(dev);
|
||||
|
||||
return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
|
||||
return sysfs_emit(buf, "%s\n", acpi_power_state_string(adev->power.state));
|
||||
}
|
||||
|
||||
static DEVICE_ATTR_RO(power_state);
|
||||
|
|
@ -399,7 +399,7 @@ hid_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|||
{
|
||||
struct acpi_device *acpi_dev = to_acpi_device(dev);
|
||||
|
||||
return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
|
||||
return sysfs_emit(buf, "%s\n", acpi_device_hid(acpi_dev));
|
||||
}
|
||||
static DEVICE_ATTR_RO(hid);
|
||||
|
||||
|
|
@ -435,7 +435,7 @@ static ssize_t uid_show(struct device *dev,
|
|||
{
|
||||
struct acpi_device *acpi_dev = to_acpi_device(dev);
|
||||
|
||||
return sprintf(buf, "%s\n", acpi_device_uid(acpi_dev));
|
||||
return sysfs_emit(buf, "%s\n", acpi_device_uid(acpi_dev));
|
||||
}
|
||||
static DEVICE_ATTR_RO(uid);
|
||||
|
||||
|
|
@ -445,9 +445,9 @@ static ssize_t adr_show(struct device *dev,
|
|||
struct acpi_device *acpi_dev = to_acpi_device(dev);
|
||||
|
||||
if (acpi_dev->pnp.bus_address > U32_MAX)
|
||||
return sprintf(buf, "0x%016llx\n", acpi_dev->pnp.bus_address);
|
||||
return sysfs_emit(buf, "0x%016llx\n", acpi_dev->pnp.bus_address);
|
||||
else
|
||||
return sprintf(buf, "0x%08llx\n", acpi_dev->pnp.bus_address);
|
||||
return sysfs_emit(buf, "0x%08llx\n", acpi_dev->pnp.bus_address);
|
||||
}
|
||||
static DEVICE_ATTR_RO(adr);
|
||||
|
||||
|
|
@ -509,7 +509,7 @@ sun_show(struct device *dev, struct device_attribute *attr,
|
|||
if (ACPI_FAILURE(status))
|
||||
return -EIO;
|
||||
|
||||
return sprintf(buf, "%llu\n", sun);
|
||||
return sysfs_emit(buf, "%llu\n", sun);
|
||||
}
|
||||
static DEVICE_ATTR_RO(sun);
|
||||
|
||||
|
|
@ -525,7 +525,7 @@ hrv_show(struct device *dev, struct device_attribute *attr,
|
|||
if (ACPI_FAILURE(status))
|
||||
return -EIO;
|
||||
|
||||
return sprintf(buf, "%llu\n", hrv);
|
||||
return sysfs_emit(buf, "%llu\n", hrv);
|
||||
}
|
||||
static DEVICE_ATTR_RO(hrv);
|
||||
|
||||
|
|
@ -540,7 +540,7 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
|
|||
if (ACPI_FAILURE(status))
|
||||
return -EIO;
|
||||
|
||||
return sprintf(buf, "%llu\n", sta);
|
||||
return sysfs_emit(buf, "%llu\n", sta);
|
||||
}
|
||||
static DEVICE_ATTR_RO(status);
|
||||
|
||||
|
|
|
|||
|
|
@ -687,7 +687,7 @@ static ssize_t counter_show(struct kobject *kobj,
|
|||
acpi_irq_not_handled;
|
||||
all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
|
||||
acpi_gpe_count;
|
||||
size = sprintf(buf, "%8u", all_counters[index].count);
|
||||
size = sysfs_emit(buf, "%8u", all_counters[index].count);
|
||||
|
||||
/* "gpe_all" or "sci" */
|
||||
if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
|
||||
|
|
@ -698,29 +698,29 @@ static ssize_t counter_show(struct kobject *kobj,
|
|||
goto end;
|
||||
|
||||
if (status & ACPI_EVENT_FLAG_ENABLE_SET)
|
||||
size += sprintf(buf + size, " EN");
|
||||
size += sysfs_emit_at(buf, size, " EN");
|
||||
else
|
||||
size += sprintf(buf + size, " ");
|
||||
size += sysfs_emit_at(buf, size, " ");
|
||||
if (status & ACPI_EVENT_FLAG_STATUS_SET)
|
||||
size += sprintf(buf + size, " STS");
|
||||
size += sysfs_emit_at(buf, size, " STS");
|
||||
else
|
||||
size += sprintf(buf + size, " ");
|
||||
size += sysfs_emit_at(buf, size, " ");
|
||||
|
||||
if (!(status & ACPI_EVENT_FLAG_HAS_HANDLER))
|
||||
size += sprintf(buf + size, " invalid ");
|
||||
size += sysfs_emit_at(buf, size, " invalid ");
|
||||
else if (status & ACPI_EVENT_FLAG_ENABLED)
|
||||
size += sprintf(buf + size, " enabled ");
|
||||
size += sysfs_emit_at(buf, size, " enabled ");
|
||||
else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
|
||||
size += sprintf(buf + size, " wake_enabled");
|
||||
size += sysfs_emit_at(buf, size, " wake_enabled");
|
||||
else
|
||||
size += sprintf(buf + size, " disabled ");
|
||||
size += sysfs_emit_at(buf, size, " disabled ");
|
||||
if (status & ACPI_EVENT_FLAG_MASKED)
|
||||
size += sprintf(buf + size, " masked ");
|
||||
size += sysfs_emit_at(buf, size, " masked ");
|
||||
else
|
||||
size += sprintf(buf + size, " unmasked");
|
||||
size += sysfs_emit_at(buf, size, " unmasked");
|
||||
|
||||
end:
|
||||
size += sprintf(buf + size, "\n");
|
||||
size += sysfs_emit_at(buf, size, "\n");
|
||||
return result ? result : size;
|
||||
}
|
||||
|
||||
|
|
@ -937,7 +937,7 @@ static void __exit interrupt_stats_exit(void)
|
|||
|
||||
static ssize_t pm_profile_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", acpi_gbl_FADT.preferred_profile);
|
||||
return sysfs_emit(buf, "%d\n", acpi_gbl_FADT.preferred_profile);
|
||||
}
|
||||
|
||||
static const struct kobj_attribute pm_profile_attr = __ATTR_RO(pm_profile);
|
||||
|
|
@ -946,7 +946,7 @@ static ssize_t enabled_show(struct kobject *kobj, struct kobj_attribute *attr, c
|
|||
{
|
||||
struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj);
|
||||
|
||||
return sprintf(buf, "%d\n", hotplug->enabled);
|
||||
return sysfs_emit(buf, "%d\n", hotplug->enabled);
|
||||
}
|
||||
|
||||
static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr,
|
||||
|
|
@ -1000,7 +1000,7 @@ void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
|
|||
static ssize_t force_remove_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", 0);
|
||||
return sysfs_emit(buf, "%d\n", 0);
|
||||
}
|
||||
|
||||
static ssize_t force_remove_store(struct kobject *kobj,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue