Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2018784pxm; Sun, 27 Feb 2022 09:03:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPiXYdj4aCX/6Rvl7T2rIRS3FuikL4toHZWOkyx9khxXH6zndgHKU9KfBrJaYUwfnESqUI X-Received: by 2002:a17:906:7189:b0:6b6:1ef8:f392 with SMTP id h9-20020a170906718900b006b61ef8f392mr12412452ejk.590.1645981405611; Sun, 27 Feb 2022 09:03:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645981405; cv=none; d=google.com; s=arc-20160816; b=LUfX608NBU3Hk5MqnDZAHW1IKF0Mi39pzIAJ7yQ/cWoAanDl1sBezCn6iGRqcvJSbT J3b/KC5BzX0Np2bq63OXVn4mgWQr3usO6uJjbCIcKTrtXcgihNnmUrjZynaY3MNrIPje C2auM1A69XvGJD7H0mde9HVNpZbj8aADwVs0yb0cdLd3NWWoTKMEQG7YES08IJYugs6j J1cviWyAGObSsdNi3sKVD5jYWeirX9nKVfapVFEIqufXdTZgw++20N7B2vlTUc/OffZu K94RfuYIqv9wclmGS1wo80TKHWAsTC2tJQR6R4Z5GdsMTYBvLcULLZv9oPzsnnWDydBv H/ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=0azag6v+1uR8a4wOo4OrSJQed/Lyr2YVQstG09jLzok=; b=1JPQSodSP3vLoMp9wFf00gxPjD21qHvOFW7WzCZpJ4jEH61De0hGSiHM7q4MVqenAy xvEbVzBl42DzFVi4/lYZcRLnk2bj5s5Or51QunLsMeXCbmzzl1w0hbI48YNOprwqMz7B +AcnDBHUiYKyK1UBFeNssOnn5TbeqlTjRrySkgPth7wn8kkNZu0EtZPYCYA/hLT3yQIB 9ER7zSf2pYAev/11QSnCI5CJQirXYD9Ye+skdLnoS7/eguC+oophvNUMDkI9t0NdVNsv CsM+T4NRAkRSbapqRqd7+PeAw3xL7pULrxmM7YE3/gcmWVIl/wo9YPXD4XpBFyKCn4kW GOjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cpC96hMh; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q23-20020aa7d457000000b0041124e6584dsi5335842edr.105.2022.02.27.09.03.02; Sun, 27 Feb 2022 09:03:25 -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=@gmail.com header.s=20210112 header.b=cpC96hMh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbiB0Qrp (ORCPT + 99 others); Sun, 27 Feb 2022 11:47:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiB0Qrn (ORCPT ); Sun, 27 Feb 2022 11:47:43 -0500 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32D96D3AA; Sun, 27 Feb 2022 08:47:06 -0800 (PST) Received: by mail-oo1-xc31.google.com with SMTP id r41-20020a4a966c000000b0031bf85a4124so15267751ooi.0; Sun, 27 Feb 2022 08:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0azag6v+1uR8a4wOo4OrSJQed/Lyr2YVQstG09jLzok=; b=cpC96hMhyn1TjUGPC9TRaLCMQ4VOgWtXdO94E8dvyc920DWhOwAZbhiLrI9D6MABfH A3RHYZ2JBnqCwYdptFdIGEpRyMS9HwfwSfXousRDrQg/eBC/USbs/KZSjWiAVia/H5pL QGGAGjwSPQtapxzKW9N8JbvLpLNFKsohaJVKVNokV6EyLDLz4c9dsLvBlMm3206XTkJE TzqHcpePDEm4z4o1f4Fy+SxJx7HoXSoUZNdpBVI5x3NMq/G+3mwHZOS1lbHU1SSOPbOm 7BH/znH3bKOe8uoOynKU0Ls6pzkp5DyrPJpYfi6jFVRfBCcdyWcXA/vxnGbBsrXjtWMq uaGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=0azag6v+1uR8a4wOo4OrSJQed/Lyr2YVQstG09jLzok=; b=kWiV3YrpWBCwAo6OigoxsoBOSj4iXKn9JMLo1D13CGp3iqCwg7qc0PAweum7rzuv1C +tCEVKWRBAdrji3Uaw/iZhLnpwOsZ34PAFoGKsK93ne9ArzAGaecZXuZt8BJoajdv908 pcRo/s1o7lHJVBKHZtdGA/PaoHH3oW/ExGIkFBqOTlBFHItUmqCqwULGCbCdU0BbQ4+i fggENEAE6zR2PfSd0P+zWzujCWnPJpDwrvfUbg4qYze2FNIXFhVpl5cX/YqJQ1kXEzom AH8eKEcKFV0WkoW4N7MRY4EXO5bJ+MjSbFgccVA9eyE2D8hdh56XQ0qQl/tX2VG+vJ7I Jx6A== X-Gm-Message-State: AOAM533chfev6wVooicloo/FupwTv6F79NjG0Wx5+DXltA1kVS+PkLmE m5AqbUjslv51Txc/voEM3hionyhnBsg= X-Received: by 2002:a05:6871:80e:b0:d7:3c9:6afa with SMTP id q14-20020a056871080e00b000d703c96afamr3428362oap.126.1645980426297; Sun, 27 Feb 2022 08:47:06 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id a11-20020a0568300b8b00b005acfd19434asm3652761otv.75.2022.02.27.08.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 08:47:05 -0800 (PST) Sender: Guenter Roeck Date: Sun, 27 Feb 2022 08:47:04 -0800 From: Guenter Roeck To: Marcello Sylvester Bauer Cc: Jean Delvare , linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph Subject: Re: [PATCH v1 1/1] drivers/hwmon/pmbus: Add mutex to regulator ops Message-ID: <20220227164704.GA770993@roeck-us.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 On Fri, Feb 25, 2022 at 05:06:09PM +0100, Marcello Sylvester Bauer wrote: > 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 Good catch. Applied. Thanks, Guenter > --- > 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)