Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp233977pxb; Thu, 2 Sep 2021 03:01:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaiVFbLv2jXHZsCnMl0MIdLcxeIg7e/lQ+AhvG3jQ4tmPFCcY75V2gf4mPX//S9+xUHs7v X-Received: by 2002:a6b:8e50:: with SMTP id q77mr1972529iod.96.1630576869201; Thu, 02 Sep 2021 03:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630576869; cv=none; d=google.com; s=arc-20160816; b=y0CfC9XCdYRhl1kpf6JGPPR4vC0lSFJ+/mW/MVg/aSQg4XIOxEyKm18V1RWSP5630C jkS4v7U0zgdtmdmpTlVPciMoZH0ZVuhCLujMvcg0baXm7Mh2UP8tv53WFnT5LDBie60h Y/l2TMlTq2IH4ljlAZPkuMY3Ztnaiuh3lM1SyJtmg3H+vB1x/uLasxkNPmQJKxRJkQUV no+bweF7pLhEmJ3CEYUP/QGZFYvc7OnHuZvkmcnOmK/2RZqss2DDbKoSbV3/6LTuH8Ho bbpCjay6j7nTDvJZXHn56ICD0hVneqE+ZGAvMuzBQeSwuiqmvuviVnEtZEbb6WTJFLRz s8UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=tpu1/5Wyg/gDdjYzfVqHQ8+J/jPo7EjDtua3kyeYNoM=; b=dZuYlr/N1iizrAbNJnMBLYp2GZOUpnX6XmD6VNUJEaEnlvH/5DCTOBwnfl9CParS0n zQCWgDCd8IuYxnkfSPhmKx4nTiVdPs0+ZYhbDHjcvGGMQKYIsLz0BtvMa7ugQ//2DMX8 b8X3zhHWAVk3CW/ifQA4K3zpSX8NeNuQeCoFLZW1CJ+GMV/ZsXvwYftkK1G95qNuE+2h 43cNJCvUFnrA2h+vyR7IJ9a9Q/Bzlh+0HDHuf+G2n2C8Do7Mrf0CRcB9P2aiagpvThwq B8Z6ifaq6Ctrdu8wc3eSS3GXeX7orVXblh1+lCRFgSU172NP6xHP3q3RZ3RNwo5j5BJD 6pXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m62si1016279ioa.15.2021.09.02.03.00.57; Thu, 02 Sep 2021 03:01:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244706AbhIBI5X convert rfc822-to-8bit (ORCPT + 99 others); Thu, 2 Sep 2021 04:57:23 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:40853 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244827AbhIBI5V (ORCPT ); Thu, 2 Sep 2021 04:57:21 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id DD6D2240017; Thu, 2 Sep 2021 08:56:20 +0000 (UTC) Date: Thu, 2 Sep 2021 10:56:19 +0200 From: Miquel Raynal To: Jonathan Cameron Cc: "Sa, Nuno" , Lars-Peter Clausen , Thomas Petazzoni , "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 10/16] iio: adc: max1027: Prevent single channel accesses during buffer reads Message-ID: <20210902105619.311e62d9@xps13> In-Reply-To: <20210830112024.4583f3cb@jic23-huawei> References: <20210818111139.330636-1-miquel.raynal@bootlin.com> <20210818111139.330636-11-miquel.raynal@bootlin.com> <20210830112024.4583f3cb@jic23-huawei> Organization: Bootlin X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jonathan, Jonathan Cameron wrote on Mon, 30 Aug 2021 11:20:24 +0100: > On Fri, 20 Aug 2021 07:30:07 +0000 > "Sa, Nuno" wrote: > > > > -----Original Message----- > > > From: Sa, Nuno > > > Sent: Friday, August 20, 2021 9:21 AM > > > To: Miquel Raynal ; Jonathan Cameron > > > ; Lars-Peter Clausen > > > Cc: Thomas Petazzoni ; linux- > > > iio@vger.kernel.org; linux-kernel@vger.kernel.org > > > Subject: RE: [PATCH 10/16] iio: adc: max1027: Prevent single channel > > > accesses during buffer reads > > > > > > [External] > > > > > > > > > > > > > -----Original Message----- > > > > From: Miquel Raynal > > > > Sent: Wednesday, August 18, 2021 1:12 PM > > > > To: Jonathan Cameron ; Lars-Peter Clausen > > > > > > > > Cc: Thomas Petazzoni ; linux- > > > > iio@vger.kernel.org; linux-kernel@vger.kernel.org; Miquel Raynal > > > > > > > > Subject: [PATCH 10/16] iio: adc: max1027: Prevent single channel > > > > accesses during buffer reads > > > > > > > > [External] > > > > > > > > When hardware buffers are enabled (the cnvst pin being the > > > trigger), > > > > one > > > > should not mess with the device state by requesting a single channel > > > > read. Prevent it with a iio_buffer_enabled() check. > > > > > > > > Signed-off-by: Miquel Raynal > > > > --- > > > > drivers/iio/adc/max1027.c | 2 ++ > > > > 1 file changed, 2 insertions(+) > > > > > > > > diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c > > > > index 223c9e4abd86..83526f3d7d3a 100644 > > > > --- a/drivers/iio/adc/max1027.c > > > > +++ b/drivers/iio/adc/max1027.c > > > > @@ -335,6 +335,8 @@ static int max1027_read_raw(struct iio_dev > > > > *indio_dev, > > > > > > > > switch (mask) { > > > > case IIO_CHAN_INFO_RAW: > > > > + if (iio_buffer_enabled(indio_dev)) > > > > + return -EBUSY; > > > > > > I guess 'iio_device_claim_direct_mode()' would be a better option > > > here? There's nothing preventing this check to pass and then, > > > concurrently > > > someone enables the buffer... > > > > > > > Taking a second look, it seems that this check is already done [1]? Am I missing > > I missing something? You're right, I missed that too. > > Also, I think we are returning with the 'st->lock' held... > > > > [1]: https://elixir.bootlin.com/linux/latest/source/drivers/iio/adc/max1027.c#L247 > Absolutely agree this should be done with iio_device_claim_direct_mode() to close the > possible races. Didn't know this helper, nice. > I wonder why this one has been missed in all the cleanups of that stuff? Looks like > a simple case, but I guess it wasn't immediately visible in the read_raw() function > so no one noticed. > > Jonathan > Thanks, Miquèl