diff mbox series

[v4,1/3] efi/cper: Adjust infopfx size to accept an extra space

Message ID a8cfcd9e9827770de748db7be44362a98c957642.1718906288.git.mchehab+huawei@kernel.org (mailing list archive)
State New
Headers show
Series Fix CPER issues related to UEFI 2.9A Errata | expand

Commit Message

Mauro Carvalho Chehab June 20, 2024, 6:01 p.m. UTC
Compiling with W=1 with werror enabled produces an error:

drivers/firmware/efi/cper-arm.c: In function ‘cper_print_proc_arm’:
drivers/firmware/efi/cper-arm.c:298:64: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  298 |                         snprintf(infopfx, sizeof(infopfx), "%s ", newpfx);
      |                                                                ^
drivers/firmware/efi/cper-arm.c:298:25: note: ‘snprintf’ output between 2 and 65 bytes into a destination of size 64
  298 |                         snprintf(infopfx, sizeof(infopfx), "%s ", newpfx);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As the logic there adds an space at the end of infopx buffer.
Add an extra space to avoid such warning.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/firmware/efi/cper-arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jonathan Cameron June 21, 2024, 9:04 a.m. UTC | #1
On Thu, 20 Jun 2024 20:01:44 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> Compiling with W=1 with werror enabled produces an error:
> 
> drivers/firmware/efi/cper-arm.c: In function ‘cper_print_proc_arm’:
> drivers/firmware/efi/cper-arm.c:298:64: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
>   298 |                         snprintf(infopfx, sizeof(infopfx), "%s ", newpfx);
>       |                                                                ^
> drivers/firmware/efi/cper-arm.c:298:25: note: ‘snprintf’ output between 2 and 65 bytes into a destination of size 64
>   298 |                         snprintf(infopfx, sizeof(infopfx), "%s ", newpfx);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> As the logic there adds an space at the end of infopx buffer.
> Add an extra space to avoid such warning.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Trivial suggestion inline. Either way LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/firmware/efi/cper-arm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/efi/cper-arm.c b/drivers/firmware/efi/cper-arm.c
> index fa9c1c3bf168..d9bbcea0adf4 100644
> --- a/drivers/firmware/efi/cper-arm.c
> +++ b/drivers/firmware/efi/cper-arm.c
> @@ -240,7 +240,7 @@ void cper_print_proc_arm(const char *pfx,
>  	int i, len, max_ctx_type;
>  	struct cper_arm_err_info *err_info;
>  	struct cper_arm_ctx_info *ctx_info;
> -	char newpfx[64], infopfx[64];
> +	char newpfx[64], infopfx[65];

Maybe make it explicit so we don't wonder if it was
a typo in future. Something like?

	char newpfx[64];
	char infofx[ARRAY_SIZE(newpfx) + 1];

>  
>  	printk("%sMIDR: 0x%016llx\n", pfx, proc->midr);
>
diff mbox series

Patch

diff --git a/drivers/firmware/efi/cper-arm.c b/drivers/firmware/efi/cper-arm.c
index fa9c1c3bf168..d9bbcea0adf4 100644
--- a/drivers/firmware/efi/cper-arm.c
+++ b/drivers/firmware/efi/cper-arm.c
@@ -240,7 +240,7 @@  void cper_print_proc_arm(const char *pfx,
 	int i, len, max_ctx_type;
 	struct cper_arm_err_info *err_info;
 	struct cper_arm_ctx_info *ctx_info;
-	char newpfx[64], infopfx[64];
+	char newpfx[64], infopfx[65];
 
 	printk("%sMIDR: 0x%016llx\n", pfx, proc->midr);