Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp10826imb; Thu, 28 Feb 2019 14:21:07 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaoa0znnJ0USMnbEu3XqZpH0KHfTuw7a57GZRTP72wxrtzi8GNs5uDltFc60e4LQAEjk5QO X-Received: by 2002:a62:e413:: with SMTP id r19mr1968057pfh.236.1551392467368; Thu, 28 Feb 2019 14:21:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551392467; cv=none; d=google.com; s=arc-20160816; b=jITZCiwG6PiR83NVO0ES5blARybFLDL9g7oa2IjTu33yNuEzEA9W9Y55boctxn+m1U Mb5ttiMB/pj5PZwyxSiwwH/Ns7cjRf/EqCe4/h/gE2ykv7jhwSLcAqpWt3/vgloqq8Y4 Z4J/xz8Ble+Fwyl2i54Ifp/T0UoTFCLyeIPpqzMkMvr3qZmIwkBE3zXQVopY0fpvzkUB JOgTqG3a66PzH3yuLC5IBOiO5n2Bh+KNQAmr13A9WHvG+HA0kZoscplXNm2lDcHDX8XJ uFhKXTSn+1mwnHKb9cFC/sRpOq5SGERYllSKkmBq6MBuwAcSf59zgqaSjhA4g6UY7ypy KX/w== 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=jki2Pfol5S5xkuDVkDbK7J22JxYriZgQ+Stggv5cLINB9XW1PzvVZlIcma1N0ZZPQ9 KLiuY7xykl74Y41DLWWUkI9v1C1IlAbQIXjSdrhH5DK3IHiLCeBIqwlFnAB80oUH+bSv ks+SeJYygUxGwsTJD8CXq+PSukkbruxmyght4StPwwUQqIPEtDbY1GR6dBjCeiBqlnpQ wzr938o8PySuh3S/k8PZoqRPHTgoi2V0cPg5s1pwoLg9m85qzM2tdh7FXNOoejMeXBSP l7YjRtvKUtfqqxe7NjYP5m1TKk/zKzDuSIUIL5Ae8NshP4OMXn48qmv7Grijk+ce+SMM DeNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=tAulTENt; 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 s6si18854613plq.160.2019.02.28.14.20.52; Thu, 28 Feb 2019 14:21:07 -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=tAulTENt; 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 S1728903AbfB1WRt (ORCPT + 99 others); Thu, 28 Feb 2019 17:17:49 -0500 Received: from rnd-relay.smtp.broadcom.com ([192.19.229.170]:54740 "EHLO rnd-relay.smtp.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbfB1WRq (ORCPT ); Thu, 28 Feb 2019 17:17:46 -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 5EF4D30C04C; Thu, 28 Feb 2019 14:17:44 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.10.3 rnd-relay.smtp.broadcom.com 5EF4D30C04C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1551392264; bh=6v8rWmKbm19cPG30ujMQBqdZv3fhMujqMeaEXG+Iib8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAulTENtbAevIfGMN+Ey1ef+DKh8Z7K9E+8FhQ4VcLaMFWP9VcX+c6GPChWYQW1Rx APK26cWNPoVeuZHhz3jQgMFroS8VyYPysDj7ReYsl8bLU2G1DoHCqUssxLHCV5JvD4 kvzIUTPYpgIW8buOApeZNunwFCSlLIN/NjbgoOWY= 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 11D77AC0798; Thu, 28 Feb 2019 14:17:45 -0800 (PST) Received: by stbirv-lnx-2.igp.broadcom.net (Postfix, from userid 47169) id 09E6B27ECE7; Thu, 28 Feb 2019 14:17:45 -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 v4 1/2] iio: adc: ti-ads7950: Fix improper use of mlock Date: Thu, 28 Feb 2019 14:16:48 -0800 Message-Id: <1551392209-20004-2-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551392209-20004-1-git-send-email-justinpopo6@gmail.com> References: <1551392209-20004-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