2024-04-28 19:27:03

by Szilard Fabian

[permalink] [raw]
Subject: [PATCH] platform/x86/fujitsu-laptop: Replace sprintf() with sysfs_emit()

As suggested by Documentation/filesystems/sysfs.rst sysfs_emit() should be
used when formatting the value to be returned to user space.

Signed-off-by: Szilard Fabian <[email protected]>
---
drivers/platform/x86/fujitsu-laptop.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 94480af49467..968fc91bd5e4 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -386,11 +386,11 @@ static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
struct fujitsu_laptop *priv = dev_get_drvdata(dev);

if (!(priv->flags_supported & FLAG_LID))
- return sprintf(buf, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
if (priv->flags_state & FLAG_LID)
- return sprintf(buf, "open\n");
+ return sysfs_emit(buf, "open\n");
else
- return sprintf(buf, "closed\n");
+ return sysfs_emit(buf, "closed\n");
}

static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
@@ -399,11 +399,11 @@ static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
struct fujitsu_laptop *priv = dev_get_drvdata(dev);

if (!(priv->flags_supported & FLAG_DOCK))
- return sprintf(buf, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
if (priv->flags_state & FLAG_DOCK)
- return sprintf(buf, "docked\n");
+ return sysfs_emit(buf, "docked\n");
else
- return sprintf(buf, "undocked\n");
+ return sysfs_emit(buf, "undocked\n");
}

static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
@@ -412,11 +412,11 @@ static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
struct fujitsu_laptop *priv = dev_get_drvdata(dev);

if (!(priv->flags_supported & FLAG_RFKILL))
- return sprintf(buf, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
if (priv->flags_state & FLAG_RFKILL)
- return sprintf(buf, "on\n");
+ return sysfs_emit(buf, "on\n");
else
- return sprintf(buf, "killed\n");
+ return sysfs_emit(buf, "killed\n");
}

static DEVICE_ATTR_RO(lid);
--
2.44.0




2024-04-29 01:19:15

by Jonathan Woithe

[permalink] [raw]
Subject: Re: [PATCH] platform/x86/fujitsu-laptop: Replace sprintf() with sysfs_emit()

On Sun, Apr 28, 2024 at 07:26:33PM +0000, Szilard Fabian wrote:
> As suggested by Documentation/filesystems/sysfs.rst sysfs_emit() should be
> used when formatting the value to be returned to user space.
>
> Signed-off-by: Szilard Fabian <[email protected]>

This seems entirely reasonable.

Acked-by: Jonathan Woithe <[email protected]>

> ---
> drivers/platform/x86/fujitsu-laptop.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index 94480af49467..968fc91bd5e4 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -386,11 +386,11 @@ static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
> struct fujitsu_laptop *priv = dev_get_drvdata(dev);
>
> if (!(priv->flags_supported & FLAG_LID))
> - return sprintf(buf, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> if (priv->flags_state & FLAG_LID)
> - return sprintf(buf, "open\n");
> + return sysfs_emit(buf, "open\n");
> else
> - return sprintf(buf, "closed\n");
> + return sysfs_emit(buf, "closed\n");
> }
>
> static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
> @@ -399,11 +399,11 @@ static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
> struct fujitsu_laptop *priv = dev_get_drvdata(dev);
>
> if (!(priv->flags_supported & FLAG_DOCK))
> - return sprintf(buf, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> if (priv->flags_state & FLAG_DOCK)
> - return sprintf(buf, "docked\n");
> + return sysfs_emit(buf, "docked\n");
> else
> - return sprintf(buf, "undocked\n");
> + return sysfs_emit(buf, "undocked\n");
> }
>
> static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
> @@ -412,11 +412,11 @@ static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
> struct fujitsu_laptop *priv = dev_get_drvdata(dev);
>
> if (!(priv->flags_supported & FLAG_RFKILL))
> - return sprintf(buf, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> if (priv->flags_state & FLAG_RFKILL)
> - return sprintf(buf, "on\n");
> + return sysfs_emit(buf, "on\n");
> else
> - return sprintf(buf, "killed\n");
> + return sysfs_emit(buf, "killed\n");
> }
>
> static DEVICE_ATTR_RO(lid);
> --
> 2.44.0
>
>

Subject: Re: [PATCH] platform/x86/fujitsu-laptop: Replace sprintf() with sysfs_emit()

Hi,

On 4/28/24 12:26 PM, Szilard Fabian wrote:
> As suggested by Documentation/filesystems/sysfs.rst sysfs_emit() should be
> used when formatting the value to be returned to user space.
>
> Signed-off-by: Szilard Fabian <[email protected]>
> ---

Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]>

> drivers/platform/x86/fujitsu-laptop.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index 94480af49467..968fc91bd5e4 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -386,11 +386,11 @@ static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
> struct fujitsu_laptop *priv = dev_get_drvdata(dev);
>
> if (!(priv->flags_supported & FLAG_LID))
> - return sprintf(buf, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> if (priv->flags_state & FLAG_LID)
> - return sprintf(buf, "open\n");
> + return sysfs_emit(buf, "open\n");
> else
> - return sprintf(buf, "closed\n");
> + return sysfs_emit(buf, "closed\n");
> }
>
> static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
> @@ -399,11 +399,11 @@ static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
> struct fujitsu_laptop *priv = dev_get_drvdata(dev);
>
> if (!(priv->flags_supported & FLAG_DOCK))
> - return sprintf(buf, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> if (priv->flags_state & FLAG_DOCK)
> - return sprintf(buf, "docked\n");
> + return sysfs_emit(buf, "docked\n");
> else
> - return sprintf(buf, "undocked\n");
> + return sysfs_emit(buf, "undocked\n");
> }
>
> static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
> @@ -412,11 +412,11 @@ static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
> struct fujitsu_laptop *priv = dev_get_drvdata(dev);
>
> if (!(priv->flags_supported & FLAG_RFKILL))
> - return sprintf(buf, "unknown\n");
> + return sysfs_emit(buf, "unknown\n");
> if (priv->flags_state & FLAG_RFKILL)
> - return sprintf(buf, "on\n");
> + return sysfs_emit(buf, "on\n");
> else
> - return sprintf(buf, "killed\n");
> + return sysfs_emit(buf, "killed\n");
> }
>
> static DEVICE_ATTR_RO(lid);

--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer