linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions
@ 2021-07-15 14:16 Andy Shevchenko
  2021-07-15 14:16 ` [PATCH v1 2/2] ACPI: configfs: Make get_header() to return error pointer Andy Shevchenko
  2021-07-16 17:28 ` [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-07-15 14:16 UTC (permalink / raw)
  To: Andy Shevchenko, linux-acpi, linux-kernel; +Cc: Rafael J. Wysocki, Len Brown

The sysfs_emit() function was introduced to make it less ambiguous
which function is preferred when writing to the output buffer in
a "show" callback [1].

Convert the GPIO library sysfs interface from sprintf() to sysfs_emit()
accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly
returns the number of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/acpi_configfs.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
index 76b83b181356..6e6ef8a1f447 100644
--- a/drivers/acpi/acpi_configfs.c
+++ b/drivers/acpi/acpi_configfs.c
@@ -103,7 +103,7 @@ static ssize_t acpi_table_signature_show(struct config_item *cfg, char *str)
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->signature);
+	return sysfs_emit(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->signature);
 }
 
 static ssize_t acpi_table_length_show(struct config_item *cfg, char *str)
@@ -113,7 +113,7 @@ static ssize_t acpi_table_length_show(struct config_item *cfg, char *str)
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%d\n", h->length);
+	return sysfs_emit(str, "%d\n", h->length);
 }
 
 static ssize_t acpi_table_revision_show(struct config_item *cfg, char *str)
@@ -123,7 +123,7 @@ static ssize_t acpi_table_revision_show(struct config_item *cfg, char *str)
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%d\n", h->revision);
+	return sysfs_emit(str, "%d\n", h->revision);
 }
 
 static ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str)
@@ -133,7 +133,7 @@ static ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str)
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id);
+	return sysfs_emit(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id);
 }
 
 static ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str)
@@ -143,7 +143,7 @@ static ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str)
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id);
+	return sysfs_emit(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id);
 }
 
 static ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str)
@@ -153,7 +153,7 @@ static ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str)
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%d\n", h->oem_revision);
+	return sysfs_emit(str, "%d\n", h->oem_revision);
 }
 
 static ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg,
@@ -164,7 +164,7 @@ static ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg,
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->asl_compiler_id);
+	return sysfs_emit(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->asl_compiler_id);
 }
 
 static ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg,
@@ -175,7 +175,7 @@ static ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg,
 	if (!h)
 		return -EINVAL;
 
-	return sprintf(str, "%d\n", h->asl_compiler_revision);
+	return sysfs_emit(str, "%d\n", h->asl_compiler_revision);
 }
 
 CONFIGFS_ATTR_RO(acpi_table_, signature);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] ACPI: configfs: Make get_header() to return error pointer
  2021-07-15 14:16 [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions Andy Shevchenko
@ 2021-07-15 14:16 ` Andy Shevchenko
  2021-07-16 17:28 ` [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-07-15 14:16 UTC (permalink / raw)
  To: Andy Shevchenko, linux-acpi, linux-kernel; +Cc: Rafael J. Wysocki, Len Brown

Instead of duplicating error codes here and there,
make get_header() to return error pointer.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/acpi_configfs.c | 38 ++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
index 6e6ef8a1f447..c970792b11a4 100644
--- a/drivers/acpi/acpi_configfs.c
+++ b/drivers/acpi/acpi_configfs.c
@@ -70,7 +70,7 @@ static inline struct acpi_table_header *get_header(struct config_item *cfg)
 	if (!table->header)
 		pr_err("table not loaded\n");
 
-	return table->header;
+	return table->header ?: ERR_PTR(-EINVAL);
 }
 
 static ssize_t acpi_table_aml_read(struct config_item *cfg,
@@ -78,8 +78,8 @@ static ssize_t acpi_table_aml_read(struct config_item *cfg,
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	if (data)
 		memcpy(data, h, h->length);
@@ -100,8 +100,8 @@ static ssize_t acpi_table_signature_show(struct config_item *cfg, char *str)
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->signature);
 }
@@ -110,8 +110,8 @@ static ssize_t acpi_table_length_show(struct config_item *cfg, char *str)
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%d\n", h->length);
 }
@@ -120,8 +120,8 @@ static ssize_t acpi_table_revision_show(struct config_item *cfg, char *str)
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%d\n", h->revision);
 }
@@ -130,8 +130,8 @@ static ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str)
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id);
 }
@@ -140,8 +140,8 @@ static ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str)
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id);
 }
@@ -150,8 +150,8 @@ static ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str)
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%d\n", h->oem_revision);
 }
@@ -161,8 +161,8 @@ static ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg,
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->asl_compiler_id);
 }
@@ -172,8 +172,8 @@ static ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg,
 {
 	struct acpi_table_header *h = get_header(cfg);
 
-	if (!h)
-		return -EINVAL;
+	if (IS_ERR(h))
+		return PTR_ERR(h);
 
 	return sysfs_emit(str, "%d\n", h->asl_compiler_revision);
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions
  2021-07-15 14:16 [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions Andy Shevchenko
  2021-07-15 14:16 ` [PATCH v1 2/2] ACPI: configfs: Make get_header() to return error pointer Andy Shevchenko
@ 2021-07-16 17:28 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2021-07-16 17:28 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: ACPI Devel Maling List, Linux Kernel Mailing List,
	Rafael J. Wysocki, Len Brown

On Thu, Jul 15, 2021 at 4:16 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> The sysfs_emit() function was introduced to make it less ambiguous
> which function is preferred when writing to the output buffer in
> a "show" callback [1].
>
> Convert the GPIO library sysfs interface from sprintf() to sysfs_emit()
> accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly
> returns the number of bytes written into the buffer.
>
> No functional change intended.
>
> [1] Documentation/filesystems/sysfs.rst
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/acpi/acpi_configfs.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/acpi/acpi_configfs.c b/drivers/acpi/acpi_configfs.c
> index 76b83b181356..6e6ef8a1f447 100644
> --- a/drivers/acpi/acpi_configfs.c
> +++ b/drivers/acpi/acpi_configfs.c
> @@ -103,7 +103,7 @@ static ssize_t acpi_table_signature_show(struct config_item *cfg, char *str)
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->signature);
> +       return sysfs_emit(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->signature);
>  }
>
>  static ssize_t acpi_table_length_show(struct config_item *cfg, char *str)
> @@ -113,7 +113,7 @@ static ssize_t acpi_table_length_show(struct config_item *cfg, char *str)
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%d\n", h->length);
> +       return sysfs_emit(str, "%d\n", h->length);
>  }
>
>  static ssize_t acpi_table_revision_show(struct config_item *cfg, char *str)
> @@ -123,7 +123,7 @@ static ssize_t acpi_table_revision_show(struct config_item *cfg, char *str)
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%d\n", h->revision);
> +       return sysfs_emit(str, "%d\n", h->revision);
>  }
>
>  static ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str)
> @@ -133,7 +133,7 @@ static ssize_t acpi_table_oem_id_show(struct config_item *cfg, char *str)
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id);
> +       return sysfs_emit(str, "%.*s\n", ACPI_OEM_ID_SIZE, h->oem_id);
>  }
>
>  static ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str)
> @@ -143,7 +143,7 @@ static ssize_t acpi_table_oem_table_id_show(struct config_item *cfg, char *str)
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id);
> +       return sysfs_emit(str, "%.*s\n", ACPI_OEM_TABLE_ID_SIZE, h->oem_table_id);
>  }
>
>  static ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str)
> @@ -153,7 +153,7 @@ static ssize_t acpi_table_oem_revision_show(struct config_item *cfg, char *str)
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%d\n", h->oem_revision);
> +       return sysfs_emit(str, "%d\n", h->oem_revision);
>  }
>
>  static ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg,
> @@ -164,7 +164,7 @@ static ssize_t acpi_table_asl_compiler_id_show(struct config_item *cfg,
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->asl_compiler_id);
> +       return sysfs_emit(str, "%.*s\n", ACPI_NAMESEG_SIZE, h->asl_compiler_id);
>  }
>
>  static ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg,
> @@ -175,7 +175,7 @@ static ssize_t acpi_table_asl_compiler_revision_show(struct config_item *cfg,
>         if (!h)
>                 return -EINVAL;
>
> -       return sprintf(str, "%d\n", h->asl_compiler_revision);
> +       return sysfs_emit(str, "%d\n", h->asl_compiler_revision);
>  }
>
>  CONFIGFS_ATTR_RO(acpi_table_, signature);
> --

Applied along with the [2/2[ as 5.15 material, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-16 17:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-15 14:16 [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions Andy Shevchenko
2021-07-15 14:16 ` [PATCH v1 2/2] ACPI: configfs: Make get_header() to return error pointer Andy Shevchenko
2021-07-16 17:28 ` [PATCH v1 1/2] ACPI: configfs: Use sysfs_emit() in "show" functions Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).