linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/dlm: use scnprintf() in lockspace show funcs
@ 2025-06-16 10:34 Pranav Tyagi
  2025-06-16 14:22 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Pranav Tyagi @ 2025-06-16 10:34 UTC (permalink / raw)
  To: aahringo, teigland
  Cc: skhan, gfs2, linux-kernel, linux-kernel-mentees, Pranav Tyagi

Replace all snprintf() instances with scnprintf(). snprintf() returns
the number of bytes that would have been written had there been enough
space. For sysfs attributes, snprintf() should not be used for the
show() method. Instead use scnprintf() which returns the number of
bytes actually written.

Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
---
 fs/dlm/config.c    | 2 +-
 fs/dlm/lockspace.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/dlm/config.c b/fs/dlm/config.c
index a23fd524a6ee..10486a46a540 100644
--- a/fs/dlm/config.c
+++ b/fs/dlm/config.c
@@ -185,7 +185,7 @@ static ssize_t cluster_##name##_store(struct config_item *item, \
 }                                                                             \
 static ssize_t cluster_##name##_show(struct config_item *item, char *buf)     \
 {                                                                             \
-	return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name);        \
+	return scnprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name);       \
 }                                                                             \
 CONFIGFS_ATTR(cluster_, name);
 
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 1929327ffbe1..2e83e381e54c 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -69,7 +69,7 @@ static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len)
 
 static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id);
+	return scnprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id);
 }
 
 static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
@@ -83,7 +83,7 @@ static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
 
 static ssize_t dlm_nodir_show(struct dlm_ls *ls, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%u\n", dlm_no_directory(ls));
+	return scnprintf(buf, PAGE_SIZE, "%u\n", dlm_no_directory(ls));
 }
 
 static ssize_t dlm_nodir_store(struct dlm_ls *ls, const char *buf, size_t len)
@@ -101,12 +101,12 @@ static ssize_t dlm_nodir_store(struct dlm_ls *ls, const char *buf, size_t len)
 static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf)
 {
 	uint32_t status = dlm_recover_status(ls);
-	return snprintf(buf, PAGE_SIZE, "%x\n", status);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", status);
 }
 
 static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid);
 }
 
 struct dlm_attr {
-- 
2.49.0


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

* Re: [PATCH] fs/dlm: use scnprintf() in lockspace show funcs
  2025-06-16 10:34 [PATCH] fs/dlm: use scnprintf() in lockspace show funcs Pranav Tyagi
@ 2025-06-16 14:22 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-06-16 14:22 UTC (permalink / raw)
  To: Pranav Tyagi
  Cc: aahringo, teigland, skhan, gfs2, linux-kernel,
	linux-kernel-mentees

On Mon, Jun 16, 2025 at 04:04:41PM +0530, Pranav Tyagi wrote:
> Replace all snprintf() instances with scnprintf(). snprintf() returns
> the number of bytes that would have been written had there been enough
> space. For sysfs attributes, snprintf() should not be used for the
> show() method. Instead use scnprintf() which returns the number of
> bytes actually written.
> 
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> ---
>  fs/dlm/config.c    | 2 +-
>  fs/dlm/lockspace.c | 8 ++++----
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/dlm/config.c b/fs/dlm/config.c
> index a23fd524a6ee..10486a46a540 100644
> --- a/fs/dlm/config.c
> +++ b/fs/dlm/config.c
> @@ -185,7 +185,7 @@ static ssize_t cluster_##name##_store(struct config_item *item, \
>  }                                                                             \
>  static ssize_t cluster_##name##_show(struct config_item *item, char *buf)     \
>  {                                                                             \
> -	return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name);        \
> +	return scnprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name);       \

sysfs_emit() or no change at all please.

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

end of thread, other threads:[~2025-06-16 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 10:34 [PATCH] fs/dlm: use scnprintf() in lockspace show funcs Pranav Tyagi
2025-06-16 14:22 ` Greg KH

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).