Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1327609imb; Sat, 2 Mar 2019 10:54:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzP3VDzs8VIvfydx2XcbzxhjDpwYaVHlYj11EqRbDRhKhm4/44r/bWBFWeezoRp+n4QRuYy X-Received: by 2002:aa7:9152:: with SMTP id 18mr11643342pfi.215.1551552884459; Sat, 02 Mar 2019 10:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551552884; cv=none; d=google.com; s=arc-20160816; b=z1EtSJ5XSwoHmcVeRDTRBTt4EcZXPcuo5DIi7t7hRF7ZjUMh/ej7ERN6SmXH2SEQDh 5aVL50eiNlfDaXJPywLE3EZrnhcD3Yyq+3m5pSY6ova7p/j0Oxy9LpXAFZHBzLJfVyuJ ugVnGRRX+h0vTxHekgdQUQUIwgV+uOXgsLzENhlu0VxIy3Q4OEdmR5KxNTxfK6s+v3Ev zfqAplHIyNkL4XObCPggWwpDfl+T7QZZYFLVGmX2gNl18qqKfWd887KuplX9BBPZgx+/ J7ft2roezKSlUSKlco8OsIN/yx52ga558Sq1GIRvVDRzGmKiS6gF7glru9iBU4omavUn SbiQ== 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=xXYqZXTEHSZ9/7XUq1qO/H1DCuERFEiRC+qXWye0ubs=; b=snMnWUNQXY1Nnog7iuPZOAUxinALejizr7Ehinjgukkf+Rl+BTj/R7qIhym7YUPJlH gqBReqsWgafIqCI8S8u10wklk0TiH1qDW8P5DPcIViVjMlhbwgGX6QcjZthbWG3r8g89 VnMG7trS/14guxleT6crO3PLVwRvgonEAlh/jmVkxQcM3qDZ9BSvbOcKuoAggOPV2Afu UGeb/Kd6T/aa9/T78zkDu7aOrsnnS5Q1w5xDJ0mK+rwsArC1xZH7VWJqqw16sIBowSpI A9BRAEen6OGcbkXfpJax1WGkNG/ic8V2zBJQpImKdoiOODoSzXFQqhGLCtlps1/XZvoS NU9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QEv3gzGS; 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 i4si1124558pgs.408.2019.03.02.10.54.29; Sat, 02 Mar 2019 10:54:44 -0800 (PST) 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=QEv3gzGS; 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 S1727300AbfCBSx5 (ORCPT + 99 others); Sat, 2 Mar 2019 13:53:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:44718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbfCBSx5 (ORCPT ); Sat, 2 Mar 2019 13:53:57 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 653EB20449; Sat, 2 Mar 2019 18:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551552835; bh=Fitcxw94RzbZAVYEPd3Ilv+6poC1g3EvnpR3LUQVnTE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QEv3gzGSI2yBjqLAQEv3upTTU33AgzroQlYEQY7XpGQdtXm/w9+X6z5KsetCoG/zy tiboBYGJkVOI5irSG7OOmWvLTVL4xXBwozXp8JxQULRNPX4s9Gh5ailYcNsDt2EMte l3hjuXEHuTn+b6WyRDVTWKSVltBOHDeVdWfwQzHM= Date: Sat, 2 Mar 2019 18:53:49 +0000 From: Jonathan Cameron To: justinpopo6@gmail.com Cc: linux-iio@vger.kernel.org, linux-gpio@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, f.fainelli@gmail.com, bgolaszewski@baylibre.com, linus.walleij@linaro.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/2] iio: adc: ti-ads7950: Fix improper use of mlock Message-ID: <20190302185349.7c46488f@archlinux> In-Reply-To: <1551392209-20004-2-git-send-email-justinpopo6@gmail.com> References: <1551392209-20004-1-git-send-email-justinpopo6@gmail.com> <1551392209-20004-2-git-send-email-justinpopo6@gmail.com> X-Mailer: Claws Mail 3.17.3 (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 Thu, 28 Feb 2019 14:16:48 -0800 justinpopo6@gmail.com wrote: > From: Justin Chen > > Indio->mlock is used for protecting the different iio device modes. > It is currently not being used in this way. Replace the lock with > an internal lock specifically used for protecting the SPI transfer > buffer. > > Signed-off-by: Justin Chen Great, thanks for doing this. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/iio/adc/ti-ads7950.c | 19 +++++++++++++++---- > 1 file changed, 15 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c > index 0ad6359..1e47bef 100644 > --- a/drivers/iio/adc/ti-ads7950.c > +++ b/drivers/iio/adc/ti-ads7950.c > @@ -56,6 +56,9 @@ struct ti_ads7950_state { > struct spi_message ring_msg; > struct spi_message scan_single_msg; > > + /* Lock to protect the spi xfer buffers */ > + struct mutex slock; > + > struct regulator *reg; > unsigned int vref_mv; > > @@ -268,6 +271,7 @@ static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p) > struct ti_ads7950_state *st = iio_priv(indio_dev); > int ret; > > + mutex_lock(&st->slock); > ret = spi_sync(st->spi, &st->ring_msg); > if (ret < 0) > goto out; > @@ -276,6 +280,7 @@ static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p) > iio_get_time_ns(indio_dev)); > > out: > + mutex_unlock(&st->slock); > iio_trigger_notify_done(indio_dev->trig); > > return IRQ_HANDLED; > @@ -286,7 +291,7 @@ static int ti_ads7950_scan_direct(struct iio_dev *indio_dev, unsigned int ch) > struct ti_ads7950_state *st = iio_priv(indio_dev); > int ret, cmd; > > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->slock); > > cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(ch) | st->settings; > st->single_tx = cmd; > @@ -298,7 +303,7 @@ static int ti_ads7950_scan_direct(struct iio_dev *indio_dev, unsigned int ch) > ret = st->single_rx; > > out: > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->slock); > > return ret; > } > @@ -432,16 +437,19 @@ static int ti_ads7950_probe(struct spi_device *spi) > if (ACPI_COMPANION(&spi->dev)) > st->vref_mv = TI_ADS7950_VA_MV_ACPI_DEFAULT; > > + mutex_init(&st->slock); > + > st->reg = devm_regulator_get(&spi->dev, "vref"); > if (IS_ERR(st->reg)) { > dev_err(&spi->dev, "Failed get get regulator \"vref\"\n"); > - return PTR_ERR(st->reg); > + ret = PTR_ERR(st->reg); > + goto error_destroy_mutex; > } > > ret = regulator_enable(st->reg); > if (ret) { > dev_err(&spi->dev, "Failed to enable regulator \"vref\"\n"); > - return ret; > + goto error_destroy_mutex; > } > > ret = iio_triggered_buffer_setup(indio_dev, NULL, > @@ -463,6 +471,8 @@ static int ti_ads7950_probe(struct spi_device *spi) > iio_triggered_buffer_cleanup(indio_dev); > error_disable_reg: > regulator_disable(st->reg); > +error_destroy_mutex: > + mutex_destroy(&st->slock); > > return ret; > } > @@ -475,6 +485,7 @@ static int ti_ads7950_remove(struct spi_device *spi) > iio_device_unregister(indio_dev); > iio_triggered_buffer_cleanup(indio_dev); > regulator_disable(st->reg); > + mutex_destroy(&st->slock); > > return 0; > }