diff mbox series

[v2,2/4] soc: renesas: rz-sysc: Fix SoC ID string extraction

Message ID 20250101163344.128139-3-john.madieu.xa@bp.renesas.com (mailing list archive)
State Under Review
Delegated to: Geert Uytterhoeven
Headers show
Series soc: renesas: Add system controller support for RZ/G3E SoC | expand

Commit Message

John Madieu Jan. 1, 2025, 4:33 p.m. UTC
Fix string length calculation when extracting the SoC ID from the compatible
string. Add +1 to the size calculation to ensure proper string termination when
copying with strncpy().

This prevents potential string trunctation when processing the device tree
compatible string to identify the SoC.

Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com>
---
New patch introduced in v2, targetting specific fix.

 drivers/soc/renesas/rz-sysc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Geert Uytterhoeven Jan. 2, 2025, 8:14 p.m. UTC | #1
Hi John,

On Wed, Jan 1, 2025 at 5:34 PM John Madieu
<john.madieu.xa@bp.renesas.com> wrote:
> Fix string length calculation when extracting the SoC ID from the compatible
> string. Add +1 to the size calculation to ensure proper string termination when
> copying with strncpy().
>
> This prevents potential string trunctation when processing the device tree
> compatible string to identify the SoC.
>
> Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com>
> ---
> New patch introduced in v2, targetting specific fix.

Thanks for your patch!

> --- a/drivers/soc/renesas/rz-sysc.c
> +++ b/drivers/soc/renesas/rz-sysc.c
> @@ -231,7 +231,7 @@ static int rz_sysc_soc_init(struct rz_sysc *sysc, const struct of_device_id *mat
>
>         soc_id_start = strchr(match->compatible, ',') + 1;
>         soc_id_end = strchr(match->compatible, '-');
> -       size = soc_id_end - soc_id_start;
> +       size = soc_id_end - soc_id_start + 1;
>         if (size > 32)
>                 size = 32;
>         strscpy(soc_id, soc_id_start, size);

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

As the code fixed was introduced by a patch[1] that has not been
accepted yet, this fix should be incorporated into the original patch
(together with other fixes according to review comments).

[1] "[PATCH v2 04/15] soc: renesas: rz-sysc: Add SoC detection support"
https://lore.kernel.org/linux-renesas-soc/20241126092050.1825607-5-claudiu.beznea.uj@bp.renesas.com

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

diff --git a/drivers/soc/renesas/rz-sysc.c b/drivers/soc/renesas/rz-sysc.c
index d34d295831b8..e472fda3995b 100644
--- a/drivers/soc/renesas/rz-sysc.c
+++ b/drivers/soc/renesas/rz-sysc.c
@@ -231,7 +231,7 @@  static int rz_sysc_soc_init(struct rz_sysc *sysc, const struct of_device_id *mat
 
 	soc_id_start = strchr(match->compatible, ',') + 1;
 	soc_id_end = strchr(match->compatible, '-');
-	size = soc_id_end - soc_id_start;
+	size = soc_id_end - soc_id_start + 1;
 	if (size > 32)
 		size = 32;
 	strscpy(soc_id, soc_id_start, size);