From patchwork Wed Apr 5 14:52:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 79749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp378127vqo; Wed, 5 Apr 2023 08:07:47 -0700 (PDT) X-Google-Smtp-Source: AKy350bbw3PtZgxFh8vv56CUJiOjG19eIKUL2B0QXLxscr1TjkLLy4Zodik1/ahbcAGBt/eqaIo3 X-Received: by 2002:aa7:c949:0:b0:502:9a70:3a39 with SMTP id h9-20020aa7c949000000b005029a703a39mr2134604edt.1.1680707266885; Wed, 05 Apr 2023 08:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680707266; cv=none; d=google.com; s=arc-20160816; b=grwggqwnZb7FryeVld4CJAbRVmNgzTJbrDFH2ojym77T5GMQ748sNElZAHoAntzpUD WytBlamaH74bvb4P+rFTQwl87Kiu5Rzr9iT0XFL6ZU7CML4JWsTy17d/+jShtThce/Qj zB09iVDHA1nX9leulMeJXFg1HTyJ+83Yw1SIZlu2b5Rcigj8Vd1Oh1znest//nBWPZiK QIwrV6bei4QZKgde+cy5CVAiG0OLXYw/YHx2ll88u/F10ZqHTHRrv/HC1ii7n5LK2PGY uDY4Po56jAzJWsgsxXwX+vg4IzQlEou9bUOB8NNOTOg4p8UEVbgKx38g+htjszFoMjxE htlA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1Kpd8suCSJvpllpL/T0XrbZxPVM/IOIfz+qTGO3kGdc=; b=Y+38Z59JatMWiaYsKleHxXcJrqGFqsyPT+mr2FqrLpalXwx06FCDc60c7764ZwExZ6 K+VBMigmP5yz/eTyYkp0bqk5HV9fYqq0pl8L5dVBywoFyZ49hj+sctU8v1jzbH2iQFXu x1xyoK1FgsQoN3FFqO8m/sbOIW3dP/xuA9XAqpsyBDHNWgkGN0Hqd+oGIhFydbXKji9p o/F/wdTBOSvgteYRzBaJNc30y9P4J229RWq5NRJavMAQWkZEX8BH6Ig8mswGb+hTwTdD snimEh2RJsAGnn3j+VB7UCadMU/30HvyPBjHdiBaPSq5b/ipj7JLJ8ql9FqZxlFAikDT GX4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=XnrXTr+w; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm26-20020a0564020b1a00b004bf5fd5d860si720130edb.606.2023.04.05.08.07.18; Wed, 05 Apr 2023 08:07:46 -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=@ibm.com header.s=pp1 header.b=XnrXTr+w; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238604AbjDEOw4 (ORCPT + 99 others); Wed, 5 Apr 2023 10:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238216AbjDEOwv (ORCPT ); Wed, 5 Apr 2023 10:52:51 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822B1658A; Wed, 5 Apr 2023 07:52:50 -0700 (PDT) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 335DObjU005230; Wed, 5 Apr 2023 14:52:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=1Kpd8suCSJvpllpL/T0XrbZxPVM/IOIfz+qTGO3kGdc=; b=XnrXTr+wLChDJFRQ8m9oX5iv1ttEKP+EUYOpfIsjg5TYC//kAfcBnPxTE5ckmXOllIOj vQ6cns8bgiNOG1/XWNFaPzEUXXjJiwQVt9eINlzKfErf4FuAcRfQt66+36LQ0iSRU/92 P3kGYJ7PS8Q7VisSdJC+c8FLjrXomdELeWoWMgkT6wNC+mUOTSUP3aRPM9yew5YQ9MCF 8CH658PcJio+LOP0h2B8m0jbHDYVTt0saa67u7fCxdduiwZGgGsHp2qKOF3joVEu36Ke 1Ki1dcMyzmgO+StE3WhudXAqIxSfl6k2iWueQYUBpETtv14kzlj6MKe7mcfR7m4QbgUz cQ== Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3ps9umjhq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Apr 2023 14:52:36 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 335DN7ex031588; Wed, 5 Apr 2023 14:52:35 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([9.208.130.98]) by ppma02dal.us.ibm.com (PPS) with ESMTPS id 3ppc88cg47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Apr 2023 14:52:35 +0000 Received: from smtpav04.dal12v.mail.ibm.com (smtpav04.dal12v.mail.ibm.com [10.241.53.103]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 335EqY1S66781678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 5 Apr 2023 14:52:34 GMT Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC9E95805E; Wed, 5 Apr 2023 14:52:34 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18E0458056; Wed, 5 Apr 2023 14:52:34 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.160.127.161]) by smtpav04.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 5 Apr 2023 14:52:33 +0000 (GMT) From: Eddie James To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jdelvare@suse.com, linux@roeck-us.net, Eddie James Subject: [PATCH 1/2] hwmon: (pmbus/core) Add lock and unlock functions Date: Wed, 5 Apr 2023 09:52:29 -0500 Message-Id: <20230405145230.68631-2-eajames@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230405145230.68631-1-eajames@linux.ibm.com> References: <20230405145230.68631-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: EfwuhR8T7a6SP21RIQbmzdllcdalXsOW X-Proofpoint-GUID: EfwuhR8T7a6SP21RIQbmzdllcdalXsOW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-05_09,2023-04-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 priorityscore=1501 phishscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304050132 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762349109847582873?= X-GMAIL-MSGID: =?utf-8?q?1762349302843047926?= Debugfs operations may set the page number, which must be done atomically with the subsequent i2c operation. Lock the update_lock in the debugfs functions and provide a function for pmbus drivers to lock and unlock the update_lock. Signed-off-by: Eddie James --- drivers/hwmon/pmbus/pmbus.h | 2 ++ drivers/hwmon/pmbus/pmbus_core.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 11e84e141126..b0832a4c690d 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -505,6 +505,8 @@ int pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id, enum pmbus_fan_mode mode); int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id, enum pmbus_fan_mode mode); +int pmbus_lock_interruptible(struct i2c_client *client); +void pmbus_unlock(struct i2c_client *client); int pmbus_update_fan(struct i2c_client *client, int page, int id, u8 config, u8 mask, u16 command); struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client); diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index ca4510e4f918..04b4c65666fd 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -3212,8 +3212,13 @@ static int pmbus_debugfs_get(void *data, u64 *val) { int rc; struct pmbus_debugfs_entry *entry = data; + struct pmbus_data *pdata = i2c_get_clientdata(entry->client); + rc = mutex_lock_interruptible(&pdata->update_lock); + if (rc) + return rc; rc = _pmbus_read_byte_data(entry->client, entry->page, entry->reg); + mutex_unlock(&pdata->update_lock); if (rc < 0) return rc; @@ -3230,7 +3235,11 @@ static int pmbus_debugfs_get_status(void *data, u64 *val) struct pmbus_debugfs_entry *entry = data; struct pmbus_data *pdata = i2c_get_clientdata(entry->client); + rc = mutex_lock_interruptible(&pdata->update_lock); + if (rc) + return rc; rc = pdata->read_status(entry->client, entry->page); + mutex_unlock(&pdata->update_lock); if (rc < 0) return rc; @@ -3246,10 +3255,15 @@ static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf, { int rc; struct pmbus_debugfs_entry *entry = file->private_data; + struct pmbus_data *pdata = i2c_get_clientdata(entry->client); char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 }; + rc = mutex_lock_interruptible(&pdata->update_lock); + if (rc) + return rc; rc = pmbus_read_block_data(entry->client, entry->page, entry->reg, data); + mutex_unlock(&pdata->update_lock); if (rc < 0) return rc; @@ -3587,6 +3601,22 @@ struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client) } EXPORT_SYMBOL_NS_GPL(pmbus_get_debugfs_dir, PMBUS); +int pmbus_lock_interruptible(struct i2c_client *client) +{ + struct pmbus_data *data = i2c_get_clientdata(client); + + return mutex_lock_interruptible(&data->update_lock); +} +EXPORT_SYMBOL_NS_GPL(pmbus_lock_interruptible, PMBUS); + +void pmbus_unlock(struct i2c_client *client) +{ + struct pmbus_data *data = i2c_get_clientdata(client); + + mutex_unlock(&data->update_lock); +} +EXPORT_SYMBOL_NS_GPL(pmbus_unlock, PMBUS); + static int __init pmbus_core_init(void) { pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL);