From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16B0CC77B75 for ; Mon, 8 May 2023 10:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234516AbjEHKWd (ORCPT ); Mon, 8 May 2023 06:22:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234519AbjEHKVw (ORCPT ); Mon, 8 May 2023 06:21:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25CB12646F for ; Mon, 8 May 2023 03:21:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8E5B462544 for ; Mon, 8 May 2023 10:21:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84D1BC433D2; Mon, 8 May 2023 10:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1683541264; bh=d9BnRLNFQ8S4dfcDbJW70ry6tDS+uDw92joYRDnVDoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UCl7k591hdmBja+cSpfgu1NHfxNsGdzrOhmVY8A/uiy/7zXfKA1LYU8aHLB6kBNxP s1BRMR5sP2DM4TXreZIgHrEGLOH2+FPMnGve6lSt6T34cn2p9cjMgk7H/j9n+L05OA DtF0PJ4yq9ULdVpqemoLcdy6D3zEDywqfVzfSJ+0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, William Breathitt Gray , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 6.2 058/663] iio: addac: stx104: Fix race condition when converting analog-to-digital Date: Mon, 8 May 2023 11:38:04 +0200 Message-Id: <20230508094430.372314449@linuxfoundation.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230508094428.384831245@linuxfoundation.org> References: <20230508094428.384831245@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: William Breathitt Gray commit 4f9b80aefb9e2f542a49d9ec087cf5919730e1dd upstream. 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 Link: https://lore.kernel.org/r/2ae5e40eed5006ca735e4c12181a9ff5ced65547.1680790580.git.william.gray@linaro.org Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/addac/stx104.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/iio/addac/stx104.c +++ b/drivers/iio/addac/stx104.c @@ -114,6 +114,8 @@ static int stx104_read_raw(struct iio_de return IIO_VAL_INT; } + mutex_lock(&priv->lock); + /* select ADC channel */ iowrite8(chan->channel | (chan->channel << 4), ®->achan); @@ -124,6 +126,8 @@ static int stx104_read_raw(struct iio_de 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 */