Skip to contentSkip to conversation

Fixes and cleanup for CS35L41 HDA

PATCH In review Stefan Binding 2 participants 5 messages Jun 6, 2023 Sound

lore
Share & tools
lore
#1 lore raw

PATCH v3 1/3 ALSA: hda: cs35l41: Clean up Firmware Load Controls

In reply to Stefan Binding

Ensure Firmware Load control and Firmware Type control returns 1 when the value changes.

Remove fw_mutex from firmware load control put, since it is unnecessary, and prevents any possibility of mutex inversion.

---
 sound/pci/hda/cs35l41_hda.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
sound/pci/hda/cs35l41_hda.c +10 -14
index b5210abb5141f..d100189e15b83 100644
@@ -835,34 +835,26 @@ static int cs35l41_fw_load_ctl_put(struct snd_kcontrol *kcontrol,
 				   struct snd_ctl_elem_value *ucontrol)
 {
 	struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol);
-	unsigned int ret = 0;
-
-	mutex_lock(&cs35l41->fw_mutex);
 
 	if (cs35l41->request_fw_load == ucontrol->value.integer.value[0])
-		goto err;
+		return 0;
 
 	if (cs35l41->fw_request_ongoing) {
 		dev_dbg(cs35l41->dev, "Existing request not complete\n");
-		ret = -EBUSY;
-		goto err;
+		return -EBUSY;
 	}
 
 	/* Check if playback is ongoing when initial request is made */
 	if (cs35l41->playback_started) {
 		dev_err(cs35l41->dev, "Cannot Load/Unload firmware during Playback\n");
-		ret = -EBUSY;
-		goto err;
+		return -EBUSY;
 	}
 
 	cs35l41->fw_request_ongoing = true;
 	cs35l41->request_fw_load = ucontrol->value.integer.value[0];
 	schedule_work(&cs35l41->fw_load_work);
 
-err:
-	mutex_unlock(&cs35l41->fw_mutex);
-
-	return ret;
+	return 1;
 }
 
 static int cs35l41_fw_type_ctl_get(struct snd_kcontrol *kcontrol,
@@ -881,8 +873,12 @@ static int cs35l41_fw_type_ctl_put(struct snd_kcontrol *kcontrol,
 	struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol);
 
 	if (ucontrol->value.enumerated.item[0] < HDA_CS_DSP_NUM_FW) {
-		cs35l41->firmware_type = ucontrol->value.enumerated.item[0];
-		return 0;
+		if (cs35l41->firmware_type != ucontrol->value.enumerated.item[0]) {
+			cs35l41->firmware_type = ucontrol->value.enumerated.item[0];
+			return 1;
+		} else {
+			return 0;
+		}
 	}
 
 	return -EINVAL;
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/3 ALSA: hda: cs35l41: Fix endian conversions

In reply to Stefan Binding

Found during static analysis, ensure variables are correct types before endian conversion.

---
 sound/pci/hda/cs35l41_hda.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/pci/hda/cs35l41_hda.c +4 -4
index d100189e15b83..ce5faa6205170 100644
@@ -308,8 +308,8 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
 }
 
 #if IS_ENABLED(CONFIG_EFI)
-static int cs35l41_apply_calibration(struct cs35l41_hda *cs35l41, unsigned int ambient,
-				     unsigned int r0, unsigned int status, unsigned int checksum)
+static int cs35l41_apply_calibration(struct cs35l41_hda *cs35l41, __be32 ambient, __be32 r0,
+				     __be32 status, __be32 checksum)
 {
 	int ret;
 
@@ -745,7 +745,7 @@ static int cs35l41_runtime_resume(struct device *dev)
 
 static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
 {
-	int halo_sts;
+	__be32 halo_sts;
 	int ret;
 
 	ret = cs35l41_init_dsp(cs35l41);
@@ -773,7 +773,7 @@ static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
 				&halo_sts, sizeof(halo_sts));
 
 	if (ret) {
-		dev_err(cs35l41->dev, "Timeout waiting for HALO Core to start. State: %d\n",
+		dev_err(cs35l41->dev, "Timeout waiting for HALO Core to start. State: %u\n",
 			 halo_sts);
 		goto clean_dsp;
 	}
Signature · 1 line
2.34.1
#0 lore raw

v3 cover Fixes and cleanup for CS35L41 HDA

Several minor issues were found during additional testing and static analysis. These patches fix these minor issues.

CHANGES SINCE V2:
Patch 3:
- Add missing break

CHANGES SINCE V1:
Patch 2:
- Removed unnecessary cast

Stefan Binding (3):
ALSA: hda: cs35l41: Clean up Firmware Load Controls
ALSA: hda: cs35l41: Fix endian conversions
ALSA: hda/realtek: Delete cs35l41 component master during free

 sound/pci/hda/cs35l41_hda.c   | 32 ++++++++++++++------------------
 sound/pci/hda/patch_realtek.c |  3 +++
 2 files changed, 17 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/3 ALSA: hda/realtek: Delete cs35l41 component master during free

This ensures that the driver is properly cleaned up when freed.

---
 sound/pci/hda/patch_realtek.c | 3 +++
 1 file changed, 3 insertions(+)
sound/pci/hda/patch_realtek.c +3 -0
index f10790ace5c1d..a0e88fd17aa42 100644
@@ -6757,6 +6757,9 @@ static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char
 		else
 			spec->gen.pcm_playback_hook = comp_generic_playback_hook;
 		break;
+	case HDA_FIXUP_ACT_FREE:
+		component_master_del(dev, &comp_master_ops);
+		break;
 	}
 }
 
Signature · 1 line
2.34.1
#4 lore raw
In reply to Stefan Binding
Quoted 8 lines · Stefan Binding

Several minor issues were found during additional testing and static analysis. These patches fix these minor issues.

CHANGES SINCE V2:
Patch 3:
- Add missing break

Quoted 8 lines

CHANGES SINCE V1:
Patch 2:
- Removed unnecessary cast

Stefan Binding (3):
ALSA: hda: cs35l41: Clean up Firmware Load Controls
ALSA: hda: cs35l41: Fix endian conversions
ALSA: hda/realtek: Delete cs35l41 component master during free

Now applied all three patches. Thanks.

Takashi