* [PATCH] staging: greybus: arche: use sysfs_emit() instead of sprintf()
@ 2026-02-25 21:29 Ruslan Valiyev
2026-02-26 7:18 ` Dan Carpenter
2026-02-26 7:48 ` [PATCH v2] " Ruslan Valiyev
0 siblings, 2 replies; 4+ messages in thread
From: Ruslan Valiyev @ 2026-02-25 21:29 UTC (permalink / raw)
To: Vaibhav Hiremath, Johan Hovold, Alex Elder, Greg Kroah-Hartman
Cc: greybus-dev, linux-staging, linux-kernel, Ruslan Valiyev
Replace sprintf() with sysfs_emit() in state_show() sysfs attribute
callbacks in arche-platform.c and arche-apb-ctrl.c.
sysfs_emit() is preferred over sprintf() in sysfs show functions
because it is aware of the PAGE_SIZE buffer limit, preventing
potential buffer overflows. This addresses checkpatch warnings
about the use of sprintf() in sysfs show callbacks.
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
---
drivers/staging/greybus/arche-apb-ctrl.c | 10 +++++-----
drivers/staging/greybus/arche-platform.c | 10 +++++-----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/greybus/arche-apb-ctrl.c b/drivers/staging/greybus/arche-apb-ctrl.c
index 33f26a65f..19a6e59b6 100644
--- a/drivers/staging/greybus/arche-apb-ctrl.c
+++ b/drivers/staging/greybus/arche-apb-ctrl.c
@@ -300,16 +300,16 @@ static ssize_t state_show(struct device *dev,
switch (apb->state) {
case ARCHE_PLATFORM_STATE_OFF:
- return sprintf(buf, "off%s\n",
+ return sysfs_emit(buf, "off%s\n",
apb->init_disabled ? ",disabled" : "");
case ARCHE_PLATFORM_STATE_ACTIVE:
- return sprintf(buf, "active\n");
+ return sysfs_emit(buf, "active\n");
case ARCHE_PLATFORM_STATE_STANDBY:
- return sprintf(buf, "standby\n");
+ return sysfs_emit(buf, "standby\n");
case ARCHE_PLATFORM_STATE_FW_FLASHING:
- return sprintf(buf, "fw_flashing\n");
+ return sysfs_emit(buf, "fw_flashing\n");
default:
- return sprintf(buf, "unknown state\n");
+ return sysfs_emit(buf, "unknown state\n");
}
}
diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c
index f669a7e2e..de5de59ea 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -374,15 +374,15 @@ static ssize_t state_show(struct device *dev,
switch (arche_pdata->state) {
case ARCHE_PLATFORM_STATE_OFF:
- return sprintf(buf, "off\n");
+ return sysfs_emit(buf, "off\n");
case ARCHE_PLATFORM_STATE_ACTIVE:
- return sprintf(buf, "active\n");
+ return sysfs_emit(buf, "active\n");
case ARCHE_PLATFORM_STATE_STANDBY:
- return sprintf(buf, "standby\n");
+ return sysfs_emit(buf, "standby\n");
case ARCHE_PLATFORM_STATE_FW_FLASHING:
- return sprintf(buf, "fw_flashing\n");
+ return sysfs_emit(buf, "fw_flashing\n");
default:
- return sprintf(buf, "unknown state\n");
+ return sysfs_emit(buf, "unknown state\n");
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: greybus: arche: use sysfs_emit() instead of sprintf()
2026-02-25 21:29 [PATCH] staging: greybus: arche: use sysfs_emit() instead of sprintf() Ruslan Valiyev
@ 2026-02-26 7:18 ` Dan Carpenter
2026-02-26 7:48 ` [PATCH v2] " Ruslan Valiyev
1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-02-26 7:18 UTC (permalink / raw)
To: Ruslan Valiyev
Cc: Vaibhav Hiremath, Johan Hovold, Alex Elder, Greg Kroah-Hartman,
greybus-dev, linux-staging, linux-kernel
On Wed, Feb 25, 2026 at 09:29:55PM +0000, Ruslan Valiyev wrote:
> Replace sprintf() with sysfs_emit() in state_show() sysfs attribute
> callbacks in arche-platform.c and arche-apb-ctrl.c.
>
> sysfs_emit() is preferred over sprintf() in sysfs show functions
> because it is aware of the PAGE_SIZE buffer limit, preventing
> potential buffer overflows. This addresses checkpatch warnings
> about the use of sprintf() in sysfs show callbacks.
>
> Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
> ---
I really want these sorts of patches to have some kind of analysis
whether the "potential buffer overflows" are actual buffer overflows or
not. In this case, it's really easy to see that there are no buffer
overflows so it feels petty for something I can see just by glancing
at the patch... I just got finished asking for the same thing from
someone else, but in that case I had to look up the buffer size.
Anyway, just add a sentence at the start which says that "This code is
obviously safe". And remove the bits which mention "potential buffer
overflows".
Checkpatch complains about code using sprintf(). This code here is
obviously safe as-is, but it would be more appropriate to use
sysfs_emit().
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] staging: greybus: arche: use sysfs_emit() instead of sprintf()
2026-02-25 21:29 [PATCH] staging: greybus: arche: use sysfs_emit() instead of sprintf() Ruslan Valiyev
2026-02-26 7:18 ` Dan Carpenter
@ 2026-02-26 7:48 ` Ruslan Valiyev
2026-02-26 8:00 ` Dan Carpenter
1 sibling, 1 reply; 4+ messages in thread
From: Ruslan Valiyev @ 2026-02-26 7:48 UTC (permalink / raw)
To: Vaibhav Hiremath, Johan Hovold, Alex Elder, Greg Kroah-Hartman
Cc: Dan Carpenter, greybus-dev, linux-staging, linux-kernel,
Ruslan Valiyev
Replace sprintf() with sysfs_emit() in state_show() sysfs attribute
callbacks in arche-platform.c and arche-apb-ctrl.c.
Checkpatch complains about code using sprintf(). This code here is
obviously safe as-is, but it would be more appropriate to use
sysfs_emit().
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
---
drivers/staging/greybus/arche-apb-ctrl.c | 10 +++++-----
drivers/staging/greybus/arche-platform.c | 10 +++++-----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/greybus/arche-apb-ctrl.c b/drivers/staging/greybus/arche-apb-ctrl.c
index 33f26a65f..19a6e59b6 100644
--- a/drivers/staging/greybus/arche-apb-ctrl.c
+++ b/drivers/staging/greybus/arche-apb-ctrl.c
@@ -300,16 +300,16 @@ static ssize_t state_show(struct device *dev,
switch (apb->state) {
case ARCHE_PLATFORM_STATE_OFF:
- return sprintf(buf, "off%s\n",
+ return sysfs_emit(buf, "off%s\n",
apb->init_disabled ? ",disabled" : "");
case ARCHE_PLATFORM_STATE_ACTIVE:
- return sprintf(buf, "active\n");
+ return sysfs_emit(buf, "active\n");
case ARCHE_PLATFORM_STATE_STANDBY:
- return sprintf(buf, "standby\n");
+ return sysfs_emit(buf, "standby\n");
case ARCHE_PLATFORM_STATE_FW_FLASHING:
- return sprintf(buf, "fw_flashing\n");
+ return sysfs_emit(buf, "fw_flashing\n");
default:
- return sprintf(buf, "unknown state\n");
+ return sysfs_emit(buf, "unknown state\n");
}
}
diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c
index f669a7e2e..de5de59ea 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -374,15 +374,15 @@ static ssize_t state_show(struct device *dev,
switch (arche_pdata->state) {
case ARCHE_PLATFORM_STATE_OFF:
- return sprintf(buf, "off\n");
+ return sysfs_emit(buf, "off\n");
case ARCHE_PLATFORM_STATE_ACTIVE:
- return sprintf(buf, "active\n");
+ return sysfs_emit(buf, "active\n");
case ARCHE_PLATFORM_STATE_STANDBY:
- return sprintf(buf, "standby\n");
+ return sysfs_emit(buf, "standby\n");
case ARCHE_PLATFORM_STATE_FW_FLASHING:
- return sprintf(buf, "fw_flashing\n");
+ return sysfs_emit(buf, "fw_flashing\n");
default:
- return sprintf(buf, "unknown state\n");
+ return sysfs_emit(buf, "unknown state\n");
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: greybus: arche: use sysfs_emit() instead of sprintf()
2026-02-26 7:48 ` [PATCH v2] " Ruslan Valiyev
@ 2026-02-26 8:00 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-02-26 8:00 UTC (permalink / raw)
To: Ruslan Valiyev
Cc: Vaibhav Hiremath, Johan Hovold, Alex Elder, Greg Kroah-Hartman,
greybus-dev, linux-staging, linux-kernel
On Thu, Feb 26, 2026 at 07:48:58AM +0000, Ruslan Valiyev wrote:
> Replace sprintf() with sysfs_emit() in state_show() sysfs attribute
> callbacks in arche-platform.c and arche-apb-ctrl.c.
>
> Checkpatch complains about code using sprintf(). This code here is
> obviously safe as-is, but it would be more appropriate to use
> sysfs_emit().
>
> Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
> ---
Thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-26 8:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 21:29 [PATCH] staging: greybus: arche: use sysfs_emit() instead of sprintf() Ruslan Valiyev
2026-02-26 7:18 ` Dan Carpenter
2026-02-26 7:48 ` [PATCH v2] " Ruslan Valiyev
2026-02-26 8:00 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox