Re: [PATCH] platform/x86: dell: use sysfs_emit() to instead of scnprintf()

From: Hans de Goede
Date: Thu Dec 08 2022 - 11:09:09 EST


Hi,

On 12/2/22 10:21, ye.xingchen@xxxxxxxxxx wrote:
> From: ye xingchen <ye.xingchen@xxxxxxxxxx>
>
> Follow the advice of the Documentation/filesystems/sysfs.rst and show()
> should only use sysfs_emit() or sysfs_emit_at() when formatting the
> value to be returned to user space.
>
> Signed-off-by: ye xingchen <ye.xingchen@xxxxxxxxxx>

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/dell/alienware-wmi.c | 41 +++++++++--------------
> 1 file changed, 16 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c
> index a34e07ef2c79..a9477e5432e4 100644
> --- a/drivers/platform/x86/dell/alienware-wmi.c
> +++ b/drivers/platform/x86/dell/alienware-wmi.c
> @@ -398,10 +398,10 @@ static ssize_t show_control_state(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> if (lighting_control_state == LEGACY_BOOTING)
> - return scnprintf(buf, PAGE_SIZE, "[booting] running suspend\n");
> + return sysfs_emit(buf, "[booting] running suspend\n");
> else if (lighting_control_state == LEGACY_SUSPEND)
> - return scnprintf(buf, PAGE_SIZE, "booting running [suspend]\n");
> - return scnprintf(buf, PAGE_SIZE, "booting [running] suspend\n");
> + return sysfs_emit(buf, "booting running [suspend]\n");
> + return sysfs_emit(buf, "booting [running] suspend\n");
> }
>
> static ssize_t store_control_state(struct device *dev,
> @@ -547,14 +547,12 @@ static ssize_t show_hdmi_cable(struct device *dev,
> (u32 *) &out_data);
> if (ACPI_SUCCESS(status)) {
> if (out_data == 0)
> - return scnprintf(buf, PAGE_SIZE,
> - "[unconnected] connected unknown\n");
> + return sysfs_emit(buf, "[unconnected] connected unknown\n");
> else if (out_data == 1)
> - return scnprintf(buf, PAGE_SIZE,
> - "unconnected [connected] unknown\n");
> + return sysfs_emit(buf, "unconnected [connected] unknown\n");
> }
> pr_err("alienware-wmi: unknown HDMI cable status: %d\n", status);
> - return scnprintf(buf, PAGE_SIZE, "unconnected connected [unknown]\n");
> + return sysfs_emit(buf, "unconnected connected [unknown]\n");
> }
>
> static ssize_t show_hdmi_source(struct device *dev,
> @@ -571,14 +569,12 @@ static ssize_t show_hdmi_source(struct device *dev,
>
> if (ACPI_SUCCESS(status)) {
> if (out_data == 1)
> - return scnprintf(buf, PAGE_SIZE,
> - "[input] gpu unknown\n");
> + return sysfs_emit(buf, "[input] gpu unknown\n");
> else if (out_data == 2)
> - return scnprintf(buf, PAGE_SIZE,
> - "input [gpu] unknown\n");
> + return sysfs_emit(buf, "input [gpu] unknown\n");
> }
> pr_err("alienware-wmi: unknown HDMI source status: %u\n", status);
> - return scnprintf(buf, PAGE_SIZE, "input gpu [unknown]\n");
> + return sysfs_emit(buf, "input gpu [unknown]\n");
> }
>
> static ssize_t toggle_hdmi_source(struct device *dev,
> @@ -652,14 +648,12 @@ static ssize_t show_amplifier_status(struct device *dev,
> (u32 *) &out_data);
> if (ACPI_SUCCESS(status)) {
> if (out_data == 0)
> - return scnprintf(buf, PAGE_SIZE,
> - "[unconnected] connected unknown\n");
> + return sysfs_emit(buf, "[unconnected] connected unknown\n");
> else if (out_data == 1)
> - return scnprintf(buf, PAGE_SIZE,
> - "unconnected [connected] unknown\n");
> + return sysfs_emit(buf, "unconnected [connected] unknown\n");
> }
> pr_err("alienware-wmi: unknown amplifier cable status: %d\n", status);
> - return scnprintf(buf, PAGE_SIZE, "unconnected connected [unknown]\n");
> + return sysfs_emit(buf, "unconnected connected [unknown]\n");
> }
>
> static DEVICE_ATTR(status, S_IRUGO, show_amplifier_status, NULL);
> @@ -706,17 +700,14 @@ static ssize_t show_deepsleep_status(struct device *dev,
> (u32 *) &out_data);
> if (ACPI_SUCCESS(status)) {
> if (out_data == 0)
> - return scnprintf(buf, PAGE_SIZE,
> - "[disabled] s5 s5_s4\n");
> + return sysfs_emit(buf, "[disabled] s5 s5_s4\n");
> else if (out_data == 1)
> - return scnprintf(buf, PAGE_SIZE,
> - "disabled [s5] s5_s4\n");
> + return sysfs_emit(buf, "disabled [s5] s5_s4\n");
> else if (out_data == 2)
> - return scnprintf(buf, PAGE_SIZE,
> - "disabled s5 [s5_s4]\n");
> + return sysfs_emit(buf, "disabled s5 [s5_s4]\n");
> }
> pr_err("alienware-wmi: unknown deep sleep status: %d\n", status);
> - return scnprintf(buf, PAGE_SIZE, "disabled s5 s5_s4 [unknown]\n");
> + return sysfs_emit(buf, "disabled s5 s5_s4 [unknown]\n");
> }
>
> static ssize_t toggle_deepsleep(struct device *dev,