From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753045AbcE2SeE (ORCPT ); Sun, 29 May 2016 14:34:04 -0400 Received: from saturn.retrosnub.co.uk ([178.18.118.26]:33998 "EHLO saturn.retrosnub.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752826AbcE2SeD (ORCPT ); Sun, 29 May 2016 14:34:03 -0400 Subject: Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency To: Daniel Baluta , Alison Schofield References: <96cee774e7a4269a73b0fcd476d8af575c10ac00.1464115008.git.amsfield22@gmail.com> Cc: Lars-Peter Clausen , "Hennerich, Michael" , Hartmut Knaack , Peter Meerwald-Stadler , "linux-iio@vger.kernel.org" , Linux Kernel Mailing List From: Jonathan Cameron Message-ID: <8fee480e-f2cc-bb80-6328-0c2dcdb873e8@kernel.org> Date: Sun, 29 May 2016 19:33:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/05/16 11:36, Daniel Baluta wrote: > On Tue, May 24, 2016 at 10:17 PM, Alison Schofield wrote: >> Driver was checking for direct mode and trying to lock it, but >> left a gap where mode could change before the desired operation. >> Use iio_device_claim_direct_mode() to guarantee device stays in >> direct mode. >> >> Signed-off-by: Alison Schofield >> Cc: Daniel Baluta > > Acked-by: Daniel Baluta Again, this one is not quite so trivial so I'll wait for Lars to take a look even though I'm happy with it. Thanks, Jonathan > >> --- >> drivers/iio/adc/ad7793.c | 13 ++++--------- >> 1 file changed, 4 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c >> index 7b07bb6..3f41cd8 100644 >> --- a/drivers/iio/adc/ad7793.c >> +++ b/drivers/iio/adc/ad7793.c >> @@ -369,13 +369,6 @@ static ssize_t ad7793_write_frequency(struct device *dev, >> long lval; >> int i, ret; >> >> - mutex_lock(&indio_dev->mlock); >> - if (iio_buffer_enabled(indio_dev)) { >> - mutex_unlock(&indio_dev->mlock); >> - return -EBUSY; >> - } >> - mutex_unlock(&indio_dev->mlock); >> - >> ret = kstrtol(buf, 10, &lval); >> if (ret) >> return ret; >> @@ -387,12 +380,14 @@ static ssize_t ad7793_write_frequency(struct device *dev, >> >> for (i = 0; i < 16; i++) >> if (lval == st->chip_info->sample_freq_avail[i]) { >> - mutex_lock(&indio_dev->mlock); >> + ret = iio_device_claim_direct_mode(indio_dev); >> + if (ret) >> + return ret; >> st->mode &= ~AD7793_MODE_RATE(-1); >> st->mode |= AD7793_MODE_RATE(i); >> ad_sd_write_reg(&st->sd, AD7793_REG_MODE, >> sizeof(st->mode), st->mode); >> - mutex_unlock(&indio_dev->mlock); >> + iio_device_release_direct_mode(indio_dev); >> ret = 0; >> } >> >> -- > -- > To unsubscribe from this list: send the line "unsubscribe linux-iio" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >