Skip to contentSkip to conversation

extcon: arizona: Fix reset of HPDET after race with removal

PATCH In review Charles Keepax 2 participants 7 messages Oct 27, 2013 – Nov 4, 2013 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 extcon: arizona: Fix reset of HPDET after race with removal

We need to make sure we reset back to our starting state, especially making sure that we have disabled poll in the register cache.

---
 drivers/extcon/extcon-arizona.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/extcon/extcon-arizona.c +7 -1
index ec9a14e..dac8ba0 100644
@@ -596,9 +596,15 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 		dev_err(arizona->dev, "Failed to report HP/line: %d\n",
 			ret);
 
+done:
+	/* Reset back to starting range */
+	regmap_update_bits(arizona->regmap,
+			   ARIZONA_HEADPHONE_DETECT_1,
+			   ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
+			   0);
+
 	arizona_extcon_do_magic(info, 0);
 
-done:
 	if (id_gpio)
 		gpio_set_value_cansleep(id_gpio, 0);
 
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 2/2 extcon: arizona: Fix race with microphone detection and removal

The microphone detection code is run as delayed work to provide additional debounce, it is possible that the jack could have been removed by the time we process the microphone detection. Turn this case into a no op.

---

As Lee Jones took the first patch (extcon: arizona: Add defines for microphone detection levels) of my series yesterday through his tree I have based this patch on the extcon tree without that change applied.

Thanks,
Charles

 drivers/extcon/extcon-arizona.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/extcon/extcon-arizona.c +6 -0
index dac8ba0..9c20850 100644
@@ -773,6 +773,12 @@ static void arizona_micd_detect(struct work_struct *work)
 
 	mutex_lock(&info->lock);
 
+	if (!info->cable) {
+		dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
+		mutex_unlock(&info->lock);
+		return;
+	}
+
 	for (i = 0; i < 10 && !(val & 0x7fc); i++) {
 		ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
 		if (ret != 0) {
Signature · 1 line
1.7.2.5
maintainer
#4 lore raw
In reply to Charles Keepax

Hi Charles,

Quoted 20 lines · Charles Keepax

We need to make sure we reset back to our starting state, especially making sure that we have disabled poll in the register cache.

---
 drivers/extcon/extcon-arizona.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/extcon/extcon-arizona.c +3 -0
index ec9a14e..dac8ba0 100644
@@ -596,9 +596,15 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 		dev_err(arizona->dev, "Failed to report HP/line: %d\n",
 			ret);
 
+done:
+	/* Reset back to starting range */
+	regmap_update_bits(arizona->regmap,

drivers/extcon/extcon-arizona.c static irqreturn_t arizona_hpdet_irq(int irq, void *data) · line 610

Quoted 10 lines
drivers/extcon/extcon-arizona.c +4 -1
+			   ARIZONA_HEADPHONE_DETECT_1,
+			   ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
+			   0);
+
 	arizona_extcon_do_magic(info, 0);
 
-done:
 	if (id_gpio)
 		gpio_set_value_cansleep(id_gpio, 0);
 

The arizona_hpdet_do_id() return only either -EAGIN or 0(zero). extcon-arizona driver could never execute 'goto done;' statement.

	ret = arizona_hpdet_do_id(info, &reading, &mic);
	if (ret == -EAGAIN) {
		goto out;
	} else if (ret < 0) {
		goto done;
	}

Thanks,
Chanwoo Choi

maintainer
#2 lore raw

Re: [PATCH 2/2] extcon: arizona: Fix race with microphone detection and removal

In reply to Charles Keepax
Quoted 27 lines · Charles Keepax

The microphone detection code is run as delayed work to provide additional debounce, it is possible that the jack could have been removed by the time we process the microphone detection. Turn this case into a no op.

---

As Lee Jones took the first patch (extcon: arizona: Add defines for microphone detection levels) of my series yesterday through his tree I have based this patch on the extcon tree without that change applied.

Thanks,
Charles

 drivers/extcon/extcon-arizona.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/extcon/extcon-arizona.c +0 -0
index dac8ba0..9c20850 100644
@@ -773,6 +773,12 @@ static void arizona_micd_detect(struct work_struct *work)
 
 	mutex_lock(&info->lock);

drivers/extcon/extcon-arizona.c static void arizona_micd_detect(struct work_struct *work) · line 784

Quoted 10 lines
drivers/extcon/extcon-arizona.c +6 -0
 
+	if (!info->cable) {
+		dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
+		mutex_unlock(&info->lock);
+		return;
+	}
+
 	for (i = 0; i < 10 && !(val & 0x7fc); i++) {
 		ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
 		if (ret != 0) {

This patch has build break as below log:

drivers/extcon/extcon-arizona.c: In function ‘arizona_micd_detect’:
drivers/extcon/extcon-arizona.c:776:11: error: ‘struct arizona_extcon_info’ has no member named ‘cable’

The arizona_extcon_info structure hasn't included 'cable' field.

Cheers,
Chanwoo Choi

#3 lore raw

Re: [PATCH 2/2] extcon: arizona: Fix race with microphone detection and removal

Quoted 6 lines · Chanwoo Choi

This patch has build break as below log:

drivers/extcon/extcon-arizona.c: In function ‘arizona_micd_detect’:
drivers/extcon/extcon-arizona.c:776:11: error: ‘struct arizona_extcon_info’ has no member named ‘cable’

The arizona_extcon_info structure hasn't included 'cable' field.

Apologies, must have been accidentally being added by another patch in my tree. I will sort that out and resend.

Thanks,
Charles

#5 lore raw
In reply to Chanwoo Choi
Quoted 9 lines · Chanwoo Choi

The arizona_hpdet_do_id() return only either -EAGIN or 0(zero). extcon-arizona driver could never execute 'goto done;' statement.

	ret = arizona_hpdet_do_id(info, &reading, &mic);
	if (ret == -EAGAIN) {
		goto out;
	} else if (ret < 0) {
		goto done;
	}

True that else if is redundant at the moment, but personally I would be inclined to leave it in, it feels safer against possible future edits of arizona_hpdet_do_id. It would be reasonable for someone to assume that other return values are acceptable whilst editing it but they would then not be handled.

Thanks,
Charles

maintainer
#6 lore raw
Quoted 11 lines · Charles Keepax
Quoted 9 lines · Chanwoo Choi

The arizona_hpdet_do_id() return only either -EAGIN or 0(zero). extcon-arizona driver could never execute 'goto done;' statement.

	ret = arizona_hpdet_do_id(info, &reading, &mic);
	if (ret == -EAGAIN) {
		goto out;
	} else if (ret < 0) {
		goto done;
	}
Quoted 5 lines

True that else if is redundant at the moment, but personally I would be inclined to leave it in, it feels safer against possible future edits of arizona_hpdet_do_id. It would be reasonable for someone to assume that other return values are acceptable whilst editing it but they would then not be handled.

I know your intention. But, I cannot apply this patch for potential issue. Also, we have to fix below dead code after returning arizona_hpdet_do_id()

	>> 	} else if (ret < 0) {
	>> 		goto done;
	>> 	}

Thanks,
Chanwoo Choi