Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6061202rwl; Tue, 4 Apr 2023 07:21:46 -0700 (PDT) X-Google-Smtp-Source: AKy350Z1nnvd2v5d8rV0Vt6HSQ6EIOsHSIIDKQIgiemeVX3zIn1eaUA2oh2BBfzzYth5jz0rgBpS X-Received: by 2002:a17:90b:3b48:b0:23d:29c7:916f with SMTP id ot8-20020a17090b3b4800b0023d29c7916fmr2996478pjb.32.1680618106242; Tue, 04 Apr 2023 07:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680618106; cv=none; d=google.com; s=arc-20160816; b=QlCkCN7hougl/4WmEiuARtRH8nN31N0j6C5yz0kya9zgz97+uzzwImOBWkI9++P9sI Oc8tFBVqgLZ94IqvZMwCHA2KL6ARq/NpSlO1fxZz7s3jKKbl/swTvVd29Mi5txIHY9wD aIk95GrqxWwjClI5FggzAIcx4QhDyImrTbOINzZGxvR0qfCfERxzHQ4FvaSjqrau/Mun IwduNpePJMRWl4FKFE8L1sR942JEUC5AKxwxNWlYBmV+eHCwg0fGAaOxy38MKNWbVC0A FdZJtx0Ly9vn1Xxy7kPI1RACqkjbUKkox74NNc4yM8nU8cxlFZVyFwiYIReSm67547TY oq+A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ntJEhFvPVyRwKjpX84wW6Nzwfs8RwaisnK/y3HB3QZI=; b=Fv7NEaZukAD8+AFSJSjTWY56kZV8KzlIDDtGJ6DoDmEw1B10TYPcmVAz/gLYVlQnTe flUekb3IrZdE7vACrEjd4zzf+yRXqPlZuoqDy249l02ecP+38inSBZDSWPzC5T2kEbPv RDkvfMUII+T5a84ivf+ek1HC8ZH243+ZFrPh91iRyQPzEq+JFbaAgQVmIpzbo9HY880a Ny1m3Xi5/ylAReFXF++7692wTmtJoBFh4uGFap9paOKaiEAu2FzJThij7HE2G9To/9oT mFRdAaUNxegy9Sg4IB1n4rWcIJg9BppTajT0s9gS1vvq4SlC9OZ1NsdNXIlsS9R6bjJy AP2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q4242DFw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp2-20020a17090b4a8200b0022bbae722fcsi1528242pjb.1.2023.04.04.07.21.34; Tue, 04 Apr 2023 07:21:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q4242DFw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235640AbjDDOMX (ORCPT + 99 others); Tue, 4 Apr 2023 10:12:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235602AbjDDOML (ORCPT ); Tue, 4 Apr 2023 10:12:11 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4436D422D for ; Tue, 4 Apr 2023 07:12:08 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5491fa028adso119467147b3.10 for ; Tue, 04 Apr 2023 07:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680617527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ntJEhFvPVyRwKjpX84wW6Nzwfs8RwaisnK/y3HB3QZI=; b=q4242DFwPstTgqf5Ui1GWU4QZfjJwo8dqlFgpBF1Y0R5XPVUd4yDM1Rzwf894WOFVJ 6e1xj/rMw0ZCFRKA4dzd8FtEjKCAJKd6Qon1yqC1BVmUvacoqdHv7+1ZA50uPczq6yup ewQPrYZMCzQ5ARCh8e1iMvQevFSngbCEVU+5SyRPiku+75PNHrzPh1IojCQYIGqiqD1l qE+0Z/99iGSfJgZWPwC+IqgGydOYuLRrU7F8bV3EvVZweZ98dWmbWTfzDc6KRrzE+H82 0MgfvhI9qRyAQ8Z5FZ5+0BxfvgWHFKYZ9SauqRu/mXORNcWHCWoWsxjG0+Wuz/1wEAAV eV1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680617527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ntJEhFvPVyRwKjpX84wW6Nzwfs8RwaisnK/y3HB3QZI=; b=JgDbX623ngJFO45ilvfmwy/gG49CRwGeFlE84ZF3mTdSMT9cti8phlv9CygMgWJB0y q2exbswHQu9ZFsXNTxeY6XARRa1Muyal2Xtcca/48IfA2QXizUNd9r2wPInCucint4Qs wCfVj8u6J2e1CacLRIK8gkGqp4gPDxRoK/miaenqRQXrbxgare3xX0i2QiKMI7YpO7se Tmeabe6diCiM6AYElftfjebCema/18XU1sg7pUGWT56SE0a4uvV2oo9xABjRY9GBbMgh 9s9DVmXi74xS2/P6IpEFt9bIuPGy1o4fbvgqooouIjVe8BHlfJ2e1CEv1yYyqXIqMlQJ k+IQ== X-Gm-Message-State: AAQBX9eeq7xkml5dQbJ/W9lTstm8os7V8nBY2058WomYHBGJfxihXgXj gX6jzIsT8/uL6Dye8u5H/bxKOA== X-Received: by 2002:a0d:d88d:0:b0:541:8909:eb5a with SMTP id a135-20020a0dd88d000000b005418909eb5amr2368089ywe.18.1680617527339; Tue, 04 Apr 2023 07:12:07 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id d195-20020a811dcc000000b00545a08184d8sm3202750ywd.104.2023.04.04.07.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 07:12:06 -0700 (PDT) From: William Breathitt Gray To: Jonathan Cameron , Lars-Peter Clausen Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , William Breathitt Gray Subject: [PATCH v4 2/5] iio: addac: stx104: Fix race condition when converting analog-to-digital Date: Tue, 4 Apr 2023 10:11:59 -0400 Message-Id: <2ae5e40eed5006ca735e4c12181a9ff5ced65547.1680564468.git.william.gray@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ADC conversion procedure requires several device I/O operations performed in a particular sequence. If stx104_read_raw() is called concurrently, the ADC conversion procedure could be clobbered. Prevent such a race condition by utilizing a mutex. Fixes: 4075a283ae83 ("iio: stx104: Add IIO support for the ADC channels") Signed-off-by: William Breathitt Gray --- drivers/iio/addac/stx104.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iio/addac/stx104.c b/drivers/iio/addac/stx104.c index 4239aafe42fc..8730b79e921c 100644 --- a/drivers/iio/addac/stx104.c +++ b/drivers/iio/addac/stx104.c @@ -117,6 +117,8 @@ static int stx104_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; } + mutex_lock(&priv->lock); + /* select ADC channel */ iowrite8(chan->channel | (chan->channel << 4), ®->achan); @@ -127,6 +129,8 @@ static int stx104_read_raw(struct iio_dev *indio_dev, while (ioread8(®->cir_asr) & BIT(7)); *val = ioread16(®->ssr_ad); + + mutex_unlock(&priv->lock); return IIO_VAL_INT; case IIO_CHAN_INFO_OFFSET: /* get ADC bipolar/unipolar configuration */ -- 2.39.2