From patchwork Thu Jul 5 12:34:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10508875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 688926028F for ; Thu, 5 Jul 2018 12:34:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55BBA28FB5 for ; Thu, 5 Jul 2018 12:34:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4770C28FDA; Thu, 5 Jul 2018 12:34:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 138A928FB5 for ; Thu, 5 Jul 2018 12:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753884AbeGEMef (ORCPT ); Thu, 5 Jul 2018 08:34:35 -0400 Received: from mail-eopbgr680042.outbound.protection.outlook.com ([40.107.68.42]:39072 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753824AbeGEMee (ORCPT ); Thu, 5 Jul 2018 08:34:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3ThwNZaWssPaBp0s7ZeTZszawY+usmPHiGR9xw5UHak=; b=JGzrVgkiIS5K8Q1jY4d6DZQk8SCFJ2OdCkTdW2mJLQSrgP8ZmOtwuxPS8yPIicv+tUMf7RP7LvAbyIxNpc/l7mfZpV6w6FcUcu7uPIlh+pjwy6/vyQYvbdqZek5j+krylzrs+UPvqIQM/cjn6mAMhFgYC2QoCv23ovfY3LiJX1M= Received: from MWHPR03CA0044.namprd03.prod.outlook.com (2603:10b6:301:3b::33) by BY1PR0301MB1224.namprd03.prod.outlook.com (2a01:111:e400:510f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.26; Thu, 5 Jul 2018 12:34:31 +0000 Received: from BN1BFFO11FD004.protection.gbl (2a01:111:f400:7c10::1:193) by MWHPR03CA0044.outlook.office365.com (2603:10b6:301:3b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.906.25 via Frontend Transport; Thu, 5 Jul 2018 12:34:31 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BN1BFFO11FD004.mail.protection.outlook.com (10.58.144.67) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.820.5 via Frontend Transport; Thu, 5 Jul 2018 12:34:30 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id w65CYUai000772 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Thu, 5 Jul 2018 05:34:30 -0700 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.301.0; Thu, 5 Jul 2018 08:34:30 -0400 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w65CYS6N018419; Thu, 5 Jul 2018 08:34:28 -0400 From: Alexandru Ardelean To: , , , CC: Alexandru Ardelean Subject: [PATCH V3] iio: ad9523: replace core mlock with local lock Date: Thu, 5 Jul 2018 15:34:22 +0300 Message-ID: <20180705123422.18786-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(39860400002)(396003)(346002)(376002)(136003)(2980300002)(438002)(199004)(189003)(77096007)(426003)(476003)(5660300001)(7636002)(106002)(305945005)(26005)(2616005)(53416004)(50466002)(186003)(107886003)(336012)(478600001)(48376002)(486006)(7696005)(44832011)(86362001)(126002)(14444005)(2906002)(2201001)(51416003)(47776003)(106466001)(1076002)(246002)(110136005)(6666003)(8936002)(316002)(16586007)(50226002)(36756003)(8676002)(4326008)(356003)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0301MB1224; H:nwd2mta1.analog.com; FPR:; SPF:Pass; LANG:en; PTR:nwd2mail10.analog.com; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD004; 1:7Am4zmZsfcLCQOtGfgPxFn7d+FcremIMmHJ5o4LjmagzflV9YSqDYZywzRbEXMmWwzs2mJ4833RWp61Be5wjUDmi/9bSEeWCJdrPHcgl9EZxy55Okj+siuL5OLg8n/FU X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0c61915a-7671-444c-58fd-08d5e273a7ff X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600053)(711020)(4608076)(2017052603328)(7153060); SRVR:BY1PR0301MB1224; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1224; 3:QAQqNqSNTqtG+AlGWEXESMoXQN5l4SEDYBbGYIFLQkvDEYbl7kysxz+msGD7Vq94u0wG0Kp7qbrWwWYtyWigOBCj5FGXs7Mc9hVh7OZ/JpDL/X8l0fBmWn3pTKAEpYJHioBKV1a9JaHLPu6j3AGS9jQCANCMqiYxt6rS/S02dKCOOCv5yRG8DJ2uEPHW/muNJNi0pmAE8p+AGS8k1cJsXYojr9qH+fZN8N0TzUKAqepLfTz9GMxbWdLLMSjlSSKfF++TzqSaT2GVZRVqyFXUwuU4mCe3nbaaZROx6Pm+fquzPeazh0xH3eRYwcJqN8hQMBinDWEFLXraQnL7INFdqoiCoelleqdyNX9HfKBvoPA=; 25:NO4aHSJtehYrYuiC0uLykWdeXj91bjgm5TsDI4PkO4NiZKQT+IcMNr/2HyNdciSNGod4cgFcvScA6fJnjAHYMr1RtjTqpL6kb9t1TtYOb6L/SAAYSAxpnJRTqkG2YYD+Und16k/UZv6zme+iYOkb7xxiWaylz9ALSj3SUm1hm4FbwwjTuhX/TuAwhXnowizBvDtbQCGSp2Cz+EYakGlHO9wM3NQIcd7sRhTd5XmuoxOmIswpdmc6bsMoIVpxUK6Zm+cPRbhUOquMtcpUc2//OsBnEY3naFct6uMRq2mNQxdCxcspZONXCXbAF2gBZd5NucphbIPW45I4TlGr1W/kdA== X-MS-TrafficTypeDiagnostic: BY1PR0301MB1224: X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1224; 31:mx2qeY+MpI7/3IfA5tTLAnT3m//r9z/ntWD6dABMthE9HTDAt/My3FRNjjtM2TDVSs5HlARi4US5q7fRU0h56Xro8wxRkljaPUUCVHfnLNB7mmcdIv84bsmeQi29Su0gs9qa6zmUVBoaxwiB6X60rTyLA3ejHeBOWRWKHE+5K2D8xoAaYmcsE+/hnmSWy9Q9sQIy/83s2yIUB71Sr8CRdDHluce9MpjJbB7NUgOxb7o=; 20:Q3VAeUNo8IxuazC3W1rRTeH5LPuxz+QoRmNejbfYG7ImmM6oeEO0OSFF9e7DCVFkaG6Wzo+WHLLjJ7RrS+19fNMxJMIUjqktaK0HotoLVQImy1OIivy0XhCDDyodVPIjXSo78pTX8rglL8kZOQ3402ZEa7yiD+SLsTdLFga7/NqvpBEGSdc+tnnDcXWLyd1ia0urLKlkdPQ9btBh6mNDCapvZ0vjUa8IBojVPgj33lSKaflxrw41ORbVCZXqwBV6mK0h8ahkCCl86NsI1K88uZW2cEDpPnHf6104y3fbP2doy04jg1JYXaQmi1wWM6kmXwbTO7emQ/Fg9w6h2io2FEYdFmICJeQIqeJlgJHQmn5WvNIuF7v4/cdpZ8HXiSHgHEhpvZiFlk4qA02KuPEcZteTYIX5/+4Xz/RDjufL4WpJO2ewxsj5eNq2akHzcjqrx9RHN/uJVfNZ7xG1l5NVQT6UCjb7pMzqOZLH0b4OJ4tpABLkmgRQbx3GO5FIcWmp X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674)(788757137089); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93004095)(10201501046)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:BY1PR0301MB1224; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0301MB1224; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1224; 4:+DJ04Ff8USqysA/TuHwoeHs0Tv5hjKZDObO5cQtNog9dPl8QlA6owYytoivRhIiOo/51So7quMqwtcgs/7gC7TE1OsOU2+k+UvSc+TyzNj0Ndw4XnnlflXzn+AimIIyR8zVCl6/6XY9Nu/mVHPIGuVSXiUalt6NqbBmGdzLidBdeZ/gVZoL93rEOPI8rUYBYZwG6ChWc4EMuVnuYX8/ZFW4rkxQsFI9h0vqgKe4uhbj+j0gJzSRe2Rq5adDm7HXD4+oR5wO0w3acyc47ITDLiXsY5aRkK02Af0TLivIo42JX5X11N/L/coah1JBYLkSDy1fgZBmf7xQ4igwMhwlCzNXByWlxvQlqrSi2BTb78i4= X-Forefront-PRVS: 0724FCD4CD X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR0301MB1224; 23:h2Yx0VJHgzTugdgbmubp4FqKkAp4T1n0vE+gHDs?= =?us-ascii?Q?fMbt7GkrG9vnZX888v/ObeW+ZdTSIqC6ZInqiL9QFroZZkdIgowMuVDLC2Ah?= =?us-ascii?Q?IA5WpXFmf0fEGUHj3WqU7okD1jcBDhXKPHSLP33je92zTPvgikKvSLanLEGa?= =?us-ascii?Q?e6RlV7LGo/ThMUYDIQ8EAzYLLnCZOyOpe8u9k5ipn29QUfZCEXUPZzTo1uPv?= =?us-ascii?Q?HUgmYqtvn9TAIQZwfzkxv5pTuSlzGqztOvifj41QAszSMq9QN6ngxK529yCC?= =?us-ascii?Q?ebZhxK9uSF3EB2QTQXb04TdJS3JvjndNycfmZC32U9IxssXWu5S8RxffSQdJ?= =?us-ascii?Q?/yeS4pIyV1drpEzqiL19GZ9xHj3l+x9diaROz+XOawNIb8KI4OLDVjIPHfBc?= =?us-ascii?Q?MgmiOc/tpr6rShtK51ko8mRdYlXmO57jWhV1VvYl7yUshl41nEIcxlcoDFpy?= =?us-ascii?Q?BBpDYjo0+9sVZprlqUeOd2eRXNYNlMO2p0HS0sbCXPYmBRC+YCCul4zYlOxg?= =?us-ascii?Q?IWqdG2PeRRa9jPC1vOInHC+FmEcdSUUMrp1Tm1tDuc+LqgKYMNrRRy5qAg4k?= =?us-ascii?Q?LljkDvfFwxwo932Kq7qQLHgglknoWJB2vAomZnj8vGuABnVK/DLGC2YaNzzp?= =?us-ascii?Q?fpxZxxA9ua70GsBLzwSrcscbWU1nSMa9ST6OW9+6FwY70MSf3yZ5TOwkVPGR?= =?us-ascii?Q?SnwuiSRhUy9JZRXSmHLPJVC4sMP8gLtN7R1tntq9qE82B4sVBjEXBITyHbVt?= =?us-ascii?Q?KIHQBS4k7CUmDQnaoTSlb1a6mcK7UnQrw507OkOEt3dXI7EvuoNjoVLTpKoR?= =?us-ascii?Q?Zwg+otefJ0sYQU6T5/liQL/QrNQ7l+E1DGp8brVPBV0uznFccpxpXqxercv8?= =?us-ascii?Q?e7dV4oTGKnJO4pbqveBUXRva/9hwgune+lJCivoP5Gn1IYkBdKQWkMsVtb+O?= =?us-ascii?Q?Dcmwn8QMOLXxQRbDXTSweozeXd18vEdB95k3JTA2uctu7f4Ha6XUGm64S04H?= =?us-ascii?Q?CdDQUl46vNkzVW68MSUQtYll0uP9xkZywf+sD6kNPBLKDY+dBHiRKLWLWN4c?= =?us-ascii?Q?SN0tF0EQKqzx7rz6E4IT0GdLBg6cH?= X-Microsoft-Antispam-Message-Info: /QGCAs2ECvfqZ9N2TW+aKZ/hUScxRMbkzPV7WEwzHkejhSvfTlYd4LBIeaz7EcVNTqezwMOpYKtK8Q/NNy5u6ml/pFfRTxWGcrJt5BTBkdz7BVMSU3JzIXUa/I8+hGvrjOLwCfNnM03IDgckbq4Yqmr+ha9gfK66q17fkPTp/t+jwcjfK4piqtvydJ7NMEqlZy30eA/II0bEWEv/VczGi9Plfm2es19uOm0IID1yFHPUKc69p6Wcn763LrKgF+2u6cFilg6g6+g5Zvth3WEzQvt3iG1MXtwtK61Zj9VOfX9rEqkPlQkaQSRx16NW930XiYByBaGvhZqgH9zK7suQmESfIxz0B5/oZyKorS9KECU= X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1224; 6:ZDHAhbv2XPbc8cQJBMiBHQpwJPlS5UJ5AxSVy6KK92Yar6V1w9bVxb4d6NUA+Z9bmHWcuHz/GGZK2mWGML3WE/hdP/rCrDMV3zf0aDudF8vTOWSxc5UPIu7m5ojHn/pEfRrNFyiGTpWto+/G4oOSpcRFUXtw068f0qbuubBY5+mVxnZaAHXtPD4dDYIjIRbduiaBoykMWrn+uRjrUQz07k64kxWleRkrLcgUKJz3S2Hh6W6WnS0Wp79RJOPZNSAlg3x0Zy1tztPhVYwcGVXcrwUAqHoHljO1ZT+/jHNXJFZrekzA+Pe/QBDT4Mjqt1TW7ycx0y0IOQ+DYoQqOIYEChqf66rfiSTeA0RAyx9cMN/a0NTc3oPa8YZyhHHsBiBzUqmOpawlUOenCpxtstPunlTiXa/GZyrhD+2zMEg1D7kA2TbN0Rg+RFCpD6FXDEX5YAf/xhTWUMarMzAUfnSbgg==; 5:LY8glDn/bq130L5t+pWK4pX4vaVodkUIdEdpmjvdsC+3/SZ6p7meqMcJlcTi/ag05VClFq1giks6F0sak21avQpuHKFwjZ7A+XFLiX/d2wFT3sbFGwCHngx+H59edai8Vju0erO5M6yAbeSCmcm8nE7IcPtWqtJwUWPJoWs+chk=; 24:tMUaeI/RYhCaV3ts48B1I81Fvmn3kaJn2TIVnq6iSQImD8KpKTHwUCOXqoo/qfnNaWvjpqSLZt8tDwULibg65GTF2KxEC18HhAVFqOqenc4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1224; 7:XW4w4maIdAO+EKlM+znH+0AZDppBpyWanK/t/BmBCsPEuq3+gD2MEwr94BQIegsRCMmPuVdDeqZF23cdGfOLcCDhmpwzP+Yllke95dq4PmYjivs5bPXdOMRrNjIGuTTTnfYFaWo1gfqud6LP/K9eDU5+w88QdoLKpiLkkXv5UhxD/YRqPk3TwfuRO6v1wLnryCNu4x9/jA42qufB+95ygXOY/wqm1WeKkUe0yB6x7XLWtJPt23mKc8LmjTcnxOV3 X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2018 12:34:30.8879 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0c61915a-7671-444c-58fd-08d5e273a7ff X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a; Ip=[137.71.25.55]; Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0301MB1224 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lars-Peter Clausen This is also part of a long term effort to make the use of mlock opaque and single purpose. This lock is required for accessing device registers. The device may be accessed by multiple processes at the same time, and this can result in inconsistent data, where one device reads data before the other one has finished writing. Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean --- V2 -> V3: * added description about the impact of the change drivers/iio/frequency/ad9523.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c index ddb6a334ae68..8fb4e5890713 100644 --- a/drivers/iio/frequency/ad9523.c +++ b/drivers/iio/frequency/ad9523.c @@ -274,6 +274,14 @@ struct ad9523_state { unsigned long vco_out_freq[AD9523_NUM_CLK_SRC]; unsigned char vco_out_map[AD9523_NUM_CHAN_ALT_CLK_SRC]; + /* + * Lock for accessing device registers. The device may be accessed by + * multiple processes at the same time, and this can result in + * inconsistent data, where one device reads data before the other one + * has finished writing. + */ + struct mutex lock; + /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. @@ -500,6 +508,7 @@ static ssize_t ad9523_store(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + struct ad9523_state *st = iio_priv(indio_dev); bool state; int ret; @@ -510,7 +519,7 @@ static ssize_t ad9523_store(struct device *dev, if (!state) return 0; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); switch ((u32)this_attr->address) { case AD9523_SYNC: ret = ad9523_sync(indio_dev); @@ -521,7 +530,7 @@ static ssize_t ad9523_store(struct device *dev, default: ret = -ENODEV; } - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return ret ? ret : len; } @@ -532,15 +541,16 @@ static ssize_t ad9523_show(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + struct ad9523_state *st = iio_priv(indio_dev); int ret; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); ret = ad9523_read(indio_dev, AD9523_READBACK_0); if (ret >= 0) { ret = sprintf(buf, "%d\n", !!(ret & (1 << (u32)this_attr->address))); } - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return ret; } @@ -623,9 +633,9 @@ static int ad9523_read_raw(struct iio_dev *indio_dev, unsigned int code; int ret; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); ret = ad9523_read(indio_dev, AD9523_CHANNEL_CLOCK_DIST(chan->channel)); - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); if (ret < 0) return ret; @@ -659,7 +669,7 @@ static int ad9523_write_raw(struct iio_dev *indio_dev, unsigned int reg; int ret, tmp, code; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); ret = ad9523_read(indio_dev, AD9523_CHANNEL_CLOCK_DIST(chan->channel)); if (ret < 0) goto out; @@ -705,7 +715,7 @@ static int ad9523_write_raw(struct iio_dev *indio_dev, ad9523_io_update(indio_dev); out: - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return ret; } @@ -713,9 +723,10 @@ static int ad9523_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, unsigned int *readval) { + struct ad9523_state *st = iio_priv(indio_dev); int ret; - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); if (readval == NULL) { ret = ad9523_write(indio_dev, reg | AD9523_R1B, writeval); ad9523_io_update(indio_dev); @@ -728,7 +739,7 @@ static int ad9523_reg_access(struct iio_dev *indio_dev, } out_unlock: - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return ret; } @@ -967,6 +978,8 @@ static int ad9523_probe(struct spi_device *spi) st = iio_priv(indio_dev); + mutex_init(&st->lock); + st->reg = devm_regulator_get(&spi->dev, "vcc"); if (!IS_ERR(st->reg)) { ret = regulator_enable(st->reg);