ASoC: Intel: fix possible acpi enumeration panic
Subsystems (3)
PATCH 1/1 ASoC: Intel: fix possible acpi enumeration panic
A crash can occur on some platforms where adsp is enumerated but codec is not matched. Check that the codec_id string is valid before attempting to match.
--- sound/soc/intel/sst/sst_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/intel/sst/sst_acpi.c +1 -1
@@ -236,7 +236,7 @@ static struct sst_machines *sst_acpi_find_machine(struct sst_machines *mach;bool found = false; -for (mach = machines; mach->codec_id; mach++) +for (mach = machines; mach->codec_id[0 ]; mach++)if (ACPI_SUCCESS (acpi_get_devices (mach->codec_id, sst_acpi_mach_match, &found,NULL )) && found)
Signature · 1 line
1.9.1
Mark Brown
maintainersound/soc/intel/sst/sst_acpi.c static struct sst_machines *sst_acpi_find_machine( · line 239
Quoted 6 lines · Kevin Strasser
A crash can occur on some platforms where adsp is enumerated but codec is not matched. Check that the
codec_idstring is valid before attempting to match.sound/soc/intel/sst/sst_acpi.c +1
-1-for (mach = machines; mach->codec_id; mach++) +for (mach = machines; mach->codec_id[0 ]; mach++)
This changes the check from verifying if a codec_id is present to verifying if the first character in the codec_id is non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.
Quoted 9 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Thursday, December 11, 2014 5:20 AM>Quoted 3 lines · Kevin Strasser
A crash can occur on some platforms where adsp is enumerated but codec is not matched. Check that the
codec_idstring is valid before attempting to match.
Quoted 8 lines
sound/soc/intel/sst/sst_acpi.c static struct sst_machines *sst_acpi_find_machine( · line 239
Quoted 2 lines
sound/soc/intel/sst/sst_acpi.c +1
-1-for (mach = machines; mach->codec_id; mach++) +for (mach = machines; mach->codec_id[0 ]; mach++)This changes the check from verifying if a
codec_idis present to verifying if the first character in thecodec_idis non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.
In this case mach->codec_id is non-NULL, even for the terminating element, because it is defined to be a fixed width. So we have to take a look at the first character to see if it has been initialized.
-Kevin
Mark Brown
maintainerOn Thu, Dec 11, 2014 at 09:55:38PM +0000, Strasser, Kevin wrote:
Please fix your mailer to word wrap comfortably under 80 colums so that your mails are easily legible.
Quoted 9 lines
Quoted 5 lines
This changes the check from verifying if a
codec_idis present to verifying if the first character in thecodec_idis non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.In this case
mach->codec_idis non-NULL, even for the terminating element, because it is defined to be a fixed width. So we have to take a look at the first character to see if it has been initialized.
That's a really unusual and (as you've seen) error prone idiom - is it not better to fix the struct to use the more common idiom?
Quoted 2 lines · Mark Brown
Please fix your mailer to word wrap comfortably under 80 colums so that your mails are easily legible.
Understood
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
This changes the check from verifying if a
codec_idis present to verifying if the first character in thecodec_idis non-NULL. That doesn't seem obviously safer and the tables of machines seem to be terminated by having an entry with all fields set to zero (which is a common idiom in Linux) which would now crash with this change.
Quoted 6 lines
Quoted 3 lines
In this case
mach->codec_idis non-NULL, even for the terminating element, because it is defined to be a fixed width. So we have to take a look at the first character to see if it has been initialized.That's a really unusual and (as you've seen) error prone idiom - is it not better to fix the struct to use the more common idiom?
That seems like a good idea to me. I'll prepare a new patch to change the sst_machines definition so that codec_id gets initialized to NULL.
-Kevin
PATCH v2 1/1 ASoC: Intel: fix possible acpi enumeration panic
In reply to Kevin StrasserA crash can occur on some platforms where adsp is enumerated but codec is not matched. Define codec_id as a pointer intead of an array so that it gets initialized to NULL for the terminating element of sst_acpi_bytcr[] and sst_acpi_chv[].
--- sound/soc/intel/sst/sst_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/intel/sst/sst_acpi.c +1 -1
@@ -43,7 +43,7 @@#include "sst.h" struct sst_machines { -char codec_id[32 ]; +char *codec_id;char board[32 ];char machine[32 ];void (*machine_quirk)(void );
Signature · 1 line
1.9.1
Quoted 4 lines · Kevin Strasser
A crash can occur on some platforms where adsp is enumerated but codec is not matched. Define
codec_idas a pointer intead of an array so that it gets initialized to NULL for the terminating element of sst_acpi_bytcr[] and sst_acpi_chv[].
Applied, thanks.