As Documentation/filesystems/sysfs.rst suggested,
show() should only use sysfs_emit() or sysfs_emit_at() when formatting
the value to be returned to user space.
Signed-off-by: yunshui <[email protected]>
Signed-off-by: Ai Chao <[email protected]>
---
drivers/platform/x86/asus-laptop.c | 44 +++++++++++++++---------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index 78c42767295a..ccb33d034e2a 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -852,8 +852,8 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
* so we don't set eof to 1
*/
- len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
- len += sprintf(page + len, "Model reference : %s\n", asus->name);
+ len += sysfs_emit_at(page, len, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
+ len += sysfs_emit_at(page, len, "Model reference : %s\n", asus->name);
/*
* The SFUN method probably allows the original driver to get the list
* of features supported by a given model. For now, 0x0100 or 0x0800
@@ -862,7 +862,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
*/
rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
if (ACPI_SUCCESS(rv))
- len += sprintf(page + len, "SFUN value : %#x\n",
+ len += sysfs_emit_at(page, len, "SFUN value : %#x\n",
(uint) temp);
/*
* The HWRS method return informations about the hardware.
@@ -874,7 +874,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
*/
rv = acpi_evaluate_integer(asus->handle, "HWRS", NULL, &temp);
if (ACPI_SUCCESS(rv))
- len += sprintf(page + len, "HWRS value : %#x\n",
+ len += sysfs_emit_at(page, len, "HWRS value : %#x\n",
(uint) temp);
/*
* Another value for userspace: the ASYM method returns 0x02 for
@@ -885,25 +885,25 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
*/
rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
if (ACPI_SUCCESS(rv))
- len += sprintf(page + len, "ASYM value : %#x\n",
+ len += sysfs_emit_at(page, len, "ASYM value : %#x\n",
(uint) temp);
if (asus->dsdt_info) {
snprintf(buf, 16, "%d", asus->dsdt_info->length);
- len += sprintf(page + len, "DSDT length : %s\n", buf);
+ len += sysfs_emit_at(page, len, "DSDT length : %s\n", buf);
snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
- len += sprintf(page + len, "DSDT checksum : %s\n", buf);
+ len += sysfs_emit_at(page, len, "DSDT checksum : %s\n", buf);
snprintf(buf, 16, "%d", asus->dsdt_info->revision);
- len += sprintf(page + len, "DSDT revision : %s\n", buf);
+ len += sysfs_emit_at(page, len, "DSDT revision : %s\n", buf);
snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
- len += sprintf(page + len, "OEM id : %s\n", buf);
+ len += sysfs_emit_at(page, len, "OEM id : %s\n", buf);
snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
- len += sprintf(page + len, "OEM table id : %s\n", buf);
+ len += sysfs_emit_at(page, len, "OEM table id : %s\n", buf);
snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
- len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
+ len += sysfs_emit_at(page, len, "OEM revision : 0x%s\n", buf);
snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
- len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
+ len += sysfs_emit_at(page, len, "ASL comp vendor id : %s\n", buf);
snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
- len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
+ len += sysfs_emit_at(page, len, "ASL comp revision : 0x%s\n", buf);
}
return len;
@@ -933,7 +933,7 @@ static ssize_t ledd_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "0x%08x\n", asus->ledd_status);
+ return sysfs_emit(buf, "0x%08x\n", asus->ledd_status);
}
static ssize_t ledd_store(struct device *dev, struct device_attribute *attr,
@@ -993,7 +993,7 @@ static ssize_t wlan_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
+ return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
}
static ssize_t wlan_store(struct device *dev, struct device_attribute *attr,
@@ -1022,7 +1022,7 @@ static ssize_t bluetooth_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
+ return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
}
static ssize_t bluetooth_store(struct device *dev,
@@ -1052,7 +1052,7 @@ static ssize_t wimax_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
+ return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
}
static ssize_t wimax_store(struct device *dev, struct device_attribute *attr,
@@ -1081,7 +1081,7 @@ static ssize_t wwan_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
+ return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
}
static ssize_t wwan_store(struct device *dev, struct device_attribute *attr,
@@ -1151,7 +1151,7 @@ static ssize_t ls_switch_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus->light_switch);
+ return sysfs_emit(buf, "%d\n", asus->light_switch);
}
static ssize_t ls_switch_store(struct device *dev,
@@ -1182,7 +1182,7 @@ static ssize_t ls_level_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus->light_level);
+ return sysfs_emit(buf, "%d\n", asus->light_level);
}
static ssize_t ls_level_store(struct device *dev, struct device_attribute *attr,
@@ -1228,7 +1228,7 @@ static ssize_t ls_value_show(struct device *dev, struct device_attribute *attr,
if (!err)
err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
if (!err)
- return sprintf(buf, "%d\n", 10 * hi + lo);
+ return sysfs_emit(buf, "%d\n", 10 * hi + lo);
return err;
}
static DEVICE_ATTR_RO(ls_value);
@@ -1264,7 +1264,7 @@ static ssize_t gps_show(struct device *dev, struct device_attribute *attr,
{
struct asus_laptop *asus = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", asus_gps_status(asus));
+ return sysfs_emit(buf, "%d\n", asus_gps_status(asus));
}
static ssize_t gps_store(struct device *dev, struct device_attribute *attr,
--
2.34.1
Hi,
On 4/22/24 8:29 AM, yunshui wrote:
> As Documentation/filesystems/sysfs.rst suggested,
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
> the value to be returned to user space.
>
> Signed-off-by: yunshui <[email protected]>
> Signed-off-by: Ai Chao <[email protected]>
Thank you for your patch, I've applied this patch to my review-hans
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.
Regards,
Hans
> ---
> drivers/platform/x86/asus-laptop.c | 44 +++++++++++++++---------------
> 1 file changed, 22 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
> index 78c42767295a..ccb33d034e2a 100644
> --- a/drivers/platform/x86/asus-laptop.c
> +++ b/drivers/platform/x86/asus-laptop.c
> @@ -852,8 +852,8 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
> * so we don't set eof to 1
> */
>
> - len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
> - len += sprintf(page + len, "Model reference : %s\n", asus->name);
> + len += sysfs_emit_at(page, len, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
> + len += sysfs_emit_at(page, len, "Model reference : %s\n", asus->name);
> /*
> * The SFUN method probably allows the original driver to get the list
> * of features supported by a given model. For now, 0x0100 or 0x0800
> @@ -862,7 +862,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
> */
> rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
> if (ACPI_SUCCESS(rv))
> - len += sprintf(page + len, "SFUN value : %#x\n",
> + len += sysfs_emit_at(page, len, "SFUN value : %#x\n",
> (uint) temp);
> /*
> * The HWRS method return informations about the hardware.
> @@ -874,7 +874,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
> */
> rv = acpi_evaluate_integer(asus->handle, "HWRS", NULL, &temp);
> if (ACPI_SUCCESS(rv))
> - len += sprintf(page + len, "HWRS value : %#x\n",
> + len += sysfs_emit_at(page, len, "HWRS value : %#x\n",
> (uint) temp);
> /*
> * Another value for userspace: the ASYM method returns 0x02 for
> @@ -885,25 +885,25 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
> */
> rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
> if (ACPI_SUCCESS(rv))
> - len += sprintf(page + len, "ASYM value : %#x\n",
> + len += sysfs_emit_at(page, len, "ASYM value : %#x\n",
> (uint) temp);
> if (asus->dsdt_info) {
> snprintf(buf, 16, "%d", asus->dsdt_info->length);
> - len += sprintf(page + len, "DSDT length : %s\n", buf);
> + len += sysfs_emit_at(page, len, "DSDT length : %s\n", buf);
> snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
> - len += sprintf(page + len, "DSDT checksum : %s\n", buf);
> + len += sysfs_emit_at(page, len, "DSDT checksum : %s\n", buf);
> snprintf(buf, 16, "%d", asus->dsdt_info->revision);
> - len += sprintf(page + len, "DSDT revision : %s\n", buf);
> + len += sysfs_emit_at(page, len, "DSDT revision : %s\n", buf);
> snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
> - len += sprintf(page + len, "OEM id : %s\n", buf);
> + len += sysfs_emit_at(page, len, "OEM id : %s\n", buf);
> snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
> - len += sprintf(page + len, "OEM table id : %s\n", buf);
> + len += sysfs_emit_at(page, len, "OEM table id : %s\n", buf);
> snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
> - len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
> + len += sysfs_emit_at(page, len, "OEM revision : 0x%s\n", buf);
> snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
> - len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
> + len += sysfs_emit_at(page, len, "ASL comp vendor id : %s\n", buf);
> snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
> - len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
> + len += sysfs_emit_at(page, len, "ASL comp revision : 0x%s\n", buf);
> }
>
> return len;
> @@ -933,7 +933,7 @@ static ssize_t ledd_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "0x%08x\n", asus->ledd_status);
> + return sysfs_emit(buf, "0x%08x\n", asus->ledd_status);
> }
>
> static ssize_t ledd_store(struct device *dev, struct device_attribute *attr,
> @@ -993,7 +993,7 @@ static ssize_t wlan_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
> + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
> }
>
> static ssize_t wlan_store(struct device *dev, struct device_attribute *attr,
> @@ -1022,7 +1022,7 @@ static ssize_t bluetooth_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
> + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
> }
>
> static ssize_t bluetooth_store(struct device *dev,
> @@ -1052,7 +1052,7 @@ static ssize_t wimax_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
> + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
> }
>
> static ssize_t wimax_store(struct device *dev, struct device_attribute *attr,
> @@ -1081,7 +1081,7 @@ static ssize_t wwan_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
> + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
> }
>
> static ssize_t wwan_store(struct device *dev, struct device_attribute *attr,
> @@ -1151,7 +1151,7 @@ static ssize_t ls_switch_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus->light_switch);
> + return sysfs_emit(buf, "%d\n", asus->light_switch);
> }
>
> static ssize_t ls_switch_store(struct device *dev,
> @@ -1182,7 +1182,7 @@ static ssize_t ls_level_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus->light_level);
> + return sysfs_emit(buf, "%d\n", asus->light_level);
> }
>
> static ssize_t ls_level_store(struct device *dev, struct device_attribute *attr,
> @@ -1228,7 +1228,7 @@ static ssize_t ls_value_show(struct device *dev, struct device_attribute *attr,
> if (!err)
> err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
> if (!err)
> - return sprintf(buf, "%d\n", 10 * hi + lo);
> + return sysfs_emit(buf, "%d\n", 10 * hi + lo);
> return err;
> }
> static DEVICE_ATTR_RO(ls_value);
> @@ -1264,7 +1264,7 @@ static ssize_t gps_show(struct device *dev, struct device_attribute *attr,
> {
> struct asus_laptop *asus = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", asus_gps_status(asus));
> + return sysfs_emit(buf, "%d\n", asus_gps_status(asus));
> }
>
> static ssize_t gps_store(struct device *dev, struct device_attribute *attr,