Skip to contentSkip to conversation

fs/ecryptfs: use scnprintf() in version show

PATCH In review Pranav Tyagi 2 participants 2 messages Jun 16, 2025 Ecrypt file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ecryptfs: use scnprintf() in version show

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.

---
 fs/ecryptfs/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ecryptfs/main.c +1 -1
index 8dd1d7189c3b..2a97c2b1fc69 100644
@@ -764,7 +764,7 @@ static struct kobject *ecryptfs_kobj;
 static ssize_t version_show(struct kobject *kobj,
 			    struct kobj_attribute *attr, char *buff)
 {
-	return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
+	return scnprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
 }
 
 static struct kobj_attribute version_attr = __ATTR_RO(version);
Signature · 1 line
2.49.0
#1 lore raw
Quoted 16 lines · 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.

---
 fs/ecryptfs/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ecryptfs/main.c +0 -0
index 8dd1d7189c3b..2a97c2b1fc69 100644

fs/ecryptfs/main.c static struct kobject *ecryptfs_kobj; · line 767

Quoted 5 lines
fs/ecryptfs/main.c +1 -1
@@ -764,7 +764,7 @@ static struct kobject *ecryptfs_kobj;
 static ssize_t version_show(struct kobject *kobj,
 			    struct kobj_attribute *attr, char *buff)
 {
-	return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
+	return scnprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);

sysfs_emit() or no change at all please.