Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1429437ybh; Sun, 15 Mar 2020 02:46:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtWubiBk2rCWWPUBoYb71H/9gTWJmAeaCDNsVoouAHJDLwNNovsawncRxTjFP8zaEVlKNcx X-Received: by 2002:a05:6830:118d:: with SMTP id u13mr11222185otq.41.1584265604653; Sun, 15 Mar 2020 02:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584265604; cv=none; d=google.com; s=arc-20160816; b=MV5AXFeal85qbz6aPEFbWKzNIb405sGjck04SmkDysP/E6SbPi7/B/stGg2jb1kx/o vDBqH0JGWGuxDhu4vdiaGLfW46WQtpjVQcrWQNswUHu0JbmkEJl2vMvDO/XZcb55it9L oKK1H4SWQfCGfRcVKqYpDarcHXCPxz4+7vjMFzIlFBaglfIyvc/i3cftcTA41NiEEjsb nOBy9XmCE4vdxpy16I9wYO7ow394vC7D+cGaxwAW3gCbl0rHr1v1FOQLLZARpQJ0gyYF wDZxaZxcOhrsk2noSgDeoeIWpe0EWEhFzELahQ0rYDfvzl3RG7ANOjOa8ZAKGTkHjwLW coEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=v21/Do1RZL8TGImMeZgb14eW5uhKX1w2TPNWV7UPXQE=; b=rXDHlgAht0w5ZNZerWZWTLz2bRM84Ar2qxt+cmIVO3rZe37EiuNWTvYH3l8vb8pw2v vc9b16qStaDewaX9Fcz4LmNLqp1uX6PSS9UQFxHVy/vwNNgRhv4ugWaRlth/4cicet7W hV40ASNqe+QlxadTOcaS9SSdzl/EivO+14sJrhtoAGyUWsjzK0WjJcvczFTCch0Qq+Jj B9DnBSVYiIGPHgprbOlg2Z+4FCqbhjVTXaBYjITuq867hT/jeFrzcB8ESaS+vWnCeXDL Y2u9avSsVc+wE01yPhF6utYmmtAyi4Q2wKcbvsLLi22JDpeD3dqeVXYwv1PtvLQdJUxK 1HLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NqUIdla2; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19si8118273oif.250.2020.03.15.02.46.31; Sun, 15 Mar 2020 02:46:44 -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=@kernel.org header.s=default header.b=NqUIdla2; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728171AbgCOJqJ (ORCPT + 99 others); Sun, 15 Mar 2020 05:46:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:43392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728123AbgCOJqJ (ORCPT ); Sun, 15 Mar 2020 05:46:09 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCDE2205C9; Sun, 15 Mar 2020 09:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584265568; bh=biUlpyrXNvCOiK31I4zc/E3yxuZCzo2qiuxd+IZSWAU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NqUIdla21Wyb2/wkO+hupZvA3i4r2MrUH5+52i5fAChTQMy5pbR+ZmWjlZPW2fclo YHcOxaC9G7ydMGE4FSk1lv5B7YQ2DkVJ9USKze+M//+CZ58eKDNbbBuFAjy8pXXBkC FniQ9c3DkmfrcdF0OnVZRqFOP8sv/L83wN56mv6E= Date: Sun, 15 Mar 2020 09:46:04 +0000 From: Jonathan Cameron To: Rohit Sarkar Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, matt.ranostay@konsulko.com Subject: Re: [PATCH] iio: health: max30100: remove mlock usage Message-ID: <20200315094604.62dc96be@archlinux> In-Reply-To: <5e668b89.1c69fb81.d7e4f.0f61@mx.google.com> References: <5e668b89.1c69fb81.d7e4f.0f61@mx.google.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 10 Mar 2020 00:01:28 +0530 Rohit Sarkar wrote: > Use local lock instead of indio_dev's mlock. > The mlock was being used to protect local driver state thus using the > local lock is a better option here. > > Signed-off-by: Rohit Sarkar Matt. Definitely need your input on this. > --- > drivers/iio/health/max30100.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c > index 84010501762d..8ddc4649547d 100644 > --- a/drivers/iio/health/max30100.c > +++ b/drivers/iio/health/max30100.c > @@ -388,7 +388,7 @@ static int max30100_read_raw(struct iio_dev *indio_dev, > * Temperature reading can only be acquired while engine > * is running > */ > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&data->lock); Hmm.. It's another complex one. What is actually being protected here is the buffer state, but not to take it exclusively like claim_direct does. Here we need the inverse, we want to ensure we are 'not' in the direct mode because this hardware requires the buffer to be running to read the temperature. That is the sort of interface that is going to get userspace very confused. Matt, normally what I'd suggest here is that the temperature read should: 1) Claim direct mode, if it fails then do the dance you have here (with more comments to explain why you are taking an internal lock) 2) Start up capture as if we were in buffered mode 3) Grab that temp 4) stop capture to return to non buffered mode. 5) Release direct mode. I guess we decided it wasn't worth the hassle. So Rohit. This one probably needs a comment rather than any change. We 'could' add a 'hold_buffered_mode' function that takes the mlock, verifies we are in buffered mode and continues to hold the lock until the 'release_buffered_mode'. However, I'm not sure any other drivers do this particular dance, so clear commenting in the driver might be enough. Should we ever change how mlock is used in the core, we'd have to fix this driver up as well. Hmm. This is really hammering home that perhaps all the remaining mlock cases are 'hard'. Thanks, Jonathan > > if (!iio_buffer_enabled(indio_dev)) > ret = -EAGAIN; > @@ -399,7 +399,7 @@ static int max30100_read_raw(struct iio_dev *indio_dev, > > } > > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&data->lock); > break; > case IIO_CHAN_INFO_SCALE: > *val = 1; /* 0.0625 */