From patchwork Thu Jan 9 23:31:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= X-Patchwork-Id: 11326439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B20CA14B4 for ; Thu, 9 Jan 2020 23:31:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 8F92E20661 for ; Thu, 9 Jan 2020 23:31:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="n93JsC07"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WHYq1fFh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F92E20661 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From: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=ZOBK/RIpLjYx026ePf8yLIqn3NoDc5ozVnryCtgKhL0=; b=n93JsC07oGX3s+ I8AvaxchpFA3+57Imu1I59sl4gYZM09lTR31WP4C412d9OxlStcH85RIbCIQB8fIZNNIJZPRG+W+e C84lvfvTkJtqtNxGXMOXteVQsi0+2NXP1ZstMb8QC1MoHk2ziNY8krTE0aYNxVH0ux8N+89oFW6YE vHaVHz+eUN21m8W2nPf1EJPWaMIe4wwOfX9KCs0KXrjInTq6lD53QrHJG/K/Ux/aFyUdcGGBPFMkG G6uo+7EPJ/KM6Q3Uz4ufi37i5EZ6XZ3URydtppricMqwbOImOf8w2mjmqH+HK6OdCuA8pdovgnGql NFdpm5/Qfu4iw7ySwP3A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iphGo-0007ym-Ni; Thu, 09 Jan 2020 23:31:18 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iphGl-0007xl-NB for linux-arm-kernel@lists.infradead.org; Thu, 09 Jan 2020 23:31:17 +0000 Received: by mail-wr1-x444.google.com with SMTP id g17so33074wro.2 for ; Thu, 09 Jan 2020 15:31:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=L6mL2rwAPESuHHV2T0yqwj8NcOs/y+OPpLLCMYhkdgY=; b=WHYq1fFh9Cxbs9wNaMgifYWFbckwV0pUXZqMxJQCtBA3YP2j/BbVnFoVGSfN65SwSv gUiQ+lh/SQXhNWPPqEF9P+u4NjB54mMMprX9wevto19lDtvn2MmOi1qdH01q7ExdSYZA T4oJ9NVOU9Fbq5xWX4cRsKvqOVbyCsSsbrtEasmQROlKfYk86d7ksdG05+V5BfeswNCX GmXCGVNZUrHkOkgbiiqHhejqH9HEMkJNsogVlCBOBSzEoUqBNhVXQE2nHGf+7Oblzszo oBEqqB7TvA9q0jesZLGTK0YbHXjYJv6sxkbQeF4IAlIXxYRAnA6Vvjc3cKkcvQYqbNl+ bqRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=L6mL2rwAPESuHHV2T0yqwj8NcOs/y+OPpLLCMYhkdgY=; b=nt3SfE2abeJrOK9u6ziD3jZFz6UCdFD7FQpFaDOvqOcsqI+G1rNWshkW2lWmn0M0jt NzGjWofYDUrB2/Rzi2uu4c7v24A4y0V1K0VoC347Xi0HkdhtpiUdB2B8IfVJpQ3yG01U MQnqHRr5M4GHyZ/dURL/8emnzAFsiJAg0zODNE2Y82M9wCHvwlWJ1qRnJlJdq/oovxp3 fF3TuZUy3Pvvzjr4jCYK5qNdnooAcdgI19U98HQfzZ65ENtBizfaChxIwkx9pxNCg6bj Chiojhw5zT+2xQrJlSFf6LccT/qgfJ85DEtDTo9VS+/+5jhrDzAbwDkjstck2W6vOLM9 yyoA== X-Gm-Message-State: APjAAAXmNQ6YBLqWnPtbqO7+pIOxACzeRe90e17sDRMb09xlmrK+Dws0 2XQcQk3Noni/0L1gJ7HGPlA= X-Google-Smtp-Source: APXvYqxYCt3lxuhdOfrbwTTC08LgsFznYbnh4QnkiyuzHfw0Pr0dMFXtnPnXBE6EQuGhXyiUcDU6zQ== X-Received: by 2002:adf:eb09:: with SMTP id s9mr237036wrn.61.1578612672652; Thu, 09 Jan 2020 15:31:12 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:1f1:d0f0::42f0:c285]) by smtp.gmail.com with ESMTPSA id h2sm107563wrt.45.2020.01.09.15.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 15:31:12 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= To: Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6n?= =?utf-8?q?ig?= Subject: [PATCH] [RFC] pwm: sun4i: Move pwm_calculate out of spin_lock Date: Fri, 10 Jan 2020 00:31:06 +0100 Message-Id: <20200109233106.17060-1-peron.clem@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200109_153115_779490_DA055891 X-CRM114-Status: GOOD ( 11.28 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (peron.clem[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= , Alex Mobigo , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org pwm_calculate calls clk_get_rate while holding a spin_lock. This create an issue as clk_get_rate() may sleep. Move pwm_calculate out of this spin_lock. Fixes: c32c5c50d4fe ("pwm: sun4i: Switch to atomic PWM") Reported-by: Alex Mobigo Suggested-by: Vasily Khoruzhick Signed-off-by: Clément Péron Reviewed-by: Uwe Kleine-König Tested-By: Alexander Finger --- Hi, this issue has been reported on linux-sunxi Google groups. I don't have a board with PWM to confirm it. Please wait a tested-by. Thanks, Clément drivers/pwm/pwm-sun4i.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 1afd41ebd3fd..6b230029dc49 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -248,19 +248,18 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } } - spin_lock(&sun4i_pwm->ctrl_lock); - ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); - ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler, &bypass); if (ret) { dev_err(chip->dev, "period exceeds the maximum value\n"); - spin_unlock(&sun4i_pwm->ctrl_lock); if (!cstate.enabled) clk_disable_unprepare(sun4i_pwm->clk); return ret; } + spin_lock(&sun4i_pwm->ctrl_lock); + ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); + if (sun4i_pwm->data->has_direct_mod_clk_output) { if (bypass) { ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm);