Skip to contentSkip to conversation

Minor fixes for CS35L41 HDA Property driver

PATCH In review Stefan Binding 2 participants 5 messages Dec 19, 2023 – Dec 21, 2023 Sound

lore
Share & tools
lore
#0 lore raw

cover Minor fixes for CS35L41 HDA Property driver

Minor issues were found in static analysis.
First fix ensures unitialised variables will never be freed. Second fix only compiles in the SPI workaround if SPI is enabled in the kernel.

Stefan Binding (2):
ALSA: hda: cs35l41: Do not allow uninitialised variables to be freed
ALSA: hda: cs35l41: Only add SPI CS GPIO if SPI is enabled in kernel

 sound/pci/hda/cs35l41_hda_property.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 ALSA: hda: cs35l41: Do not allow uninitialised variables to be freed

Initialise the variables to NULL so that they cannot be uninitialised when devm_kfree is called.

Found by static analysis.

Fixes 8c4c216db8fb ("ALSA: hda: cs35l41: Add config table to support many laptops without _DSD")
---
 sound/pci/hda/cs35l41_hda_property.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/pci/hda/cs35l41_hda_property.c +4 -4
index c9eb70290973..73b304e6c83c 100644
@@ -77,10 +77,10 @@ static const struct cs35l41_config cs35l41_config_table[] = {
 static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev, int reset_gpio,
 			     int spkid_gpio, int cs_gpio_index, int num_amps)
 {
-	struct acpi_gpio_mapping *gpio_mapping;
-	struct acpi_gpio_params *reset_gpio_params;
-	struct acpi_gpio_params *spkid_gpio_params;
-	struct acpi_gpio_params *cs_gpio_params;
+	struct acpi_gpio_mapping *gpio_mapping = NULL;
+	struct acpi_gpio_params *reset_gpio_params = NULL;
+	struct acpi_gpio_params *spkid_gpio_params = NULL;
+	struct acpi_gpio_params *cs_gpio_params = NULL;
 	unsigned int num_entries = 0;
 	unsigned int reset_index, spkid_index, csgpio_index;
 	int i;
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 ALSA: hda: cs35l41: Only add SPI CS GPIO if SPI is enabled in kernel

In reply to Stefan Binding

If CONFIG_SPI is not set in the kernel, there is no point in trying to set the chip selects. We can selectively compile it.

Fixes 8c4c216db8fb ("ALSA: hda: cs35l41: Add config table to support many laptops without _DSD")
---
 sound/pci/hda/cs35l41_hda_property.c | 3 +++
 1 file changed, 3 insertions(+)
sound/pci/hda/cs35l41_hda_property.c +3 -0
index 73b304e6c83c..194e1179a253 100644
@@ -210,6 +210,8 @@ static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physde
 
 	if (cfg->bus == SPI) {
 		cs35l41->index = id;
+
+#if IS_ENABLED(CONFIG_SPI)
 		/*
 		 * Manually set the Chip Select for the second amp <cs_gpio_index> in the node.
 		 * This is only supported for systems with 2 amps, since we cannot expand the
@@ -249,6 +251,7 @@ static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physde
 				spi_setup(spi);
 			}
 		}
+#endif
 	} else {
 		if (cfg->num_amps > 2)
 			/*
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v1 2/2] ALSA: hda: cs35l41: Only add SPI CS GPIO if SPI is enabled in kernel

Quoted 3 lines · Stefan Binding

If CONFIG_SPI is not set in the kernel, there is no point in trying to set the chip selects. We can selectively compile it.

I guess it should with IS_REACHABLE() instead of IS_ENABLED()? It can be still CONFIG_SPI=m while CONFIG_SND_HDA_*=y.

thanks,

Takashi

Quoted 34 lines
Fixes 8c4c216db8fb ("ALSA: hda: cs35l41: Add config table to support many laptops without _DSD")
---
 sound/pci/hda/cs35l41_hda_property.c | 3 +++
 1 file changed, 3 insertions(+)
sound/pci/hda/cs35l41_hda_property.c +3 -0
index 73b304e6c83c..194e1179a253 100644
@@ -210,6 +210,8 @@ static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physde
 
 	if (cfg->bus == SPI) {
 		cs35l41->index = id;
+
+#if IS_ENABLED(CONFIG_SPI)
 		/*
 		 * Manually set the Chip Select for the second amp <cs_gpio_index> in the node.
 		 * This is only supported for systems with 2 amps, since we cannot expand the
@@ -249,6 +251,7 @@ static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physde
 				spi_setup(spi);
 			}
 		}
+#endif
 	} else {
 		if (cfg->num_amps > 2)
 			/*
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v1 2/2] ALSA: hda: cs35l41: Only add SPI CS GPIO if SPI is enabled in kernel

Quoted 9 lines · Takashi Iwai
Quoted 3 lines · Stefan Binding

If CONFIG_SPI is not set in the kernel, there is no point in trying to set the chip selects. We can selectively compile it.

I guess it should with IS_REACHABLE() instead of IS_ENABLED()? It can be still CONFIG_SPI=m while CONFIG_SND_HDA_*=y.

In anyway, I applied the patches as is for now, as it should work in most cases. Let's see whether the use of IS_REACHABLE() is required.

thanks,

Takashi