kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
	tiwai@suse.com, srinivas.kandagatla@linaro.org,
	yang.lee@linux.alibaba.com
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH] ASoC: codecs: Fix WCD_MBHC_HPH_PA_EN usage
Date: Sun, 17 Oct 2021 09:31:12 +0200	[thread overview]
Message-ID: <988948f7f266aa00698704687537335b7e6a67b2.1634455711.git.christophe.jaillet@wanadoo.fr> (raw)

'hphpa_on' is known to be false, so the if block at the end of the function
is dead code.

Turn it into a meaningful code by having 'hphpa_on' be static. Use is as a
flip-flop variable.

Fixes: 0e5c9e7ff899 ("ASoC: codecs: wcd: add multi button Headset detection support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
The purpose of this patch is not to be correct (!) but to draw attention
on several points:
   - in 'wcd_mbhc_adc_hs_rem_irq()', the "if (hphpa_on)" path is dead code
     because 'hphpa_on' is known to be false
   - What is this magic number '3'?
     All 'wcd_mbhc_read_field()' look for 0 or non-0
   - a 'mutex_[un]lock()' in an IRQ handler looks spurious to me

Instead of this (likely broken) patch, it is likely that something is
missing elsewhere. Maybe in 'wcd_mbhc_adc_hs_ins_irq()'.
I also guess that 'hphpa_on' should be read for somewhere else.
---
 sound/soc/codecs/wcd-mbhc-v2.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/wcd-mbhc-v2.c b/sound/soc/codecs/wcd-mbhc-v2.c
index 405128ccb4b0..783d8c35bc1b 100644
--- a/sound/soc/codecs/wcd-mbhc-v2.c
+++ b/sound/soc/codecs/wcd-mbhc-v2.c
@@ -1176,7 +1176,7 @@ static irqreturn_t wcd_mbhc_adc_hs_rem_irq(int irq, void *data)
 	struct wcd_mbhc *mbhc = data;
 	unsigned long timeout;
 	int adc_threshold, output_mv, retry = 0;
-	bool hphpa_on = false;
+	static bool hphpa_on = false;
 
 	mutex_lock(&mbhc->lock);
 	timeout = jiffies + msecs_to_jiffies(WCD_FAKE_REMOVAL_MIN_PERIOD_MS);
@@ -1212,6 +1212,9 @@ static irqreturn_t wcd_mbhc_adc_hs_rem_irq(int irq, void *data)
 
 	if (hphpa_on) {
 		hphpa_on = false;
+		wcd_mbhc_write_field(mbhc, WCD_MBHC_HPH_PA_EN, 0);
+	} else {
+		hphpa_on = true;
 		wcd_mbhc_write_field(mbhc, WCD_MBHC_HPH_PA_EN, 3);
 	}
 exit:
-- 
2.30.2


             reply	other threads:[~2021-10-17  7:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-17  7:31 Christophe JAILLET [this message]
2021-10-19 13:47 ` [PATCH] ASoC: codecs: Fix WCD_MBHC_HPH_PA_EN usage Srinivas Kandagatla
2021-10-19 17:39   ` Christophe JAILLET
2021-11-03 10:46     ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=988948f7f266aa00698704687537335b7e6a67b2.1634455711.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.com \
    --cc=yang.lee@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).