From patchwork Tue Apr 6 14:45:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12185423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FD54C433ED for ; Tue, 6 Apr 2021 14:48:31 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 03369613B8 for ; Tue, 6 Apr 2021 14:48:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03369613B8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=VREJHqYXAvtrIhHIbEKAgEZHVpkO+X207ERvQSEjkIk=; b=cYS+42lSde6R0e2zojLP5jggf0 Y4zsiw75qPhKMe5u5fC0Z/zhg0juY+onYFw7zu4pv0G3BTi+f2tESOYXlsJq/0eIy6C8tV+X3E8/U A9z6+yoPiOFNfBz6cJZMNG7p+OvxmCZcEnXAN9X9cyzwbFqF6Awc8YiU7TVWjE8YxK+32F032gpF5 HuZaieKFDki9zCI8CB6XfS1LKyX1n44ElpQkr5pMV36GrdU78aKq2279nPxELMQMpJUCcF3xyy34y FfD9HYI6UNkckmZnZWGRj2NxretQtvWcq00BH11aV7gIWCzx2i5iBP8ibGOsBzzfqkUlL1FWreDsX B1qiWV6w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lTmyD-002rv8-Af; Tue, 06 Apr 2021 14:46:21 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lTmy7-002ruE-2A for linux-arm-kernel@lists.infradead.org; Tue, 06 Apr 2021 14:46:16 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id u128so20500128ybf.12 for ; Tue, 06 Apr 2021 07:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=K97dfDzOakTNCO8JzrPfznFhYT4VKiM9VzlN1DMwR60=; b=giIt6BWIWMwL+8oWHNwVESB6kfvJE2Hmau2LQVK/qOvPwuVEBKftkRZlFONM4nGfoF Hf/3c1QQXU1V6LSOxXw1m8k1LrR5PqMpXkizk0pt2yxTS2VNowkZ6SXdp7lnqTD3G36P DfFnoQCzXpXGqSfvu8nyoT3dfIcQVDUz7hkC9HBCD50BIfK6GTOyruWVW2MGRGtsKlqS +717WzuUfV63wlvhHPAOm1OQKLr9d8jar0vqcjCLaVwtoMvwR++xHQXqUD0eKiREtED1 KH7HytuHx9+jM5UHZfehajQldXI3Ey5Jq8TyimnuZ2+Udhr92HChGO5d4JgRFXoTo73v cylw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=K97dfDzOakTNCO8JzrPfznFhYT4VKiM9VzlN1DMwR60=; b=oINYTBFC0j9o3broAhd8fy3RF1zGQ67XAKxxP7b2zXfh2S9mswIKeqtYocxujLrn+0 SfVSnTFPwQljMWgxGIQfFrrr0W4rHpbMNUtwCYvaPPfM70UZrydQldaecK2m7PFStGUu sH+6wUQIFqUb5VLbHrj2Y6xCdhI92Bu0/Dj/+RKdMebJLTH3AaZgsJNFjtJHXmH+FdXG +SOj5ZOuS+qw6ICwa4F4Kt981OlbItq2SsxeIRs625O5lH5tTO89F2QYfaLkaL0fUeMt NHBSEIpoPWOlxPD4WKL1ZfalcR2IDQ+nPoD6EeJWXTTPULfKdNIz8tyAFApkCgiU8Iz/ 1YyQ== X-Gm-Message-State: AOAM531PBMxd/Il1guQqkGz1qGQhMKanWK++uU9uQXHXPf185T0G/8xa WgwdWPL1Wv3CTnXrXkg6U1qzyiX9fmDx X-Google-Smtp-Source: ABdhPJxLBPH5IlbJAcEx+YiWk14ww+bmR7OEBrrGRnZpj3rZAnOKTtdeTjOnpEQ5A5YxHscwtF3PTCwuzler X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:9d56:89cb:f993:7b46]) (user=tzungbi job=sendgmr) by 2002:a25:e90b:: with SMTP id n11mr38157321ybd.467.1617720372864; Tue, 06 Apr 2021 07:46:12 -0700 (PDT) Date: Tue, 6 Apr 2021 22:45:40 +0800 Message-Id: <20210406144540.3467756-1-tzungbi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH] pinctrl: mediatek: use spin lock in mtk_rmw From: Tzung-Bi Shih To: sean.wang@kernel.org, linus.walleij@linaro.org Cc: alsa-devel@alsa-project.org, tzungbi@google.com, matthias.bgg@gmail.com, zhiyong.tao@mediatek.com, linux-mediatek@lists.infradead.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210406_154615_231518_894C3ABB X-CRM114-Status: GOOD ( 13.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit 42a46434e9b1 ("pinctrl: add lock in mtk_rmw function.") uses mutex lock in mtk_rmw. However the function is possible called from atomic context. For example call trace: mutex_lock+0x28/0x64 mtk_rmw+0x38/0x80 mtk_hw_set_value+0x100/0x138 mtk_gpio_set+0x48/0x58 gpiod_set_raw_value_commit+0xf4/0x110 gpiod_set_value_nocheck+0x4c/0x80 gpiod_set_value+0x4c/0x6c max98357a_daiops_trigger+0x8c/0x9c soc_pcm_trigger+0x5c/0x10c The max98357a_daiops_trigger() could run in either atomic or non-atomic context. As a result, dmesg shows some similar messages: "BUG: sleeping function called from invalid context at kernel/locking/mutex.c:254". Uses spin lock in mtk_rmw instead. Fixes: 42a46434e9b1 ("pinctrl: add lock in mtk_rmw function.") Signed-off-by: Tzung-Bi Shih --- drivers/pinctrl/mediatek/pinctrl-moore.c | 2 +- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 4 ++-- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h | 2 +- drivers/pinctrl/mediatek/pinctrl-paris.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c index f77921957f15..3a4a23c40a71 100644 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c @@ -619,7 +619,7 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, hw->nbase = hw->soc->nbase_names; - mutex_init(&hw->lock); + spin_lock_init(&hw->lock); /* Copy from internal struct mtk_pin_desc to register to the core */ pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c index fcf7c3eeee4a..9ffe01a8ceca 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c @@ -58,14 +58,14 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set) { u32 val; - mutex_lock(&pctl->lock); + spin_lock(&pctl->lock); val = mtk_r32(pctl, i, reg); val &= ~mask; val |= set; mtk_w32(pctl, i, reg, val); - mutex_unlock(&pctl->lock); + spin_unlock(&pctl->lock); } static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h index 65eac708a3b3..13836bb188b7 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h @@ -252,7 +252,7 @@ struct mtk_pinctrl { struct mtk_pinctrl_group *groups; const char **grp_names; /* lock pin's register resource to avoid multiple threads issue*/ - struct mutex lock; + spinlock_t lock; }; void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set); diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c index 48e823f6d293..85db2e4377f0 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.c +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c @@ -970,7 +970,7 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev, hw->nbase = hw->soc->nbase_names; - mutex_init(&hw->lock); + spin_lock_init(&hw->lock); err = mtk_pctrl_build_state(pdev); if (err) {