From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C022A37F8DC for ; Tue, 7 Jul 2026 05:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783401061; cv=none; b=DBev5DeWZ4a1ZsoDsJ+DLUC5u2hRDPpWdEMjH3nO2567yImINgZNy7OrUKfgfk3QPl9fPIOI8XketfXrUWmHV9VUnpCRpPj9h9zx07rf2CS1M7E0E3028mFWBiAmTWb3wh5g4J85bVLFmef0IiZAQkKe9UwANzdKTTNiE+L/Sao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783401061; c=relaxed/simple; bh=NLNJ9p8QjUYwBmyR9RSKdZ9PzqrvOLlKrVQIcV9VZ0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f/7RbliQ7ta+my32yLMc1HtnMY6+nHGxqhBPP9d/obAXw1sQ3z7do4DTn1Wa07UCJJzS5nuhY5t+zgRaRmq3yAGl7yy0r/P75+7hUIC/a6d0IKdS4MfUWhnJ+c6DoLVg9EgVA9FiunIgF++NzgHzeKi39XpdWGWp0hX8ARtySPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aiUPIWhL; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aiUPIWhL" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-847968ca62fso3929064b3a.2 for ; Mon, 06 Jul 2026 22:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783401059; x=1784005859; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bPhJ/orWytTpfq3BLT+Hf12jldViQ+Hp0ohV62p2F+A=; b=aiUPIWhLzH0lu1rwPM7nOpAxdQR9d8BB1Jx28BDy+KiHZOqCVa2mXuwnEhZl/7ps/A KndNXPRz5TQUkcXrSkwSNT6soJk0TmtHtIHDjNI5/S/QLiY4ofPUUcGk9yEBuye/++Lt timoD+df87z1DZIiITtRfsRIq2X8R/eEdpuHcE5vG+EoUqDN29mrMwraiJs8aF7ChVeW jG36JOewyZelKZWztrze/zk1TrO09hyS/37Lh/FpSlehAZHtqF15XEVNECqGGRCuEELm kS+LhErjdLosJb6u4VQZNdthulR0nkAdyOKg4cK610+UfaHDOf7SvdpPzrwsEO0CsfyI Ljhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783401059; x=1784005859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bPhJ/orWytTpfq3BLT+Hf12jldViQ+Hp0ohV62p2F+A=; b=OvHB/K/tFKczDbJ6jUDRNds4yeFsBjjEfQFNTlAmSuHF8DIhFJ+pltfEfNrXpHJPJi Bq2gh/XLn+tg62Rbzp/3IT/sRgaFbbJV8QNgXAO0jmk/llWS/+LA6FbMO0ZYEjTFbtqt hR+wiqGmWKcMQDWs0bBYjaUNHiWd8D+OkXxDV40GzmkLA8I85XpmD6k3TRZXMt2LO0j4 Pvv0YS1Dx/jMQX7W7MOZiRvIroSKSRZZNXA4d3Or2I1A5+7HfJqgUqKLwIAZgqWBAJzQ KaY9NjomsPBNCIYcVgb7eoFw59NciJnQHtwa1Nxv0+ou8OMdlVooFDZzOFxo+WR7WKZJ v0bg== X-Forwarded-Encrypted: i=1; AHgh+RpBuxwqvrwlozIHMHvJNc7NDuAJBFzfqAPzgxcM/ql4wlyr5/jmB9tWbs39LQuHrCU+lt4BkQ==@lists.linux.dev X-Gm-Message-State: AOJu0YxhL7ET3K/g+dR0+HIFJ7SUA69aIMzf9QgRaYhVziHp5OGrYVIE nCgG/+gQS9asHyJFkdgXEWGOyrAGwzRRL8pfgdnQXaALEjunX8QwcTzV X-Gm-Gg: AfdE7cmpAnA/BmAYbL+mqrX0Diw4pnhOtEMmVsR+Lpg9B/xcc1GDDmnEwb5oSEHWabR pxlWLwu9E+VIy/zYqnz+9FkQ7QfulTEvL3NdjHlbFr9gLktjUNrc7IIOA3hIGVM2inzWekC2/j8 r7HYUIhfQmUR/1renZVj+hPNq87QAekAQNOXp2QMSeIUZV/bT9g3QhwLRBWwYvEWkxvxnYDaKbJ 5rDgFFJ2oird/N380GHezHq9go1TDUP2Qy80BnbN8SKSxy6LHqZTlEuDC4tuvfmA++/YCGEYuCb 6b51sd0PMLkX//3YapEHIkOIKBuN2aLRrW/xYNSysEMZdnw+6E1sHYQKtm8jDMBjBIO1x1et1Mz VXg4yKGK7iuQlOXrNtR/VpK18uNOKFWOEQ8xElIW9xeIe9Z0ASlJ8cS+QyIZ1cDxwFJryPNVj2S bp8tnGyu70xzOSpnz0UHtZHIf9JF/qfZEiiEJEYEFREc64gD5FidNoPuIB2g== X-Received: by 2002:a05:6a00:1c86:b0:845:db8d:f631 with SMTP id d2e1a72fcca58-84826b80eb5mr3561080b3a.7.1783401058953; Mon, 06 Jul 2026 22:10:58 -0700 (PDT) Received: from phuc-desktop.. ([183.91.15.56]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847f6d4dbdesm4728495b3a.31.2026.07.06.22.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 22:10:58 -0700 (PDT) From: phucduc.bui@gmail.com To: Mark Brown , Takashi Iwai , Tzung-Bi Shih , David Rhodes , Charles Keepax Cc: Liam Girdwood , Jaroslav Kysela , Cheng-Yi Chiang , Guenter Roeck , Benson Leung , Richard Fitzgerald , povik+lin@cutebit.org, u.kleine-koenig@baylibre.com, kuninori.morimoto.gx@renesas.com, christian.ehrhardt@codasip.com, Linus Walleij , Arnd Bergmann , Sakari Ailus , Thorsten Blum , Chris Morgan , Dan Carpenter , Marco Crivellari , Rosen Penev , Weidong Wang , Teguh Sobirin , Val Packett , Luca Weiss , wangdicheng , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com, chrome-platform@lists.linux.dev, asahi@lists.linux.dev, Cezary Rojewski , bui duc phuc Subject: [PATCH v3 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers Date: Tue, 7 Jul 2026 12:09:45 +0700 Message-ID: <20260707051006.20058-4-phucduc.bui@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260707051006.20058-1-phucduc.bui@gmail.com> References: <20260707051006.20058-1-phucduc.bui@gmail.com> Precedence: bulk X-Mailing-List: asahi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: bui duc phuc Clean up the code using guard() helpers for mutex locking and PM runtime management. No functional change intended. Reviewed-by: Cezary Rojewski Reviewed-by: Charles Keepax Signed-off-by: bui duc phuc --- Changes in v2: Reworked the code to use an if/else structure, avoiding code duplication after removing the goto label. Changes in v3: Remove unnecessary blank lines. sound/soc/codecs/arizona-jack.c | 117 +++++++++++++++----------------- 1 file changed, 53 insertions(+), 64 deletions(-) diff --git a/sound/soc/codecs/arizona-jack.c b/sound/soc/codecs/arizona-jack.c index a9063bac2752..819d080b1188 100644 --- a/sound/soc/codecs/arizona-jack.c +++ b/sound/soc/codecs/arizona-jack.c @@ -5,6 +5,7 @@ * Copyright (C) 2012-2014 Wolfson Microelectronics plc */ +#include #include #include #include @@ -707,15 +708,13 @@ static void arizona_micd_timeout_work(struct work_struct *work) struct arizona_priv, micd_timeout_work.work); - mutex_lock(&info->lock); + guard(mutex)(&info->lock); dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n"); info->detecting = false; arizona_identify_headphone(info); - - mutex_unlock(&info->lock); } static int arizona_micd_adc_read(struct arizona_priv *info) @@ -921,12 +920,11 @@ static void arizona_micd_detect(struct work_struct *work) cancel_delayed_work_sync(&info->micd_timeout_work); - mutex_lock(&info->lock); + guard(mutex)(&info->lock); /* If the cable was removed while measuring ignore the result */ if (!(info->jack->status & SND_JACK_MECHANICAL)) { dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n"); - mutex_unlock(&info->lock); return; } @@ -936,7 +934,6 @@ static void arizona_micd_detect(struct work_struct *work) arizona_button_reading(info); pm_runtime_mark_last_busy(arizona->dev); - mutex_unlock(&info->lock); } static irqreturn_t arizona_micdet(int irq, void *data) @@ -948,10 +945,10 @@ static irqreturn_t arizona_micdet(int irq, void *data) cancel_delayed_work_sync(&info->micd_detect_work); cancel_delayed_work_sync(&info->micd_timeout_work); - mutex_lock(&info->lock); - if (!info->detecting) - debounce = 0; - mutex_unlock(&info->lock); + scoped_guard(mutex, &info->lock) { + if (!info->detecting) + debounce = 0; + } if (debounce) queue_delayed_work(system_power_efficient_wq, @@ -969,9 +966,8 @@ static void arizona_hpdet_work(struct work_struct *work) struct arizona_priv, hpdet_work.work); - mutex_lock(&info->lock); + guard(mutex)(&info->lock); arizona_start_hpdet_acc_id(info); - mutex_unlock(&info->lock); } static int arizona_hpdet_wait(struct arizona_priv *info) @@ -1018,9 +1014,9 @@ static irqreturn_t arizona_jackdet(int irq, void *data) cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work); cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work); - pm_runtime_get_sync(arizona->dev); + guard(pm_runtime_active_auto)(arizona->dev); - mutex_lock(&info->lock); + guard(mutex)(&info->lock); if (info->micd_clamp) { mask = ARIZONA_MICD_CLAMP_STS; @@ -1036,8 +1032,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data) ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val); if (ret) { dev_err(arizona->dev, "Failed to read jackdet status: %d\n", ret); - mutex_unlock(&info->lock); - pm_runtime_put_autosuspend(arizona->dev); return IRQ_NONE; } @@ -1056,62 +1050,61 @@ static irqreturn_t arizona_jackdet(int irq, void *data) &info->micd_timeout_work, msecs_to_jiffies(micd_timeout)); } + } else { + info->last_jackdet = val; - goto out; - } - info->last_jackdet = val; + if (info->last_jackdet == present) { + dev_dbg(arizona->dev, "Detected jack\n"); + snd_soc_jack_report(info->jack, SND_JACK_MECHANICAL, SND_JACK_MECHANICAL); - if (info->last_jackdet == present) { - dev_dbg(arizona->dev, "Detected jack\n"); - snd_soc_jack_report(info->jack, SND_JACK_MECHANICAL, SND_JACK_MECHANICAL); + info->detecting = true; + info->mic = false; + info->jack_flips = 0; - info->detecting = true; - info->mic = false; - info->jack_flips = 0; + if (!arizona->pdata.hpdet_acc_id) { + arizona_start_mic(info); + } else { + queue_delayed_work(system_power_efficient_wq, + &info->hpdet_work, + msecs_to_jiffies(HPDET_DEBOUNCE)); + } - if (!arizona->pdata.hpdet_acc_id) { - arizona_start_mic(info); + if (info->micd_clamp || !arizona->pdata.jd_invert) + regmap_update_bits(arizona->regmap, + ARIZONA_JACK_DETECT_DEBOUNCE, + ARIZONA_MICD_CLAMP_DB | + ARIZONA_JD1_DB, 0); } else { - queue_delayed_work(system_power_efficient_wq, - &info->hpdet_work, - msecs_to_jiffies(HPDET_DEBOUNCE)); - } + dev_dbg(arizona->dev, "Detected jack removal\n"); - if (info->micd_clamp || !arizona->pdata.jd_invert) - regmap_update_bits(arizona->regmap, - ARIZONA_JACK_DETECT_DEBOUNCE, - ARIZONA_MICD_CLAMP_DB | - ARIZONA_JD1_DB, 0); - } else { - dev_dbg(arizona->dev, "Detected jack removal\n"); - - arizona_stop_mic(info); + arizona_stop_mic(info); - info->num_hpdet_res = 0; - for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++) - info->hpdet_res[i] = 0; - info->mic = false; - info->hpdet_done = false; - info->hpdet_retried = false; + info->num_hpdet_res = 0; + for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++) + info->hpdet_res[i] = 0; + info->mic = false; + info->hpdet_done = false; + info->hpdet_retried = false; - snd_soc_jack_report(info->jack, 0, ARIZONA_JACK_MASK | info->micd_button_mask); + snd_soc_jack_report(info->jack, 0, + ARIZONA_JACK_MASK | info->micd_button_mask); - /* - * If the jack was removed during a headphone detection we - * need to wait for the headphone detection to finish, as - * it can not be aborted. We don't want to be able to start - * a new headphone detection from a fresh insert until this - * one is finished. - */ - arizona_hpdet_wait(info); + /* + * If the jack was removed during a headphone detection we + * need to wait for the headphone detection to finish, as + * it can not be aborted. We don't want to be able to start + * a new headphone detection from a fresh insert until this + * one is finished. + */ + arizona_hpdet_wait(info); - regmap_update_bits(arizona->regmap, - ARIZONA_JACK_DETECT_DEBOUNCE, - ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB, - ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB); + regmap_update_bits(arizona->regmap, + ARIZONA_JACK_DETECT_DEBOUNCE, + ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB, + ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB); + } } -out: /* Clear trig_sts to make sure DCVDD is not forced up */ regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG, ARIZONA_MICD_CLAMP_FALL_TRIG_STS | @@ -1119,10 +1112,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data) ARIZONA_JD1_FALL_TRIG_STS | ARIZONA_JD1_RISE_TRIG_STS); - mutex_unlock(&info->lock); - - pm_runtime_put_autosuspend(arizona->dev); - return IRQ_HANDLED; } -- 2.43.0