Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp637408pxb; Tue, 5 Apr 2022 16:50:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIlCR8FCdg0JVIopykhKOEr+goVmDfaPAtfXZgNH2uzwEjsyoGtnt2eDmLKV/oemKVZqv2 X-Received: by 2002:a65:694e:0:b0:399:5aa8:2845 with SMTP id w14-20020a65694e000000b003995aa82845mr4933675pgq.38.1649202645145; Tue, 05 Apr 2022 16:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202645; cv=none; d=google.com; s=arc-20160816; b=iuFVQqoKvqyx0NhcjOoyEC78td1VuZWSrxlcCTtUVGc6qGYQBYhUqTup+Ln9mbIpp+ A4we4mXyprcNsy8DcFw5Ufc+lwtUMLsWoIuIFLg5UrjtcF1FVyEMnYDzK54DeE7wvaw8 iKiCX+Mw1SybI2ijVwlEMSWtI9xInVKJjg58GZn/k3/gK5moIvEFpYTDz0YLdLPrPYGb 3H3zE8iw+X26UNm3m7bJbUxnpyagzCzaR5HZk5shXPFYqEcxEKwfNlfFKR/uZe1H/iy/ toJ+D1cZiGmLfObUXPWukTLjzcdaATgM/3HXv8SNTNAZGDZAL1eQt54fRwoJ/2kPWwTF y04g== 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=Ki0CjDNmO1BpQlxNuTJjhqSll9E0O9OJsRcMjT+P7ok=; b=o3Pi2h3ePFomLjU5nO6InA9eH8nMGLAJm6jiNlYUXu95auW8dedHcF+HQ9x4cQwPkH b2SbK1fMQl0ZcQ8koiHEFhHxMg/wW1YxLGqC+AtL51k30/hwoT44CA2Kbe8bU7ve5Mwg zx/YS4wegVqNbfQohTRsYBijdvrzkjsTdPINt8Ib6oMQ4XIwBI8oqHh5Or6IPAKK+FnN 59DYuDT+kJc0W+ye0MRrQyT3rG8EBahcq+8P8RRmCBnoeOywEsLmYDftk2IlwdpWHTag mnnAoOtK050rWmBNiHQZS8WV7I917eD0jEtD+UpJRuTZQXvhwByVknibduf4B0rpsAqO sR/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="xjGZz0/D"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s11-20020a17090302cb00b00153b2d1643dsi9808983plk.69.2022.04.05.16.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:50:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="xjGZz0/D"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF59B1AECB0; Tue, 5 Apr 2022 16:35:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348679AbiDEPLi (ORCPT + 99 others); Tue, 5 Apr 2022 11:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbiDEJoJ (ORCPT ); Tue, 5 Apr 2022 05:44:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4653CC6275; Tue, 5 Apr 2022 02:29:45 -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 2EED4B81CAC; Tue, 5 Apr 2022 09:29:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9156EC385A0; Tue, 5 Apr 2022 09:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150982; bh=GDkhXDUtppKjqDANeL6Q/shPJCjo5cy4GQ0T5NVoiQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xjGZz0/DH1+AwoDIRSHdSTBRq9ZVJ3ySjOTKccPKRxXO+MsCb+4YDdQKGWPWm0emg cewaKCqIwRERijen9j/Swrz1nYvZIpckJF7tpg382CqzofzOLT5dXVPQZpSHxY7e3Z ttruzP9UKO1Rb+wGeHBTHUB+VL8lRPaJ8tTdrWAs= 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 5.15 214/913] hwmon: (pmbus) Add mutex to regulator ops Date: Tue, 5 Apr 2022 09:21:16 +0200 Message-Id: <20220405070346.272729398@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 ac2fbee1ba9c..b1386a4df4cc 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2391,10 +2391,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; @@ -2405,11 +2409,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