Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp433725pxm; Fri, 25 Feb 2022 10:51:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJykGdmO0fVeHK72L7sS/8CN80Hp8tQKCv2fMw0F1IXHrvghoKX0w4BNoizoo+teJKHJYFO9 X-Received: by 2002:a05:6402:294e:b0:40f:905b:dab5 with SMTP id ed14-20020a056402294e00b0040f905bdab5mr8439580edb.103.1645815109755; Fri, 25 Feb 2022 10:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645815109; cv=none; d=google.com; s=arc-20160816; b=gi8iRDSSiw9MXbDjBLwQiTJDUndychjpQm083ey4MUYFEZ6UJr6GFF9VVlOTQ6pCTe fCPDWlLKjamXw0YzhnSqFTtLKSqEEPMc4Xv4/ueunVI1VtabMQPBWLjjsNIRYZuEbEQ+ RvYEBSRQgQ1EMYNhRrgAu2GHj1sBUqTTJzAPO3P5I3DklYCgRNV411gIO0skpt8GLCRa 5dx9FvF9I3UxcxZZpNKYeUDYgHycQtGnMqDNm7DaNJq5IDFx8w7DfSsaeQOXcRYY7LZp e4usrLV3LAYIT+ZZl7R7DPgeDr0/qMGov98qJ9UD0DOD9PAeUI3qWLQo2b/9hWCIA+WQ 8FgQ== 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 :message-id:date:subject:cc:to:dkim-signature:from; bh=ajwrqPctCAOf/kug9ZVs1DEHHuF8348gK83QTGUqptI=; b=Cs3CyCi/UuztIj4toRF3fIqImzH0xjnB+zRB5WNLGtpepV6DZv+FXIHJGSuR9/mog+ 6KLht6ZW70S1MHZb4e/eyLxvNvvxYKKYLknTlkNsThtrGVPgRcGj5hTlw91jImACJOPA L91RbfhknWOgnRk29qrGf5H82444C76ZcPzEnAQep41+Qy2LUAm1fFZEEI2bouRwmWEv RoC6jqz01ijoSCmfD9Z57UUnfVqRq09FvF/5l5H2uvnMy+5YYTugcHAWObOZr+zWjQiG RISdUxATlbybEPsVnjYSN5qJZDE5yyLAeZ6biyRNQWin52/TZyJ7Bz5BQk0ySJXr0QXI UVwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sylv.io header.s=MBO0001 header.b="KCNt/Efd"; 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=sylv.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la26-20020a170907781a00b006a7004c33aesi1891521ejc.319.2022.02.25.10.51.26; Fri, 25 Feb 2022 10:51:49 -0800 (PST) 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=@sylv.io header.s=MBO0001 header.b="KCNt/Efd"; 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=sylv.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242614AbiBYQGy (ORCPT + 99 others); Fri, 25 Feb 2022 11:06:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242557AbiBYQGx (ORCPT ); Fri, 25 Feb 2022 11:06:53 -0500 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FD19211316; Fri, 25 Feb 2022 08:06:20 -0800 (PST) Received: from smtp202.mailbox.org (smtp202.mailbox.org [80.241.60.245]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4K4vlZ0rVwz9sWK; Fri, 25 Feb 2022 17:06:18 +0100 (CET) From: Marcello Sylvester Bauer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sylv.io; s=MBO0001; t=1645805176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ajwrqPctCAOf/kug9ZVs1DEHHuF8348gK83QTGUqptI=; b=KCNt/EfdLPcJfwqy5b1g/yEK2Ah7JfyFJ7UcVVzVphXU9maItGbXKPPVSxvOj8frnHZPaZ 7i9mtV0eQpr9kRyYKJlMWGJ2OYW2aHzvnwm9yZLNBgi4VmMbgafcpxdisTLRTE6JA8N0Wr z6PwPiyfsstpCPaB4Vwua+BVtb9yO2FroH8ssrklXRUt79yqpim3DrTWyKdl77Izz1X+ht lRP7h7eTwJSH+/E94Pw6LytvcN9/FCKXbXceBaYAkVhQEUpb+/Dl1qw0ZC/S13vCkkC9Zm rZaJjN/KeBjV1aDVqajGsS7N52cmzRoIiRFn0Y8ouM2tCa6GFiYE3PgLtGbvTw== To: Guenter Roeck , Jean Delvare Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph , Marcello Sylvester Bauer Subject: [PATCH v1 1/1] drivers/hwmon/pmbus: Add mutex to regulator ops Date: Fri, 25 Feb 2022 17:06:09 +0100 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,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 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 --- 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 776ee2237be2..f79930162256 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2386,10 +2386,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; @@ -2400,11 +2404,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.35.1