diff mbox series

platform/mellanox: mlxbf-bootctl: use sysfs_emit() instead of sprintf()

Message ID 20250116080836.2890442-1-aichao@kylinos.cn (mailing list archive)
State Accepted, archived
Headers show
Series platform/mellanox: mlxbf-bootctl: use sysfs_emit() instead of sprintf() | expand

Commit Message

Ai Chao Jan. 16, 2025, 8:08 a.m. UTC
Follow the advice in Documentation/filesystems/sysfs.rst:
show() should only use sysfs_emit() or sysfs_emit_at() when formatting
the value to be returned to user space.

Signed-off-by: Ai Chao <aichao@kylinos.cn>
---
 drivers/platform/mellanox/mlxbf-bootctl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Vadim Pasternak Jan. 16, 2025, 9:03 a.m. UTC | #1
> -----Original Message-----
> From: Ai Chao <aichao@kylinos.cn>
> Sent: Thursday, 16 January 2025 10:09
> To: hdegoede@redhat.com; ilpo.jarvinen@linux.intel.com; Vadim Pasternak
> <vadimp@nvidia.com>; platform-driver-x86@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Cc: Ai Chao <aichao@kylinos.cn>
> Subject: [PATCH] platform/mellanox: mlxbf-bootctl: use sysfs_emit() instead
> of sprintf()
> 
> Follow the advice in Documentation/filesystems/sysfs.rst:
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting the
> value to be returned to user space.
> 
> Signed-off-by: Ai Chao <aichao@kylinos.cn>

Acked-by: Vadim Pasternak <vadimp@nvidia.com>

> ---
>  drivers/platform/mellanox/mlxbf-bootctl.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/platform/mellanox/mlxbf-bootctl.c
> b/drivers/platform/mellanox/mlxbf-bootctl.c
> index a2011af48201..9cae07348d5e 100644
> --- a/drivers/platform/mellanox/mlxbf-bootctl.c
> +++ b/drivers/platform/mellanox/mlxbf-bootctl.c
> @@ -177,7 +177,7 @@ static ssize_t post_reset_wdog_show(struct device
> *dev,
>  	if (ret < 0)
>  		return ret;
> 
> -	return sprintf(buf, "%d\n", ret);
> +	return sysfs_emit(buf, "%d\n", ret);
>  }
> 
>  static ssize_t post_reset_wdog_store(struct device *dev, @@ -206,7 +206,7
> @@ static ssize_t mlxbf_bootctl_show(int smc_op, char *buf)
>  	if (action < 0)
>  		return action;
> 
> -	return sprintf(buf, "%s\n", mlxbf_bootctl_action_to_string(action));
> +	return sysfs_emit(buf, "%s\n",
> +mlxbf_bootctl_action_to_string(action));
>  }
> 
>  static int mlxbf_bootctl_store(int smc_op, const char *buf, size_t count) @@ -
> 274,14 +274,14 @@ static ssize_t lifecycle_state_show(struct device *dev,
>  	 * due to using the test bits.
>  	 */
>  	if (test_state) {
> -		return sprintf(buf, "%s(test)\n",
> +		return sysfs_emit(buf, "%s(test)\n",
>  			       mlxbf_bootctl_lifecycle_states[lc_state]);
>  	} else if (use_dev_key &&
>  		   (lc_state == MLXBF_BOOTCTL_SB_LIFECYCLE_GA_SECURE)) {
> -		return sprintf(buf, "Secured (development)\n");
> +		return sysfs_emit(buf, "Secured (development)\n");
>  	}
> 
> -	return sprintf(buf, "%s\n", mlxbf_bootctl_lifecycle_states[lc_state]);
> +	return sysfs_emit(buf, "%s\n",
> +mlxbf_bootctl_lifecycle_states[lc_state]);
>  }
> 
>  static ssize_t secure_boot_fuse_state_show(struct device *dev, @@ -332,9
> +332,9 @@ static ssize_t secure_boot_fuse_state_show(struct device *dev,
>  			else
>  				status = valid ? "Invalid" : "Free";
>  		}
> -		buf_len += sprintf(buf + buf_len, "%d:%s ", key, status);
> +		buf_len += sysfs_emit(buf + buf_len, "%d:%s ", key, status);
>  	}
> -	buf_len += sprintf(buf + buf_len, "\n");
> +	buf_len += sysfs_emit(buf + buf_len, "\n");
> 
>  	return buf_len;
>  }
> --
> 2.47.1
diff mbox series

Patch

diff --git a/drivers/platform/mellanox/mlxbf-bootctl.c b/drivers/platform/mellanox/mlxbf-bootctl.c
index a2011af48201..9cae07348d5e 100644
--- a/drivers/platform/mellanox/mlxbf-bootctl.c
+++ b/drivers/platform/mellanox/mlxbf-bootctl.c
@@ -177,7 +177,7 @@  static ssize_t post_reset_wdog_show(struct device *dev,
 	if (ret < 0)
 		return ret;
 
-	return sprintf(buf, "%d\n", ret);
+	return sysfs_emit(buf, "%d\n", ret);
 }
 
 static ssize_t post_reset_wdog_store(struct device *dev,
@@ -206,7 +206,7 @@  static ssize_t mlxbf_bootctl_show(int smc_op, char *buf)
 	if (action < 0)
 		return action;
 
-	return sprintf(buf, "%s\n", mlxbf_bootctl_action_to_string(action));
+	return sysfs_emit(buf, "%s\n", mlxbf_bootctl_action_to_string(action));
 }
 
 static int mlxbf_bootctl_store(int smc_op, const char *buf, size_t count)
@@ -274,14 +274,14 @@  static ssize_t lifecycle_state_show(struct device *dev,
 	 * due to using the test bits.
 	 */
 	if (test_state) {
-		return sprintf(buf, "%s(test)\n",
+		return sysfs_emit(buf, "%s(test)\n",
 			       mlxbf_bootctl_lifecycle_states[lc_state]);
 	} else if (use_dev_key &&
 		   (lc_state == MLXBF_BOOTCTL_SB_LIFECYCLE_GA_SECURE)) {
-		return sprintf(buf, "Secured (development)\n");
+		return sysfs_emit(buf, "Secured (development)\n");
 	}
 
-	return sprintf(buf, "%s\n", mlxbf_bootctl_lifecycle_states[lc_state]);
+	return sysfs_emit(buf, "%s\n", mlxbf_bootctl_lifecycle_states[lc_state]);
 }
 
 static ssize_t secure_boot_fuse_state_show(struct device *dev,
@@ -332,9 +332,9 @@  static ssize_t secure_boot_fuse_state_show(struct device *dev,
 			else
 				status = valid ? "Invalid" : "Free";
 		}
-		buf_len += sprintf(buf + buf_len, "%d:%s ", key, status);
+		buf_len += sysfs_emit(buf + buf_len, "%d:%s ", key, status);
 	}
-	buf_len += sprintf(buf + buf_len, "\n");
+	buf_len += sysfs_emit(buf + buf_len, "\n");
 
 	return buf_len;
 }