From patchwork Mon Jan 13 09:23:13 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: 11329811 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 A29FA92A for ; Mon, 13 Jan 2020 09:23:33 +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 64A44207FF for ; Mon, 13 Jan 2020 09:23:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RyL3BNAm"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y5wOa+B0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64A44207FF 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=AoDPB9lanJsjUSct8iRqWResXpmaJQD6SVa2Q/LG408=; b=RyL3BNAmZW44yA /Uhz2+hVBJnB2j7nfe2T6O9Pb8k77srcZn3HyMkZ9FfkfzMqDc7Alm4muvdwtJv/SIRqCP0fNW4rJ jA5O/CWENOglji6C9LePZmiMAM0FY186oZI0xEWOmGNVdStoPjweILg3heYlG2FKarsO7JZsdpQh2 0yZAWujFE90TBUVlJo6mxKggeqzwMtqL9jaiiZCEtFC6cDOl99KEUMncnPAnqI5ZX08wC4YEbWvMz N5WuRGWtC5GFFZ8F5BGUi8X6+iAkZwMK+LVSLughNy1jH26pj8tU7ulBLQdi2I7xh97Y+PxsO4t6U YWIcKQazXrK47SfvMaOw==; 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 1iqvwX-00068D-7j; Mon, 13 Jan 2020 09:23:29 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iqvwT-00064w-BE for linux-arm-kernel@lists.infradead.org; Mon, 13 Jan 2020 09:23:26 +0000 Received: by mail-wr1-x442.google.com with SMTP id z3so7739172wru.3 for ; Mon, 13 Jan 2020 01:23:24 -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=CSFpFoFsjn6jAy+TG53ImMMGFOcZFIAFPo+oRWA0h9k=; b=Y5wOa+B0jyEoz6U1WZodUBGbXQqMQa2YqaIfzm972UifoEOJggbkfkCjtd7AQDiFNB 6K6dxLDAMzQXqhWnmwer7Y9EfOd2GFINKgaeQcYRCeJnOoh1IGIK20BsQOLRfXLUgGhn UaEj2ebcEU2wRuLKz/Ko6sPp/qK91G/voTiGWMUwN5oVOXC8gH6362WpUJPk7Z+LzjyH JbrvUaP8cBziF85X+TKhL/xKeQdnSSI8Vz+k+6x4HlY+939Z/NIHe0W+Dvda6IVEz2Zq sROWCixh5yCFPtYjUtK+vJuZVEOrijOWdEQd1YDls2WZ3WF4uTdtkuaqUMXgas9VMvtg 3Xmg== 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=CSFpFoFsjn6jAy+TG53ImMMGFOcZFIAFPo+oRWA0h9k=; b=Uv6olFCLE7S16gCA8fvm6aXLuNA5nGvO50zmyUjCKnFMUUxEPFnvL223kZQGVVraqZ UhUoZQmrnfzGjDl+kOF8j/wIbucciM5v0pacoiMskuItw6nPjkXAckQT9jAsDwNsILER BTe48ByiIvyAXKDIBGyNmelvgzi4snOddf5U5bSxS6xLT1qLhD8v9Sa+4wF8YlK9AoDs neKZp6s7ZqTV6gQrzXJlVQ5Wg3kRbYZyjOTHqw9ED01VZgvXfW7+hLSi+jWSeNKmxEQd i8lcbo12lVExrrZu9wPGe5yelHbKWM4L/h7nk7nt2n8VIqix1H5oSdv6pf9buRIVla9S 64dA== X-Gm-Message-State: APjAAAV/kJJwIgtSsY3i0CHUoBTaOLPJO+lMkm38eYpfMVTjwdnpCL3C zjHihRBpYnebVqImDSZUHYaX4nk/wXI= X-Google-Smtp-Source: APXvYqxRn+sRQafI02NF+bw/rFd9vEpLEBqvNZGoqkfz9ox3Xda2xz1Xoy4JcXW25lad3I8fAUWxhQ== X-Received: by 2002:adf:fd84:: with SMTP id d4mr17281818wrr.211.1578907403581; Mon, 13 Jan 2020 01:23:23 -0800 (PST) Received: from clement-Latitude-7490.outsight.local (lputeaux-656-1-11-33.w82-127.abo.wanadoo.fr. [82.127.142.33]) by smtp.gmail.com with ESMTPSA id p26sm13164466wmc.24.2020.01.13.01.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 01:23:23 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= To: Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6n?= =?utf-8?q?ig?= Subject: [PATCH v2] pwm: sun4i: Move pwm_calculate() out of spin_lock() Date: Mon, 13 Jan 2020 10:23:13 +0100 Message-Id: <20200113092313.30382-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-20200113_012325_389838_18E451F5 X-CRM114-Status: GOOD ( 10.24 ) 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:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (peron.clem[at]gmail.com) 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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_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?= , Alexander Finger , 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: Alexander Finger Sugested-by: Vasily Khoruzhick Tested-by: Alexander Finger Reviewed-by: Uwe Kleine-König Signed-off-by: Clément Péron --- Changes since v1: - Fix Alexander in Reported-by tag - Add Uwe reviewed tag and Alex Tested-by tag 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);