Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2618744pxb; Sun, 17 Oct 2021 20:41:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTHimMhi80Gh2Vk1iwx0N0th6prLwUyymg0Ba8+dr3SSQgQyEpjuBrVMyJ+pnU+cEyjsZt X-Received: by 2002:a63:7118:: with SMTP id m24mr21413011pgc.332.1634528467360; Sun, 17 Oct 2021 20:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528467; cv=none; d=google.com; s=arc-20160816; b=ywWrVhVe5rAWnO76nTSqA7KJ/p58lwDqml+BrMZx8YsH1H6GQY9UWRJj3T5C7L5HFx uewAtIZmmW4JSrpTZOSBCpDNWY8bGNqpUeJtFEoUt6ucpunOvI9Xo4kxuIgjdMSL40Nl ZOFe79ffMKXqjedFjvb5d9N19BfFN4TQT4h9Qu+cKl5b7g+kcds6o/34DJs2RU4dD2qZ YB5kBQ2TAY2sB1mVku+MAE5AVycfFjasboGyn3qjSnka+zd7bQF8rn7LXfjQ819RuAjg KxcFOQgsUy8xXhcdDRRyQIxxp1n487Qb9axlOWtgIG9BhCkiapCSU+sDucnB6ytayOTV 8AKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=NCdZLtR6EoE6IRx5fhObVN9CU47Q/KKmj9A5jdrLcvY=; b=SpF00AW9C9piEyOQ3Jm8b+zKN0zJ9deh3odQJ13YOR8f8xmLab1SuY0c2i+VFljRMd fKenDyp7EBv67iQzI0VlLAf20M1PM7p7ttH52M3wSSattokCzu8YtYS5w/6EXi8x5Sro rekbqWm2/dJ1/k3Dz+2Cxc7Wz0x7FQw78fOXcafF7e0Hl2Lvqp9+AG2WSh+3qVUD2jK7 P/drZauG0U3OcqprI3/OUf72MIcNizmH4qxmutK6mdnWArI8ctoyTP2F/9cLbIjf6Nqu EyzxaRwzFmXZD7oDgbh2JzOogE6YlZHVsVXW4TDWUXxkcSxq9c4Gr521BzaOB6kxbwUQ xKWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si27081560pgu.41.2021.10.17.20.40.53; Sun, 17 Oct 2021 20:41:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237266AbhJQHdf (ORCPT + 98 others); Sun, 17 Oct 2021 03:33:35 -0400 Received: from smtp04.smtpout.orange.fr ([80.12.242.126]:56770 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232716AbhJQHd3 (ORCPT ); Sun, 17 Oct 2021 03:33:29 -0400 Received: from pop-os.home ([92.140.161.106]) by smtp.orange.fr with ESMTPA id c0dWmm9RWWUfjc0dWm9RJT; Sun, 17 Oct 2021 09:31:18 +0200 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 17 Oct 2021 09:31:18 +0200 X-ME-IP: 92.140.161.106 From: Christophe JAILLET 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 Subject: [PATCH] ASoC: codecs: Fix WCD_MBHC_HPH_PA_EN usage Date: Sun, 17 Oct 2021 09:31:12 +0200 Message-Id: <988948f7f266aa00698704687537335b7e6a67b2.1634455711.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org '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 --- 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