public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/6] params: Use sysfs_emit() to instead of scnprintf()
@ 2023-09-12 15:05 Andy Shevchenko
  2023-09-12 15:05 ` [PATCH v1 2/6] params: Introduce the param_unknown_fn type Andy Shevchenko
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Andy Shevchenko @ 2023-09-12 15:05 UTC (permalink / raw)
  To: Andy Shevchenko, linux-kernel; +Cc: Luis Chamberlain

Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/params.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/kernel/params.c b/kernel/params.c
index 2d4a0564697e..3efe6b98a600 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -222,8 +222,7 @@ char *parse_args(const char *doing,
 	}								\
 	int param_get_##name(char *buffer, const struct kernel_param *kp) \
 	{								\
-		return scnprintf(buffer, PAGE_SIZE, format "\n",	\
-				*((type *)kp->arg));			\
+		return sysfs_emit(buffer, format "\n", *((type *)kp->arg));	\
 	}								\
 	const struct kernel_param_ops param_ops_##name = {			\
 		.set = param_set_##name,				\
@@ -287,7 +286,7 @@ EXPORT_SYMBOL(param_set_charp);
 
 int param_get_charp(char *buffer, const struct kernel_param *kp)
 {
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", *((char **)kp->arg));
+	return sysfs_emit(buffer, "%s\n", *((char **)kp->arg));
 }
 EXPORT_SYMBOL(param_get_charp);
 
@@ -318,7 +317,7 @@ EXPORT_SYMBOL(param_set_bool);
 int param_get_bool(char *buffer, const struct kernel_param *kp)
 {
 	/* Y and N chosen as being relatively non-coder friendly */
-	return sprintf(buffer, "%c\n", *(bool *)kp->arg ? 'Y' : 'N');
+	return sysfs_emit(buffer, "%c\n", *(bool *)kp->arg ? 'Y' : 'N');
 }
 EXPORT_SYMBOL(param_get_bool);
 
@@ -377,7 +376,7 @@ EXPORT_SYMBOL(param_set_invbool);
 
 int param_get_invbool(char *buffer, const struct kernel_param *kp)
 {
-	return sprintf(buffer, "%c\n", (*(bool *)kp->arg) ? 'N' : 'Y');
+	return sysfs_emit(buffer, "%c\n", (*(bool *)kp->arg) ? 'N' : 'Y');
 }
 EXPORT_SYMBOL(param_get_invbool);
 
@@ -525,7 +524,8 @@ EXPORT_SYMBOL(param_set_copystring);
 int param_get_string(char *buffer, const struct kernel_param *kp)
 {
 	const struct kparam_string *kps = kp->str;
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", kps->string);
+
+	return sysfs_emit(buffer, "%s\n", kps->string);
 }
 EXPORT_SYMBOL(param_get_string);
 
@@ -859,7 +859,7 @@ ssize_t __modver_version_show(struct module_attribute *mattr,
 	struct module_version_attribute *vattr =
 		container_of(mattr, struct module_version_attribute, mattr);
 
-	return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
+	return sysfs_emit(buf, "%s\n", vattr->version);
 }
 
 extern const struct module_version_attribute __start___modver[];
-- 
2.40.0.1.gaa8946217a0b


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

end of thread, other threads:[~2023-09-21 20:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12 15:05 [PATCH v1 1/6] params: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 2/6] params: Introduce the param_unknown_fn type Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 3/6] params: Do not go over the limit when getting the string length Andy Shevchenko
2023-09-12 15:24   ` Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 4/6] params: Use size_add() for kmalloc() Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 5/6] params: Sort headers Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 6/6] params: Fix multi-line comment style Andy Shevchenko
2023-09-18 16:57 ` [PATCH v1 1/6] params: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-09-21  0:32   ` Luis Chamberlain
2023-09-21  9:36     ` Andy Shevchenko
2023-09-21 13:34 ` kernel test robot
2023-09-21 15:36   ` Andy Shevchenko
2023-09-21 16:18     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox