Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6293587imb; Fri, 8 Mar 2019 14:05:04 -0800 (PST) X-Google-Smtp-Source: APXvYqw/NFP2jl9hvVo8w1b9R+iIvkV65SPY0R7n5d8T64UuJSiNceKoSPRcJylgdYPuzHEs7h4z X-Received: by 2002:a62:e802:: with SMTP id c2mr20453589pfi.249.1552082704233; Fri, 08 Mar 2019 14:05:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552082704; cv=none; d=google.com; s=arc-20160816; b=DwzrpV6LEWURh8CunUcIZGK0psMRy2l3PGZmy3aXGvphoXmA03gLtg3g3TCgd83Pmm ejUbLZhUHQnupdRBR5st4LoOQIh9gBqE3vLgdkLdw4+D1z/2Jc5mjot5o4OSD0KUbJB7 CWxRxXKFpvG3w2flPJdDjUvTLcMEkAlzr1XKI51VU5hP/2IxnbE8D5k5NCKzS9Nvsj7D gyTjsqcicgfKkfh9ju+fzTsHuyABlX5DucDoHXbEcmHIUA6ECUlst6SnBWliEXEV2QA7 Y2xA3L62JI1u7mp00gecKvogf+SjSwABfIKVp5ThieDMZPN1e6tA4ai4vfd5w+/C/Pr1 aIyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=RAP6smSoDaHHsF5ShnmKiq3WXBwaH97xloHNW2CkdYk=; b=CnsSsREGxYlqiup02WA0L/fEXfy5jwfBgNUsogbpVoRVPtu+/6FVTI9oi7/pwUOoBL lshmUHep3Vk9xL1HAXa4R3oqzt98nEzIW0+DADQQPhLoVXwVcanlYlamyUIlHAEwjx5H 5M6mPezDRkwxaPXji5ltPcq4lgWvK0fN9EYylxNabnOC+R/wEhd86dMnKVB4nceY/IYI 4ndq7Ye+Aan/83jhbBdqTkXp94riET++5TK1lJkAsTyEz3THs1CspbfnDVj5B4zDIDQr P9L2h/rrMvrCkAgtvaVbIOYdlY0Hd1b90O+nYqOwmD5hdDDKuu1zf6zO41n0R73XrCHg 6G+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=jXm9uSN1; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si7999312plb.103.2019.03.08.14.04.48; Fri, 08 Mar 2019 14:05:04 -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=@broadcom.com header.s=dkimrelay header.b=jXm9uSN1; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726512AbfCHWEQ (ORCPT + 99 others); Fri, 8 Mar 2019 17:04:16 -0500 Received: from rnd-relay.smtp.broadcom.com ([192.19.229.170]:45378 "EHLO rnd-relay.smtp.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726286AbfCHWEP (ORCPT ); Fri, 8 Mar 2019 17:04:15 -0500 Received: from nis-sj1-27.broadcom.com (nis-sj1-27.lvn.broadcom.net [10.75.144.136]) by rnd-relay.smtp.broadcom.com (Postfix) with ESMTP id F331030C053; Fri, 8 Mar 2019 14:04:11 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.10.3 rnd-relay.smtp.broadcom.com F331030C053 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1552082652; bh=6v8rWmKbm19cPG30ujMQBqdZv3fhMujqMeaEXG+Iib8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jXm9uSN1kC8rty64c9WCfQEMXacgLcs8Z9A31zlXUTpKKklWUlTI/7sjkiJXFNcxk qPjlxooN4JK1R1JeFNBlNwzFTBGoZzA+nCRXGm+5N7YM5EOCr87MIdC8zPZMpRufgh QdLm/lziTpe/tSgbB7yL3rCm1ElB6/N4uqB7v5So= Received: from stbirv-lnx-2.igp.broadcom.net (stbirv-lnx-2.igp.broadcom.net [10.67.48.34]) by nis-sj1-27.broadcom.com (Postfix) with ESMTP id 12BF9AC07B4; Fri, 8 Mar 2019 14:04:12 -0800 (PST) Received: by stbirv-lnx-2.igp.broadcom.net (Postfix, from userid 47169) id 044DE27FECD; Fri, 8 Mar 2019 14:04:12 -0800 (PST) From: justinpopo6@gmail.com To: linux-iio@vger.kernel.org Cc: linux-gpio@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, f.fainelli@gmail.com, bgolaszewski@baylibre.com, linus.walleij@linaro.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-kernel@vger.kernel.org, Justin Chen Subject: [PATCH v5 1/2] iio: adc: ti-ads7950: Fix improper use of mlock Date: Fri, 8 Mar 2019 14:03:27 -0800 Message-Id: <1552082608-42603-2-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552082608-42603-1-git-send-email-justinpopo6@gmail.com> References: <1552082608-42603-1-git-send-email-justinpopo6@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.7.4