Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3984884pxb; Tue, 19 Apr 2022 14:11:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywi/BVO5KHbiL/d+2fMvDUawZ9DNuFu7fUIBP3ZqpEx3QeKLgaWVZ16+TVEsh4FHyfMNyK X-Received: by 2002:a17:902:7445:b0:158:4bda:a594 with SMTP id e5-20020a170902744500b001584bdaa594mr17527784plt.16.1650402716559; Tue, 19 Apr 2022 14:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650402716; cv=none; d=google.com; s=arc-20160816; b=B1wqRZLy8j2+icNni/v1sfxAEOnyx7bomHHYa8uWA0kWdfksma0ooKatE1bOu88stV lt/AKN/OjS1sk/D2cLV7emt0zKYMP0Tvn1G97QYm6+c/RLwgQ09WqpEFzjMJnsOz6qGL qZKx4Cnerl7wWW1UOFIrMCV61IfQXdL3LEOJyw6r3PfUAf/7j4w83CSxe2wni8+ikeMt wvYS5VnF/ZrIQH6FyhDVGTh9E3+Zwfo1eV8e3Q9QgCBcrkJasze3LCJnxjJK1o8w+4JY C4YdF0ZBnAFjRw28u3vI9gIArqwhIIsW6k8zbyK0c3CMjYYw9tK1GzOWAD1AcVK3JXOn 1Nbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kl/tFG8Cm7QPIPR0INHIMpN3p3SX8E6n2Ol6dv0SnNE=; b=dG6kShI+mJdxt6dqcDkzHtEwB9hNo5Dljp/Mw/pdH3tkHkFr/oB/1BsoSb5k1v/f4Q Lsirm/irxA/bigLqkU6U4pFhylic9wpGBMxTL/Si6/+WYweubJ1w2v3sia1MlW2Y7oia 6Jq7LNElTQQU9c2NNVlnznh7ZjtkYIWVJ4N5CpFmkSpzAHwXAHHLpc/kB+wVOIx9TRCv 51Jwvgy7/eAnfpRZ+RxoPK597S1bcEpACdsw76ZM3kXWBrD+KxpfTXFftWLtKdWhf4j9 1GRbUZUlN4tNfzgDrFCT8MarpWLm+jhZEaP61fb8Xw57HDxye/k/fbAWKcbF+nPE3CAr oG7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UoqpJnaP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a170902e84800b00158b259cf77si359228plg.169.2022.04.19.14.11.23; Tue, 19 Apr 2022 14:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UoqpJnaP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242262AbiDRNgs (ORCPT + 99 others); Mon, 18 Apr 2022 09:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243775AbiDRNK1 (ORCPT ); Mon, 18 Apr 2022 09:10:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E7B38BE6; Mon, 18 Apr 2022 05:49:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 37EA9B80D9C; Mon, 18 Apr 2022 12:49:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A41BFC385A1; Mon, 18 Apr 2022 12:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286195; bh=Z+memAqozLRat+c4a6Ee/jBxhRozmCAnZLdoYOh8JHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UoqpJnaPg7LYlsVS3CfayeQKxLVOyCKvjnpMdHJFRCrlk9Y9ieN4YMkLG/xHyoq3w 7TWac5XwGenvi6g6mFz7nNhPwbKfNOYB4lT/BZr/laaR6GPXAlRxMyigqbrwgIgKtE 3L/P2uqoYZDHij19qgpi4g0jPIYK7lewvcTubPvc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Patrick Rudolph , Marcello Sylvester Bauer , Alan Tull , Guenter Roeck , Sasha Levin Subject: [PATCH 4.14 058/284] hwmon: (pmbus) Add mutex to regulator ops Date: Mon, 18 Apr 2022 14:10:39 +0200 Message-Id: <20220418121212.343156460@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Patrick Rudolph [ Upstream commit 686d303ee6301261b422ea51e64833d7909a2c36 ] On PMBUS devices with multiple pages, the regulator ops need to be protected with the update mutex. This prevents accidentally changing the page in a separate thread while operating on the PMBUS_OPERATION register. Tested on Infineon xdpe11280 while a separate thread polls for sensor data. Signed-off-by: Patrick Rudolph Signed-off-by: Marcello Sylvester Bauer Link: https://lore.kernel.org/r/b991506bcbf665f7af185945f70bf9d5cf04637c.1645804976.git.sylv@sylv.io Fixes: ddbb4db4ced1b ("hwmon: (pmbus) Add regulator support") Cc: Alan Tull Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/pmbus/pmbus_core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index cb9064ac4977..66c72aedde5e 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1861,10 +1861,14 @@ static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) { struct device *dev = rdev_get_dev(rdev); struct i2c_client *client = to_i2c_client(dev->parent); + struct pmbus_data *data = i2c_get_clientdata(client); u8 page = rdev_get_id(rdev); int ret; + mutex_lock(&data->update_lock); ret = pmbus_read_byte_data(client, page, PMBUS_OPERATION); + mutex_unlock(&data->update_lock); + if (ret < 0) return ret; @@ -1875,11 +1879,17 @@ static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable) { struct device *dev = rdev_get_dev(rdev); struct i2c_client *client = to_i2c_client(dev->parent); + struct pmbus_data *data = i2c_get_clientdata(client); u8 page = rdev_get_id(rdev); + int ret; - return pmbus_update_byte_data(client, page, PMBUS_OPERATION, - PB_OPERATION_CONTROL_ON, - enable ? PB_OPERATION_CONTROL_ON : 0); + mutex_lock(&data->update_lock); + ret = pmbus_update_byte_data(client, page, PMBUS_OPERATION, + PB_OPERATION_CONTROL_ON, + enable ? PB_OPERATION_CONTROL_ON : 0); + mutex_unlock(&data->update_lock); + + return ret; } static int pmbus_regulator_enable(struct regulator_dev *rdev) -- 2.34.1