Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3477074pxb; Mon, 30 Aug 2021 03:18:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw18EzCKDJADspsVtAUjLqL7vZIxHHi6W2IWWZCwnKMY0ySsKnIzKxk9Ad/NOGbWm1+ncPz X-Received: by 2002:a6b:b502:: with SMTP id e2mr17172151iof.152.1630318700244; Mon, 30 Aug 2021 03:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630318700; cv=none; d=google.com; s=arc-20160816; b=Ozac5EM6bBtgR2HocWS3Uv87Yoobi+La75HHQnO2zCxWjvESAHzxBpRa540W3h/uv7 DnMlXNziYqlOy7oIfWMUH/BS7YU66OO/of9nNptFIBrfJKiSHqibgKPth9Bm22TdHTPr ZdbqZzI5vLOrI1GR+fzczb7oHJb2NpspwEytnsPGuW/w1mI6GJd+Mp2/Dd0nOk04UbNr OBkSQdGZ1kAJ8J8fMcqjdI234g+FxjrGKA5sOjex5KmMRD/hO6CFgH/Px9at06jEcKAa HecYnsimktpywMyjpywq65a8ZZx+qgfErDuRbZujvtAe5joaJVFFbVGfY5eMh8WiP+qF +AaA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=S22ABgX4MJqAh0/7zvoozUI/okq7ocn89OQA97ukG2w=; b=IPAhiriafmC8knmBPAsWKVEdp7ZAWGXaWr2vknVy8PG3joJHZBD7oKJbcKRUPm8iXQ aTVW+wMgxoieppZvTxpVXbiiTpuxmlJodl/N7CXhTYT6QMliYnHzpzP+mrb30M/Q2et6 3C+4UD1BCGe4+16OimAzCT8xcwl57yXZ/xV5VoK5la57XQU3R1CRV07vLb91VMgtkxB2 uKn2I4yDSS8ylcnColn0N2SXHm1xzRebzPCG1eDM9sw/sMfx7tdjbFS1RRGkgHm0Z1rS e3mVaCSLBEiJKVSIOAweAwcGeNDDbxUHV21tlyiHyuvEJrqSJDmiDB8OTOT2V/Z49m+b yOdQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si17710977jas.59.2021.08.30.03.18.08; Mon, 30 Aug 2021 03:18:20 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236316AbhH3KSL (ORCPT + 99 others); Mon, 30 Aug 2021 06:18:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:56906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236123AbhH3KSJ (ORCPT ); Mon, 30 Aug 2021 06:18:09 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (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 5FF89610A4; Mon, 30 Aug 2021 10:17:14 +0000 (UTC) Date: Mon, 30 Aug 2021 11:20:24 +0100 From: Jonathan Cameron To: "Sa, Nuno" Cc: Miquel Raynal , 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: <20210830112024.4583f3cb@jic23-huawei> In-Reply-To: References: <20210818111139.330636-1-miquel.raynal@bootlin.com> <20210818111139.330636-11-miquel.raynal@bootlin.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > 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. 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