diff mbox series

[2/2] x86: acpi: Add memset to initialize SPCR table

Message ID 20200909123322.1684889-2-wolfgang.wallner@br-automation.com
State Superseded
Delegated to: Bin Meng
Headers show
Series [1/2] x86: acpi: Fix calculation of DSDT length | expand

Commit Message

Wolfgang Wallner Sept. 9, 2020, 12:33 p.m. UTC
Add a missing memset to acpi_create_spcr().

The other acpi_create_xxxx() functions perform a memset on their
structures, acpi_create_spcr() does not and as a result the contents of
this table are partly uninitialized (and thus random after every reset).

Signed-off-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
---

 arch/x86/lib/acpi_table.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andy Shevchenko Sept. 9, 2020, 1:09 p.m. UTC | #1
On Wed, Sep 09, 2020 at 02:33:21PM +0200, Wolfgang Wallner wrote:
> Add a missing memset to acpi_create_spcr().
> 
> The other acpi_create_xxxx() functions perform a memset on their
> structures, acpi_create_spcr() does not and as a result the contents of
> this table are partly uninitialized (and thus random after every reset).

Fixes: tag?
In any case, after addressing below,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
> ---
> 
>  arch/x86/lib/acpi_table.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
> index 6b827bfa3f..054235843e 100644
> --- a/arch/x86/lib/acpi_table.c
> +++ b/arch/x86/lib/acpi_table.c
> @@ -252,6 +252,8 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
>  	int space_id;
>  	int ret = -ENODEV;
>  
> +	memset((void *)spcr, 0, sizeof(struct acpi_spcr));
> +
>  	/* Fill out header fields */
>  	acpi_fill_header(header, "SPCR");
>  	header->length = sizeof(struct acpi_spcr);

> @@ -359,6 +361,7 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
>  		spcr->baud_rate = 0;
>  
>  	/* Fix checksum */
> +
>  	header->checksum = table_compute_checksum((void *)spcr, header->length);
>  }

Unrelated change.
Simon Glass Sept. 9, 2020, 2:35 p.m. UTC | #2
On Wed, 9 Sep 2020 at 06:33, Wolfgang Wallner
<wolfgang.wallner@br-automation.com> wrote:
>
> Add a missing memset to acpi_create_spcr().
>
> The other acpi_create_xxxx() functions perform a memset on their
> structures, acpi_create_spcr() does not and as a result the contents of
> this table are partly uninitialized (and thus random after every reset).
>
> Signed-off-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
> ---
>
>  arch/x86/lib/acpi_table.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

For further thought, I do wonder if acpi_fill_header() should do the
memset, if sizeof() could be passed as a parameter?
diff mbox series

Patch

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 6b827bfa3f..054235843e 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -252,6 +252,8 @@  static void acpi_create_spcr(struct acpi_spcr *spcr)
 	int space_id;
 	int ret = -ENODEV;
 
+	memset((void *)spcr, 0, sizeof(struct acpi_spcr));
+
 	/* Fill out header fields */
 	acpi_fill_header(header, "SPCR");
 	header->length = sizeof(struct acpi_spcr);
@@ -359,6 +361,7 @@  static void acpi_create_spcr(struct acpi_spcr *spcr)
 		spcr->baud_rate = 0;
 
 	/* Fix checksum */
+
 	header->checksum = table_compute_checksum((void *)spcr, header->length);
 }