From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EC77392C4F for ; Fri, 19 Jun 2026 14:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781880132; cv=none; b=dkjuYzXq1Vb0S0mGq8NaEfDUuuvpza0sQWtDnAVWY4ErusFnWKJRTI4vZ0C4bC6iNWv0wTC/l2RUSAV1uVsNGOc3RrvwHOhtEARLq7bjByqfXKIFI+nMVyUBbIZQ52niHxamU8LlHnSWsudFq/jrgSRggclqAqk4Hxl+MJaj7kI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781880132; c=relaxed/simple; bh=EITmngCCMhar0hLU+x6qvbIAa+DctYKdDcsgG81q2Ps=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=GGDqpcTsmVfNX/jUW+WPGlIZ8hPbhuLZEq1HzdxWFdJ/aXInvsX7Wz2VB/E4jeP7RV/hiLda30vNH7xVpo+hbmwhYH07KXgARBaHhN5cCcuVuR8vl5cqtsC7WIunSM8SmuuGzCbfNPSpshFeqFBHxFStOluPX2si5vs1uAZsGFQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b=hF0T8MCf; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b="hF0T8MCf" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7e92c443cbcso657986a34.0 for ; Fri, 19 Jun 2026 07:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1781880129; x=1782484929; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=FKnVjGucb6IkF6/IYcinWjlII+ulFbmjFsYIvp41Gig=; b=hF0T8MCfMlcEX0q1bEu53byi+U/rZn+Uuz/YulvDqCYdyXZp/pYwScegTC9oVKHdEg 14R321KkBcxXVSMmnXt4d2zjid7Mzr370IKO0BZOB+4WZaaiZqOrOnrX8tb85CxTforg QSFoT528CjPoMgWtTNRXHu6g2sm7vObutThSX+uTqgAQKWSPhItbNbQYOItsVgy/w86U fPbPx+fg6+9eGGsr4oDhWiiHXlot4XwLq56oxTVxMCokk3sSvDNBBH4E73cWnKDVgX4k WobNMB8RvKAT65lIKRJa6emae4tbrFo77HKgCWvJuDORKVpsFkL8MyhaOMQkIuuKeFwE qrhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781880129; x=1782484929; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FKnVjGucb6IkF6/IYcinWjlII+ulFbmjFsYIvp41Gig=; b=VQfeLyTmb8gnqNEGfSTVjYtaObCNxk4AhApz+DjLyktGdqs27+XRWEX6ejJ7lXXrea yOWPFyGGNQ98DTLeSfMKrbnILA7llUz750Qg+kvNcwk/whyDMlJD6cbGBw2B/r4iw3D4 36JNJ8kpaMjbpalV0C4Ssdalhx86oWZZREz7irXNs4I+lvECGL2OOxqQfO+4sgHygC/o sWF8aG1wAFH9oXC3UX9NFCVZGr1q5JPI5bY3COnBuyh9xV3hTwTA9tigaV8GNmfa/IDA 0kUigiX7WrJAFuphQMqmsRPPkqN+vq+ppi37xJ/anTM9lKgNWsi2oeRw/fgplTloOBIw viaw== X-Forwarded-Encrypted: i=1; AFNElJ8gM3fD//HIiFyisu+7ornb/rmT/j27paVeJDROVRtkOYDbOiugzTRGl4TraX4C9JyfzhKdz0bwyLiu2SI=@vger.kernel.org X-Gm-Message-State: AOJu0YzA1YDpU22eR+14L+0o0fYts1vbb4gK9tXDkmMdvPVNK/FuyZmD 1RI7ViD6BV+Z4AS5vXPTGxSzoyONqQegFa+0SsXy7kRoAmylD4lhuvJUSiQ/lbqFsUo= X-Gm-Gg: AfdE7ckgYLeTUAIlD0aFgI3rUu0fR3pU+60ddlLwg5O6Q+qRAA1PG9xATC7z+ZbK+BS q+0QmtSgCXpdlwePMgD9bSYVjx20PQqMitCuYWFICxTTyIRiAx0axeJvuKabDklGnPFl0/t70E1 JTk47MQs4swUGXq8g8McqxkfN5KZpSRYLS87PkHArur6Zq3upoMVXxP2scAM0EI09F/QbyGO63k MN7pU4vipfEo9nZ7cIYt1TX+ECTEeL45kbmaX0SIQ8hJ6FBhsym0tp9JnhyVXYns/26ueLNN9iF udz+TwAoehJbIUiCPtBPd0P3h5kXtb1fWAakPAkDTg1wfVOlqReYBvT8BzBPEIekFjkP2S/oK/8 q9cBbivQyvJ1ctjyUspEvDPtOudvRXaPJ0KP387bhfQpOJKLPZgImNF9uF8wMqugwPWLzoRevim zl9OAK5X/9GkFluHAG0h61rdxKw/13gT9sJIWkqltO7QczHs8wV8GF5zqtsg== X-Received: by 2002:a05:6830:82d6:b0:7e6:50c0:87a6 with SMTP id 46e09a7af769-7e92d83a030mr2776195a34.8.1781880128987; Fri, 19 Jun 2026 07:42:08 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:500:dd8:d93b:3cde:c07? ([2600:8803:e7e4:500:dd8:d93b:3cde:c07]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e92e031985sm1998461a34.0.2026.06.19.07.42.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Jun 2026 07:42:08 -0700 (PDT) Message-ID: Date: Fri, 19 Jun 2026 09:42:08 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] iio: ti-ads7138: Disable STATS_EN bit while reading conversion results To: Paul Geurts , jic23@kernel.org, nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, tobias.sperling@softing.com References: <20260619090004.355053-1-paul.geurts@prodrive-technologies.com> Content-Language: en-US From: David Lechner In-Reply-To: <20260619090004.355053-1-paul.geurts@prodrive-technologies.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/19/26 4:00 AM, Paul Geurts wrote: > The device might update channel data while it's read by the host, > providing a data race. Disable the update of the channel stats before > reading the values. This description seems a bit short on details. It looks like this driver doesn't support buffered reads. So if we disable statistics during a direct read, why would we want to enable statistics in the first place? (This driver suffers from the comments say "what" rather than "why" /* Enable statistics and digital window comparator */ so it is hard to say what the original intention was.) Can you explain more what this race condition is about and what happens before the fix vs. after the fix? People generally do this with two columns showing concurrent function calls. It seems to me like disabling statistics would break IIO_CHAN_INFO_PEAK. > > Signed-off-by: Paul Geurts > Fixes: 93a39542d3c3 ("iio: adc: Add driver for ADS7128 / ADS7138") > --- > > V1 -> V2: Checked return values and prefixed iio: in commit msg > > v1: https://lore.kernel.org/all/20260619075646.4100193-1-paul.geurts@prodrive-technologies.com/ > --- > drivers/iio/adc/ti-ads7138.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/iio/adc/ti-ads7138.c b/drivers/iio/adc/ti-ads7138.c > index ee5c1b8e3a8e..81380fd2badc 100644 > --- a/drivers/iio/adc/ti-ads7138.c > +++ b/drivers/iio/adc/ti-ads7138.c > @@ -237,11 +237,21 @@ static int ads7138_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > + /* Disable statistics update so the value is not updated mid read */ > + ret = ads7138_i2c_clear_bit(data->client, ADS7138_REG_GENERAL_CFG, > + ADS7138_GENERAL_CFG_STATS_EN); > + if (ret) > + return ret; > ret = ads7138_i2c_read_block(data->client, > ADS7138_REG_RECENT_LSB_CH(chan->channel), > values, ARRAY_SIZE(values)); > if (ret) > return ret; > + /* Enable statistics update after read */ > + ret = ads7138_i2c_set_bit(data->client, ADS7138_REG_GENERAL_CFG, > + ADS7138_GENERAL_CFG_STATS_EN); > + if (ret) > + return ret; > > *val = get_unaligned_le16(values); > return IIO_VAL_INT;