* [PATCH] fs/ocfs2: use scnprintf() in show functions
@ 2025-06-16 10:50 Pranav Tyagi
2025-06-16 14:21 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Pranav Tyagi @ 2025-06-16 10:50 UTC (permalink / raw)
To: mark, jlbec, joseph.qi
Cc: skhan, ocfs2-devel, 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/ocfs2/cluster/masklog.c | 2 +-
fs/ocfs2/cluster/sys.c | 2 +-
fs/ocfs2/stackglue.c | 14 +++++++-------
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index 563881ddbf00..0bc21dc71d29 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -28,7 +28,7 @@ static ssize_t mlog_mask_show(u64 mask, char *buf)
else
state = "off";
- return snprintf(buf, PAGE_SIZE, "%s\n", state);
+ return scnprintf(buf, PAGE_SIZE, "%s\n", state);
}
static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c
index 022f716c74ff..23febbe3dc5d 100644
--- a/fs/ocfs2/cluster/sys.c
+++ b/fs/ocfs2/cluster/sys.c
@@ -21,7 +21,7 @@
static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
+ return scnprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
}
static struct kobj_attribute attr_version =
__ATTR(interface_revision, S_IRUGO, version_show, NULL);
diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c
index a28c127b9934..9af03869a04b 100644
--- a/fs/ocfs2/stackglue.c
+++ b/fs/ocfs2/stackglue.c
@@ -477,9 +477,9 @@ static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj,
spin_lock(&ocfs2_stack_lock);
if (locking_max_version.pv_major)
- ret = snprintf(buf, PAGE_SIZE, "%u.%u\n",
- locking_max_version.pv_major,
- locking_max_version.pv_minor);
+ ret = scnprintf(buf, PAGE_SIZE, "%u.%u\n",
+ locking_max_version.pv_major,
+ locking_max_version.pv_minor);
spin_unlock(&ocfs2_stack_lock);
return ret;
@@ -525,8 +525,8 @@ static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj,
spin_lock(&ocfs2_stack_lock);
if (active_stack) {
- ret = snprintf(buf, PAGE_SIZE, "%s\n",
- active_stack->sp_name);
+ ret = scnprintf(buf, PAGE_SIZE, "%s\n",
+ active_stack->sp_name);
if (ret >= PAGE_SIZE)
ret = -E2BIG;
}
@@ -545,7 +545,7 @@ static ssize_t ocfs2_cluster_stack_show(struct kobject *kobj,
{
ssize_t ret;
spin_lock(&ocfs2_stack_lock);
- ret = snprintf(buf, PAGE_SIZE, "%s\n", cluster_stack_name);
+ ret = scnprintf(buf, PAGE_SIZE, "%s\n", cluster_stack_name);
spin_unlock(&ocfs2_stack_lock);
return ret;
@@ -595,7 +595,7 @@ static ssize_t ocfs2_dlm_recover_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "1\n");
+ return scnprintf(buf, PAGE_SIZE, "1\n");
}
static struct kobj_attribute ocfs2_attr_dlm_recover_support =
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fs/ocfs2: use scnprintf() in show functions
2025-06-16 10:50 [PATCH] fs/ocfs2: use scnprintf() in show functions Pranav Tyagi
@ 2025-06-16 14:21 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-06-16 14:21 UTC (permalink / raw)
To: Pranav Tyagi
Cc: mark, jlbec, joseph.qi, skhan, ocfs2-devel, linux-kernel,
linux-kernel-mentees
On Mon, Jun 16, 2025 at 04:20:28PM +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/ocfs2/cluster/masklog.c | 2 +-
> fs/ocfs2/cluster/sys.c | 2 +-
> fs/ocfs2/stackglue.c | 14 +++++++-------
> 3 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
> index 563881ddbf00..0bc21dc71d29 100644
> --- a/fs/ocfs2/cluster/masklog.c
> +++ b/fs/ocfs2/cluster/masklog.c
> @@ -28,7 +28,7 @@ static ssize_t mlog_mask_show(u64 mask, char *buf)
> else
> state = "off";
>
> - return snprintf(buf, PAGE_SIZE, "%s\n", state);
> + return scnprintf(buf, PAGE_SIZE, "%s\n", state);
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:21 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:50 [PATCH] fs/ocfs2: use scnprintf() in show functions Pranav Tyagi
2025-06-16 14:21 ` 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).