From patchwork Wed Oct 12 15:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 13005147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45F8EC4332F for ; Wed, 12 Oct 2022 15:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbiJLPRB convert rfc822-to-8bit (ORCPT ); Wed, 12 Oct 2022 11:17:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbiJLPQs (ORCPT ); Wed, 12 Oct 2022 11:16:48 -0400 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98103CE9AE for ; Wed, 12 Oct 2022 08:16:40 -0700 (PDT) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29CEGmL2000662; Wed, 12 Oct 2022 11:15:38 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3k3645e13d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Oct 2022 11:15:38 -0400 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 29CFFbEs045454 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Oct 2022 11:15:37 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 12 Oct 2022 11:15:36 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 12 Oct 2022 11:15:36 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Wed, 12 Oct 2022 11:15:36 -0400 Received: from nsa.ad.analog.com ([10.44.3.62]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 29CFEunb022095; Wed, 12 Oct 2022 11:14:59 -0400 From: =?utf-8?q?Nuno_S=C3=A1?= To: , , , , CC: Chen-Yu Tsai , Andriy Tryshnivskyy , Ciprian Regus , Vladimir Zapolskiy , Cixi Geng , Neil Armstrong , "Miquel Raynal" , Sascha Hauer , Heiko Stuebner , =?utf-8?q?Nuno_S=C3=A1?= , Fabio Estevam , Jerome Brunet , Martin Blumenstingl , Pengutronix Kernel Team , Baolin Wang , "Hans de Goede" , Alexandru Ardelean , Michael Hennerich , Haibo Chen , Lars-Peter Clausen , Jyoti Bhayana , Jonathan Cameron , Andy Shevchenko , Florian Boor , Chunyan Zhang , Orson Zhai , "Shawn Guo" , Kevin Hilman Subject: [PATCH v3 0/4] Make 'mlock' really private Date: Wed, 12 Oct 2022 17:16:16 +0200 Message-ID: <20221012151620.1725215-1-nuno.sa@analog.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: r_C5qfRQbavOxvOQkH8WZcF4BbERRqlw X-Proofpoint-ORIG-GUID: r_C5qfRQbavOxvOQkH8WZcF4BbERRqlw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-12_07,2022-10-12_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 phishscore=0 mlxlogscore=796 priorityscore=1501 spamscore=0 suspectscore=0 impostorscore=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210120100 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This patchset cleans all the drivers directly using the iio_device 'mlock'. This lock is private and should not be used outside the core (or by using proper helpers). Most of the conversions where straight, but there are some that really need extra looking. Mainly patches [13/15] and [14/15] were a bit hacky since iio_device_claim_direct_mode() does not fit 100%. The reason is that we want to check if the device is buffering and do something if it is (in which case the API return -EBUSY and released the lock. I just used a combinations of locks to get around this (hopefully I did not messed up). Note that this series was only compiled tested using allyesconfig for ARM. I ran 'git grep' to make sure there were no more users of 'mlock'. Hopefully I covered them all... v2: [PATCH 1-8, 10-12/16] * Mention the inclusion of mutex.h in the commit message. [PATCH 1-8, 10, 12/16] * Initialize mutex as late as possible. Note that [PATCH 11/16] was not included since the code to do so was not direct enough. Would need to get a pointer to the private struture outside of scmi_alloc_iiodev() to do it. While not hard, the added changes in the code is not really worth it (IMO of course). [PATCH 1/16] * Refactored the commit message a bit. I guess this one will still needs more discussion... [PATCH 9/16] * New patch to add an helper function to read the samples. [PATCH 13/16] * New patch to introduce iio_device_{claim|release}_buffer_mode() APIs. [PATCH 14/16] * Make use of the new iio_device_{claim|release}_buffer_mode() helpers [PATCH 15/16] * Make use of the new iio_device_{claim|release}_buffer_mode() helpers in combination with claim_direct_mode(). This is needed so that we make sure we always get one of the modes (and hence the iio_dev lock) to safely call max30102_get_temp(). Note that I'm not particular "happy" with the code but OTOH, it does not look as bad as I thought :). Anyways, if there are no complains with it, I'm ok to leave it as-is. Otherwise, I think we can think on the flag approach (briefly discussed in the first series). v3: [PATCH 1/4] * fix 'make W=1' warning about prototypes mismatch. [PATCH 2/4] * improved commit message to explain why we are shadowing error codes. [PATCH 4/4] * minor English fix on the commit message (as suggested by Andy). Nuno Sá (4): iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs iio: health: max30100: do not use internal iio_dev lock iio: health: max30102: do not use internal iio_dev lock iio: core: move 'mlock' to 'struct iio_dev_opaque' drivers/iio/TODO | 3 -- drivers/iio/health/max30100.c | 9 ++--- drivers/iio/health/max30102.c | 19 +++++++--- drivers/iio/industrialio-buffer.c | 29 ++++++++------- drivers/iio/industrialio-core.c | 58 +++++++++++++++++++++++++----- drivers/iio/industrialio-event.c | 4 +-- drivers/iio/industrialio-trigger.c | 12 +++---- include/linux/iio/iio-opaque.h | 2 ++ include/linux/iio/iio.h | 5 ++- 9 files changed, 97 insertions(+), 44 deletions(-) Reviewed-by: Andy Shevchenko