* [PATCH] firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create()
@ 2023-10-29 7:52 Christophe JAILLET
2023-10-30 8:00 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2023-10-29 7:52 UTC (permalink / raw)
To: Nishanth Menon, Tero Kristo, Santosh Shilimkar
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, Tero Kristo,
linux-arm-kernel
The ending NULL is not taken into account by strncat(), so switch to
strlcat() to correctly compute the size of the available memory when
building 'debug_name'.
Because of the difference in the return type between strncat() and
strlcat(), some code shuffling is needed.
Fixes: aa276781a64a ("firmware: Add basic support for TI System Control Interface (TI-SCI) protocol")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/firmware/ti_sci.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 7041befc756a..1036c6b0f3eb 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -181,10 +181,9 @@ static int ti_sci_debugfs_create(struct platform_device *pdev,
/* Setup NULL termination */
info->debug_buffer[info->debug_region_size] = 0;
- info->d = debugfs_create_file(strncat(debug_name, dev_name(dev),
- sizeof(debug_name) -
- sizeof("ti_sci_debug@")),
- 0444, NULL, info, &ti_sci_debug_fops);
+ strlcat(debug_name, dev_name(dev), sizeof(debug_name));
+ info->d = debugfs_create_file(debug_name, 0444, NULL, info,
+ &ti_sci_debug_fops);
if (IS_ERR(info->d))
return PTR_ERR(info->d);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create()
2023-10-29 7:52 [PATCH] firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create() Christophe JAILLET
@ 2023-10-30 8:00 ` Dan Carpenter
2023-10-30 8:02 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2023-10-30 8:00 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Nishanth Menon, Tero Kristo, Santosh Shilimkar, linux-kernel,
kernel-janitors, Tero Kristo, linux-arm-kernel
On Sun, Oct 29, 2023 at 08:52:36AM +0100, Christophe JAILLET wrote:
> The ending NULL is not taken into account by strncat(), so switch to
> strlcat() to correctly compute the size of the available memory when
> building 'debug_name'.
>
> Because of the difference in the return type between strncat() and
> strlcat(), some code shuffling is needed.
>
> Fixes: aa276781a64a ("firmware: Add basic support for TI System Control Interface (TI-SCI) protocol")
The fixes tag isn't really required.
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/firmware/ti_sci.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
> index 7041befc756a..1036c6b0f3eb 100644
> --- a/drivers/firmware/ti_sci.c
> +++ b/drivers/firmware/ti_sci.c
> @@ -181,10 +181,9 @@ static int ti_sci_debugfs_create(struct platform_device *pdev,
> /* Setup NULL termination */
> info->debug_buffer[info->debug_region_size] = 0;
>
> - info->d = debugfs_create_file(strncat(debug_name, dev_name(dev),
> - sizeof(debug_name) -
> - sizeof("ti_sci_debug@")),
> - 0444, NULL, info, &ti_sci_debug_fops);
> + strlcat(debug_name, dev_name(dev), sizeof(debug_name));
Eventually we are going to want to get rid for the strlcat() as well,
right? Everyone hates strl* functions because they do a strlen() on
the src string. It's fine if the src string is a string constant, I
suppose. Here we basically trust dev_name() to be reasonable so either
strncat and strlcpy() are fine I guess...
But it's is more readable if the we use snprintf().
snprintf(debug_name, sizeof(debug_name),
"ti_sci_debug@%s", dev_name(dev));
regards,
dan carpenter
> + info->d = debugfs_create_file(debug_name, 0444, NULL, info,
> + &ti_sci_debug_fops);
> if (IS_ERR(info->d))
> return PTR_ERR(info->d);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create()
2023-10-30 8:00 ` Dan Carpenter
@ 2023-10-30 8:02 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2023-10-30 8:02 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Nishanth Menon, Tero Kristo, Santosh Shilimkar, linux-kernel,
kernel-janitors, Tero Kristo, linux-arm-kernel
On Mon, Oct 30, 2023 at 11:00:59AM +0300, Dan Carpenter wrote:
> On Sun, Oct 29, 2023 at 08:52:36AM +0100, Christophe JAILLET wrote:
> > The ending NULL is not taken into account by strncat(), so switch to
> > strlcat() to correctly compute the size of the available memory when
> > building 'debug_name'.
> >
> > Because of the difference in the return type between strncat() and
> > strlcat(), some code shuffling is needed.
> >
> > Fixes: aa276781a64a ("firmware: Add basic support for TI System Control Interface (TI-SCI) protocol")
>
> The fixes tag isn't really required.
Ah sorry. It's an off by one. Yeah, that's a bug even if it doesn't
affect runtime. I don't know why I didn't read this commit message
better...
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-30 8:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-29 7:52 [PATCH] firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create() Christophe JAILLET
2023-10-30 8:00 ` Dan Carpenter
2023-10-30 8:02 ` Dan Carpenter
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).