Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2353067ybh; Mon, 16 Mar 2020 01:22:34 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtNq3cP6xsoDuzDbFojuP2VpGrEk7L63HLCGMlIfqlCLDcWPxcJZB65UClwmT3VVM7MwBXm X-Received: by 2002:aca:dc8b:: with SMTP id t133mr16695471oig.98.1584346953979; Mon, 16 Mar 2020 01:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584346953; cv=none; d=google.com; s=arc-20160816; b=KzbGgXWZMQv8rHs6zsH+ODNWmOnMtEwMg8+5B3zaKRiXSbgbecJUu1GZq6ldt5IMMn nJ1TrSlX3VCiKWjJD/Ch3hutUzHHv4WgxUtshi4DnvrEhgt5AX5bd0dykc7iG7APS3fb ZR5zTnArfIBVHx5r7o6JoMoPJ0xH0idZF+Ek/g5HUMbSwuJ8S09goibt+aP7Pr9b1ex3 5GX998NeElXGZREMvAo54cfpDY6u9GENL3U06KA9QRngtS0uGwrDuc/5cDCoRc42yPe2 Goh/lfHmO9MgCiYMs637PLO/OLjbYV1TvAb7uWo0xgjmnzfObT3YtlMUHapRIbNTpJY0 0Kbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fZYO6PdRUaR2GzeYHtNLWRoMQgJ9+WJyqfFclTBz8Is=; b=JfjFCVoIApnrRzYHETarcXUvtXm0yOSgMnG+/9Ne49vGu+fgMaEOD5XPzPlyEQby3H t3keRwpKZcB/5HhMiHl51cvQQb8DJWGPv+mmIGq+PUVlkZNTQYSAkmsvmU65nfG3+P9b TPMLVuExEiy+pwvetZltE3eKbrP3nbiGVxeBUWmg7T6fEBsDBQbBlkK+YMWWUYTAsYAd BiEaQl13vJty632F4+rIB5cykemYbi6ufBPAgHbQc08aqHFEkt8rQub90sGSj0fIhg4R CJxlkyn0VQTz0GEJguiHLNDN2/y2UYb5ihXts6z/WQdUgwrCgURr8stRVjOVQuvU1MIO yedA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=Qdlvvbcj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si2074499oif.202.2020.03.16.01.22.20; Mon, 16 Mar 2020 01:22:33 -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=@konsulko.com header.s=google header.b=Qdlvvbcj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730103AbgCPIVo (ORCPT + 99 others); Mon, 16 Mar 2020 04:21:44 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:35474 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730026AbgCPIVn (ORCPT ); Mon, 16 Mar 2020 04:21:43 -0400 Received: by mail-io1-f65.google.com with SMTP id h8so16207990iob.2 for ; Mon, 16 Mar 2020 01:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fZYO6PdRUaR2GzeYHtNLWRoMQgJ9+WJyqfFclTBz8Is=; b=Qdlvvbcj/qr4QzRGGZQWnxl9bC8JQb/EovzyCFwHoSeSq0PfsxKGU8msQitfHR6YHd JmAOwBxsdqyoTq07A6d+nkzEJxEhdMMOyC6iUvMBxrmz1c6j8VU6IGatnTIaD5zEWRMe DjkrQkqHgcGbO6Th22lb92dvS9hAWERdo5K+Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fZYO6PdRUaR2GzeYHtNLWRoMQgJ9+WJyqfFclTBz8Is=; b=e5JicvrIia8G4t3eAU3ez+i7SW70rr2oWWDvQQm70FIT1t/up2nkxapynKfN78GI/+ O68RTmicWSEVj+7WPqiDzR33ndYAeWfbn+FYAvpkPBRhaPI+Iypk5Z8cv7q42eA/W6zc tTaSemscqlSbRFK22YFIoTjt45epMjzSkXnsnDMe7SLiaC9z7VMiJLRbf1UAkap2BZMU 8BlOFBGx8Xy0+UcU+uhlTrtTFfVHZH0y/caSf8Z+U5lNID2brrO9hy+Sa4/jinXx04Ax UP0AOSZtJ923bqsDhLW8XL2nekdpcSYVBsqX7L9tiCMWdio4xlcInGhQ8em49N++ALws X9jQ== X-Gm-Message-State: ANhLgQ3lg4VbKIZv0ERiN1hFHCd3xN5BFkWfQ3sabG5EaIOQyMV9vL22 ru2NbmeIwvLpX6Bv1fjwHrBzQmfxx+s17BWJI28AzA== X-Received: by 2002:a05:6638:103:: with SMTP id x3mr12142684jao.62.1584346902777; Mon, 16 Mar 2020 01:21:42 -0700 (PDT) MIME-Version: 1.0 References: <5e668b89.1c69fb81.d7e4f.0f61@mx.google.com> <20200315094604.62dc96be@archlinux> In-Reply-To: <20200315094604.62dc96be@archlinux> From: Matt Ranostay Date: Mon, 16 Mar 2020 01:21:32 -0700 Message-ID: Subject: Re: [PATCH] iio: health: max30100: remove mlock usage To: Jonathan Cameron Cc: Rohit Sarkar , "open list:IIO SUBSYSTEM AND DRIVERS" , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 15, 2020 at 2:46 AM Jonathan Cameron wrote: > > 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'. Heh really had to look this over what I was doing since it has been almost half a decade now :). Think locking that mutex was only to prevent another read during the temp reading, and not really not sure how effective that is actually. Especially since the I2C subsystem should handle those reads in a queue like fashion. - Matt > > 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 */ >