Received: by 10.223.176.46 with SMTP id f43csp807256wra; Fri, 26 Jan 2018 07:14:09 -0800 (PST) X-Google-Smtp-Source: AH8x226BGh3QjTNjP2tqwFXy1sajUbWyy5KRVwZbXBe0x5lv54UurrMz46ST9hvbk9g/Fa+8VkYc X-Received: by 10.98.133.193 with SMTP id m62mr19734816pfk.18.1516979649120; Fri, 26 Jan 2018 07:14:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516979649; cv=none; d=google.com; s=arc-20160816; b=ajUFyxbJjBLGDlCGsDDEjVeOnxek5SNDkxllSYssk5Oepby6B1G7JuIY5nJGW9ZRZ1 T6lXFxD1bWMIoNAy5A2Lr+ol1/d9GW+ikdkWlumd13XP7cfOD/fNnq7N26wV+Aihf5nD ZU7kM9/+tgOwDGdH3WMwj1bAxbKAa6o05jeTLPOEw4g8SypYOVPghq4l/IkDd1aABVFS pEoZTwCq41PJYhsNrV5RNr/7DBdUMlTPe5m0yWhUAmxicpKBOrOU4ZZGAC6QGZ5jDiQW pYjtVslAr+L7LJhxcEGYhjGKe24mcQfSRhB5QEb5+nxcNJIB3AqrW4Vgm7pX1MKrg61K wr6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=s96mindnzfAD+f21sHlOTro871DB546sn+cvEbB8YxQ=; b=jz5a7NDKVpDkWHpAOF/SHfykpkgZnGL7VTZLdJjk0jIdCHa2gROSWD9z8OlZDoQ6+f yd802JpzpUbaTF/7eWwcp36luNtm9+UmzlWZ1JKweW+Ipg2r0Aw/kUIu9wGJQ82ONxHh a8fIrikj3J+CSPentkvvVeW92B58mKLZqjwlx34YLH/NNSYMtVwa+gE38nzmimN0nnwQ qT+cOEIBcz2nZbr3h8C9k9Xl1bjnCkQ59w83hSc43KgLTc5iYV5cbusDECuCLtZACRlE 4Pude+hGacIh7qJZqOMDcg9YGuciAM/oz2YoOT3o2OV1TPkyxq1xIE63YFgM6AMxXLqX lN4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si3115455pgo.66.2018.01.26.07.13.54; Fri, 26 Jan 2018 07:14:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932075AbeAZPMt (ORCPT + 99 others); Fri, 26 Jan 2018 10:12:49 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:43157 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753517AbeAZPMm (ORCPT ); Fri, 26 Jan 2018 10:12:42 -0500 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w0QF49q9018425; Fri, 26 Jan 2018 16:11:55 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2fq4dds8ch-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 26 Jan 2018 16:11:55 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9EA6531; Fri, 26 Jan 2018 15:11:54 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 721BD2CE3; Fri, 26 Jan 2018 15:11:54 +0000 (GMT) Received: from localhost (10.75.127.51) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 26 Jan 2018 16:11:54 +0100 From: Fabrice Gasnier To: , , , , CC: , , , , , , , , Subject: [PATCH v2 2/8] pwm: stm32: protect common prescaler for all channels Date: Fri, 26 Jan 2018 16:11:33 +0100 Message-ID: <1516979499-3665-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516979499-3665-1-git-send-email-fabrice.gasnier@st.com> References: <1516979499-3665-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-26_08:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There may be a race, when configuring two pwm channels, with different prescaler values, when there's no active channel yet. Add mutex lock to avoid concurrent access on pwm apply state. This is also precursor patch for pwm capture support. Signed-off-by: Fabrice Gasnier --- drivers/pwm/pwm-stm32.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index 59524f9..3ac55df 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -21,6 +21,7 @@ struct stm32_pwm { struct pwm_chip chip; + struct mutex lock; /* protect pwm config/enable */ struct clk *clk; struct regmap *regmap; u32 max_arr; @@ -213,9 +214,23 @@ static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; } +static int stm32_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) +{ + struct stm32_pwm *priv = to_stm32_pwm_dev(chip); + int ret; + + /* protect common prescaler for all active channels */ + mutex_lock(&priv->lock); + ret = stm32_pwm_apply(chip, pwm, state); + mutex_unlock(&priv->lock); + + return ret; +} + static const struct pwm_ops stm32pwm_ops = { .owner = THIS_MODULE, - .apply = stm32_pwm_apply, + .apply = stm32_pwm_apply_locked, }; static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, @@ -335,6 +350,7 @@ static int stm32_pwm_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; + mutex_init(&priv->lock); priv->regmap = ddata->regmap; priv->clk = ddata->clk; priv->max_arr = ddata->max_arr; -- 1.9.1