Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1694223ybh; Sun, 8 Mar 2020 10:32:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtdO6lUCAQHyJZLvEmJuBAFe3/IaNd0ylZR/npN+/o9ZC5A/zJjcmJItF/SZN77FNzzqDHB X-Received: by 2002:a05:6830:18c2:: with SMTP id v2mr894514ote.350.1583688737892; Sun, 08 Mar 2020 10:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583688737; cv=none; d=google.com; s=arc-20160816; b=HVHYG74Rp+cm2EHceXb3bLL4SHzjXNDzO/grCg09afR/NBuDGPjmA3ghD14fNwnGMM 9HN4lIUQR7krzXM9AybGp8cn16mPs5bnj0pqHEieMHGwlqpNlbJP5kZHE9KXLWE/Z9MD z2PDlh5gOocAQ67HE6YzFq4VlwdxwXZueLmRCp7NJmLnmHH1OXTo5aw4OB4h7cn4c1gw 8o8tB8DapFBh8Msv4HtpQroWcl1JuJQ0zyOXeNUmlwEB1mXbMQZd++ftWZrAcOgGgs6v zxdoAznYfVy3QU+iDPkhXmA9r7vogrkR52wPUwW+KEjy+rj6Nilvndr8JdKQMA8VElFD qzEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :message-id:dkim-signature; bh=e9qnB7QZOlUFXtCcAkVq3BX6tJPsQ7OsVoBtR0r8PgQ=; b=uvUcX5u8v/SeRy9ZtZ2ISrruhOGv1ACeF8C6PQHvUZ/fUHYN7PYfglWGL2JcKtndbI UiYCVYTMMXs2YoKK1qRFcY7Es/fTaEskPBgwMTxynI2vF/LzfY0ixg49hZ/XEHhqxf5H 5yQloKS7dR0Rm5gESIAIvmSYoGXyRlkR5qoluDvum/pg0lb1Fe4u/lCX5KdjEc4By09c RnJd7L9WS3L3AYwXarOHfw/0wr1zMG7fqj21xuTSxGGGHJPAf/BadibFNGZdMNtzm/cB YiGMN9815jwK/yCCNgyRPMM5u4zUWcB9jYJD+RJQOZP9KB4fsGsWkmLRscCqbwi+FnAU lXdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E34oMEN1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si2900927oip.102.2020.03.08.10.32.05; Sun, 08 Mar 2020 10:32:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E34oMEN1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbgCHRbT (ORCPT + 99 others); Sun, 8 Mar 2020 13:31:19 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44600 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbgCHRbT (ORCPT ); Sun, 8 Mar 2020 13:31:19 -0400 Received: by mail-pl1-f193.google.com with SMTP id d9so3016613plo.11; Sun, 08 Mar 2020 10:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:to:cc:subject:references:mime-version :content-disposition:in-reply-to:user-agent; bh=e9qnB7QZOlUFXtCcAkVq3BX6tJPsQ7OsVoBtR0r8PgQ=; b=E34oMEN10iVxMyUJ+phXZZF8V4aBEG6HuYoJ5hzlZxHQ+uJrxSdvWNVYX2BV1VNecG 09q0A4up/lRzCKoQFUkc9OCxWS1NyJuOgBJsswREY5frlZelZnNvYA4wsB8CeYUPO2JQ AEr8nTnQnGTG6/UP6Jq3CrjSvMq029QkjkCOGEXXlD6Bpm6jazOmuBy/x1WSdFel5Uam +0NvZ6b/ayCMRFe72QMVaAV3E7nbzXy3sf0G4t5++vxudlE4b/ekJ5luzZGZIxZKr8Wu VhS08UjGDfbZl5u6FB/ZSZ95ZbKry3a30a9dec9l1Dl1lJhh+JMVrhEGeHstQdDfItWU jjnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:to:cc:subject:references :mime-version:content-disposition:in-reply-to:user-agent; bh=e9qnB7QZOlUFXtCcAkVq3BX6tJPsQ7OsVoBtR0r8PgQ=; b=Wfj2Ux+uHPi9HwUM5+/9TrpiR+1duL9OSbDVJoKgH2noievjGbL8PHwMU4Etgt5I9L kRh2SVeRBGddml+C08Hng4/u0VrLewHF6wvn2xyp8LtU+KvnEyxAmIv4dvmHtPtO3/Ia sihx8/baDnTpE7ZZ23KgH4SbPFLUcQZ9gPBctCszWDteCCYBFrAmvsmlAdA3jeI2wPOP +aKkOYfgC9HtDftxJLLB3J+es8ZN3dOLwm5OGAo/szUcIx54Lu4bErvgl4wE6ByDiMHP czhhR8G0PGK/yFJmrifZHDlEw1h3PocZMppdftREiHFiHAqkYAyRI61osm7lRGnMPG7N fL/Q== X-Gm-Message-State: ANhLgQ1VGE+twdmeUQFWAWzUWEB7vr/aGOayZL5dRmEEge8Gs1SHqdWb 6Pk/cIc9u89w9iIGxjdMMrN58hLR9tg= X-Received: by 2002:a17:90a:6448:: with SMTP id y8mr14361094pjm.126.1583688678122; Sun, 08 Mar 2020 10:31:18 -0700 (PDT) Received: from SARKAR ([43.224.157.37]) by smtp.gmail.com with ESMTPSA id f9sm15855697pje.43.2020.03.08.10.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Mar 2020 10:31:17 -0700 (PDT) Message-ID: <5e652be5.1c69fb81.bdd67.92b5@mx.google.com> X-Google-Original-Message-ID: <20200308173052.GD12716@rohitsarkar5398@gmail.com> Date: Sun, 8 Mar 2020 23:01:12 +0530 From: Rohit Sarkar To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, alexandru.ardelean@analog.com, dragos.bogdan@analog.com Subject: Re: [PATCH v4] iio: adc: max1363: replace uses of mlock References: <5e6355a8.1c69fb81.36f2c.ab37@mx.google.com> <20200307141946.79661dd0@archlinux> <5e640c05.1c69fb81.4dd6f.a3c8@mx.google.com> <20200308161426.716d1ffb@archlinux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200308161426.716d1ffb@archlinux> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 08, 2020 at 04:14:26PM +0000, Jonathan Cameron wrote: > On Sun, 8 Mar 2020 02:32:56 +0530 > Rohit Sarkar wrote: > > > On Sat, Mar 07, 2020 at 02:19:46PM +0000, Jonathan Cameron wrote: > > > On Sat, 7 Mar 2020 13:34:51 +0530 > > > Rohit Sarkar wrote: > > > > > > > Replace usage indio_dev's mlock with either local lock or > > > > iio_device_claim_direct_mode. > > > > > > > > Signed-off-by: Rohit Sarkar > > > > > > There is a subtlety in here (which is why this one never > > > got cleaned up before). We need to protect against: > > > > > > 1) Driver state being accessed from multiple places concurrently. > > > That will use your new lock. > > > 2) Doing actions that cannot occur if in buffered mode. The > > > claim_direct_mode stuff is for that. > > I did consider using both, the local driver lock and the claim_direct in > > some places, however I noticed that the claim_direct_mode internally uses > > the mlock, hence I didnt think it was necessary to set the local lock as > > well, as according to my understanding once a process acquires the mlock > > no other process can run the critical section before the initial process > > releases the mlock. Thus the driver state also remains consistent. > > Any state changes in the driver done under the local lock can still happen. > There is also a question of 'obviousness'. The driver code should not > 'care' what the internals of claim_direct_mode is doing. > That can be expected to protect against moving out of direct mode, but > not anything about 'how'. > > Hence, take them both. That does make sense, when I thought about it again I realised doing this is essentially what was wrong with the code in the first place. Thanks for the pointers. Will send out an update. Thanks, Rohit