From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5524F3D0A1; Wed, 21 Feb 2024 14:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525531; cv=none; b=iieDdlbQ606jP+p6kzjFKfu5owYlBACUS2yW9Zn60cgQu7u+QX59QPE1obqiH2R53E4ixMTvnsKHZulffhKc+GduiRXuDv7xtsygZ4R+vomYC2Op6SVw02+ghxxt6zw19XbmX4AaH8aRuz6iemlq/mbRBcYN8OFU/7VQYyepWJI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525531; c=relaxed/simple; bh=WGAA8e78iqAaGCCLUyHgv/Yo4FQHnKwuySJbSUB+Izk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cnpGGnhiTIeq1Ght5NYbM7irsXEP1TNPBKskKi0ItZoK7KIpLxSE+sJMBIMraloo0m5FL7BCXY22UOOI4AvBBVKYXSrHDUkGTLuU7YPQhx35Q5SBS/gKHyUvQ+HB5WbPhFcjzRRgA2BACNVtF2NHXMivAXyFcRvl4Eu4xzkUh2I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kgZbjXOA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kgZbjXOA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF520C433F1; Wed, 21 Feb 2024 14:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708525531; bh=WGAA8e78iqAaGCCLUyHgv/Yo4FQHnKwuySJbSUB+Izk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgZbjXOAv4/c47597gF5zIOSbdvW0zAlQeSNmRnGELEao6p8REQtUSeUH/WiAY71b 3F7p+P2ybPIVdFuqzew4LhMj/oK44Qa91+kXV6RBXccRP0legYBhq7p51IqICgZj9K 7TQ6gC/akpoq0UIdUUAFcv8Pl7yYIpEgh8g+zo2Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Loic Prylli , Alexander Hansen , Guenter Roeck , Sasha Levin Subject: [PATCH 5.4 184/267] hwmon: (aspeed-pwm-tacho) mutex for tach reading Date: Wed, 21 Feb 2024 14:08:45 +0100 Message-ID: <20240221125945.900302654@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125940.058369148@linuxfoundation.org> References: <20240221125940.058369148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Loic Prylli [ Upstream commit 1168491e7f53581ba7b6014a39a49cfbbb722feb ] the ASPEED_PTCR_RESULT Register can only hold the result for a single fan input. Adding a mutex to protect the register until the reading is done. Signed-off-by: Loic Prylli Signed-off-by: Alexander Hansen Fixes: 2d7a548a3eff ("drivers: hwmon: Support for ASPEED PWM/Fan tach") Link: https://lore.kernel.org/r/121d888762a1232ef403cf35230ccf7b3887083a.1699007401.git.alexander.hansen@9elements.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/aspeed-pwm-tacho.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index 40f3139f1e02..dca5d3bf0629 100644 --- a/drivers/hwmon/aspeed-pwm-tacho.c +++ b/drivers/hwmon/aspeed-pwm-tacho.c @@ -194,6 +194,8 @@ struct aspeed_pwm_tacho_data { u8 fan_tach_ch_source[16]; struct aspeed_cooling_device *cdev[8]; const struct attribute_group *groups[3]; + /* protects access to shared ASPEED_PTCR_RESULT */ + struct mutex tach_lock; }; enum type { TYPEM, TYPEN, TYPEO }; @@ -528,6 +530,8 @@ static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, u8 fan_tach_ch_source, type, mode, both; int ret; + mutex_lock(&priv->tach_lock); + regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch); @@ -545,6 +549,8 @@ static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, ASPEED_RPM_STATUS_SLEEP_USEC, usec); + mutex_unlock(&priv->tach_lock); + /* return -ETIMEDOUT if we didn't get an answer. */ if (ret) return ret; @@ -909,6 +915,7 @@ static int aspeed_pwm_tacho_probe(struct platform_device *pdev) priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; + mutex_init(&priv->tach_lock); priv->regmap = devm_regmap_init(dev, NULL, (__force void *)regs, &aspeed_pwm_tacho_regmap_config); if (IS_ERR(priv->regmap)) -- 2.43.0