Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3285189pxk; Mon, 21 Sep 2020 09:41:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPwZBhCzYfX4sps0MkHJ7SYKh5F4YIGZcyX2KLWWOK9aVD6/TQu0el7u+5Eyy0oxT1y2IC X-Received: by 2002:a17:906:f92:: with SMTP id q18mr280296ejj.237.1600706478804; Mon, 21 Sep 2020 09:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706478; cv=none; d=google.com; s=arc-20160816; b=iEz3C93r6L/Lw4ISg15GFwBw5MbX7PXU/lOsbaVEnNf1UAwymz1XxlWpiG3P33e/t2 Ty3W2HrWBoSO/SphhaGP0Luo29+h+h1RC5MjnHQptl6SUamHUuLIE5rmkT0aPgxsvYOn k0e9l4Xff+p9HdhkASbDxKJD8YdRzcVJS8b1P185pIfIzNahj99WJS6+8HQ3QSOPCqZ3 ArhvdV/iQOoCXn3Jg3SzBeVMxoZ5Uodl8P5gDrNbBfMheC8o1xDoZL/WSlMnFPbrS09r /JByjjXHt/f7oVm2VIxnUn8P0MnGjF39RkcDcsVBteCZSTga/H7utnRj1VO133Whz7+V JBWw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AtvIzPxAntj+SZf6F8387Ol1c/P9ZZp3iXKp1QPY4Xk=; b=CPyQWescrFHNgjvquBfohk2wtusR/FQ7iwHPIE7xRgS7Ko3VWj8rG4/toWAXeIqcLT Y1SC871JUvsXTb1+w52Mi9OAfY3UuQoMyw3eOt5vhy+yBLX6XHYi1kTNKlCGilXk2SEj ynE0BhHF5fgczgwYUGBCdzfNaDoMRsJYyZbAGEEJ4n4mcNoxA2B8tj4w4kedSfmnC52R hI6NV96Irgug3kIlq01VJ4jLwZwCvRHyb1eUkEUE2ggkXZbjg0nnNawjftPX02hclTl+ 7oS8QwcAOgVdL95eJ7X3b5lnR8XhcOcXVzLqSPCjqalgaZmMTAkk3Mzz6KBltPDX9wqk fysQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=egm473pQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kt8si7728454ejb.503.2020.09.21.09.40.55; Mon, 21 Sep 2020 09:41:18 -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; dkim=pass header.i=@kernel.org header.s=default header.b=egm473pQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729199AbgIUQiz (ORCPT + 99 others); Mon, 21 Sep 2020 12:38:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:39786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728614AbgIUQif (ORCPT ); Mon, 21 Sep 2020 12:38:35 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 B64C7238EE; Mon, 21 Sep 2020 16:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706314; bh=UQ9uhk9yESmpsuclrVoey/brZ5TMAsHuztHElWFK4Kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=egm473pQdXx8rPphpec9nEqSgB/ejkkxz93Zm93iBxSc5vwXw7+dwbwO5Q1QeBuD8 VFR7H56fTUIvnG9t09Vuyzr8lZZJcvSCYjenmug886OerIglJk9WBMb4rlgifHep+f +OGgY3B3kTadyLA9ZMmA08dDnZD8rfZaTsmBg+/E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Angelo Compagnucci , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.14 23/94] iio: adc: mcp3422: fix locking scope Date: Mon, 21 Sep 2020 18:27:10 +0200 Message-Id: <20200921162036.617304797@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Angelo Compagnucci commit 3f1093d83d7164e4705e4232ccf76da54adfda85 upstream. Locking should be held for the entire reading sequence involving setting the channel, waiting for the channel switch and reading from the channel. If not, reading from a channel can result mixing with the reading from another channel. Fixes: 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC") Signed-off-by: Angelo Compagnucci Link: https://lore.kernel.org/r/20200819075525.1395248-1-angelo.compagnucci@gmail.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/mcp3422.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/drivers/iio/adc/mcp3422.c +++ b/drivers/iio/adc/mcp3422.c @@ -99,16 +99,12 @@ static int mcp3422_update_config(struct { int ret; - mutex_lock(&adc->lock); - ret = i2c_master_send(adc->i2c, &newconfig, 1); if (ret > 0) { adc->config = newconfig; ret = 0; } - mutex_unlock(&adc->lock); - return ret; } @@ -141,6 +137,8 @@ static int mcp3422_read_channel(struct m u8 config; u8 req_channel = channel->channel; + mutex_lock(&adc->lock); + if (req_channel != MCP3422_CHANNEL(adc->config)) { config = adc->config; config &= ~MCP3422_CHANNEL_MASK; @@ -153,7 +151,11 @@ static int mcp3422_read_channel(struct m msleep(mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->config)]); } - return mcp3422_read(adc, value, &config); + ret = mcp3422_read(adc, value, &config); + + mutex_unlock(&adc->lock); + + return ret; } static int mcp3422_read_raw(struct iio_dev *iio,