From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 A96163A5E8F for ; Mon, 30 Mar 2026 14:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774880251; cv=none; b=tuy8eCmrMHM4CGaRDS8PTsVbAGmWgc/TG0JwNvBKabkzGztfRi+DfV+jA2DKi6xI2No9xgonPJmUE21g1gAUgWxRMU+WBpdenFFq0jEMXAQOtHQn+IgW8XB2HRYOOu21r2Mr4pheOjduuWcPWnHT6a9tU0ZUXuk1KWqXq8puBnU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774880251; c=relaxed/simple; bh=jWvphccgBs+CBissFExWcsmt9A6xx59JSpOT4BwXbso=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EHQlHgTFVHVxuloLHF/l283M/dt3DCuklADSq3GWLTQbzjmsibF6Y/T8tao32j5H+g5IAYKEi4HkUiAQCqyedk70pOzechu5bdYITpTmKBQS0Nabhai/EqB0xFeBrJ+Gk6x4mydK1un6z5NPDscb9BIiCaz6BqhwWI/Jutlu9zk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PELOvD6H; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PELOvD6H" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4853c1ca73aso45609385e9.2 for ; Mon, 30 Mar 2026 07:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774880248; x=1775485048; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=QXTFV6k0jK20NuLbc5kRmXLlkPvSMTXhcz7AgsD36j4=; b=PELOvD6HHZ+3o20jk4vU7tJ0dlb+0ItUkwG7+KZhXtN+MeStPdLQVP9++lPZkRbL7Z Vl/XOI1OgJBeK1cVwEz7/EitiBckcBGEKlYy2tNEL8jv5xSVatCCM7r8e304A/I5rrj1 UvKlDOM+q/5d74TAgbBz5cp4/YaGvOdSfZRUIEvRMN3tlqbpi+5HMyQcVN1t9eA8WBD6 XBEJLR+CkoXU+YuchCSmyOb7+BBMCWiw2BwjwGVtyBPg/molOyoj5wythWrMa4889lKJ 3wj2wc05yl1vCDdw1rjuFVrkn9xCbr0MHiJtKOwbOot01weB4afMaFWkuiyBVd6VXaCm HfTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774880248; x=1775485048; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QXTFV6k0jK20NuLbc5kRmXLlkPvSMTXhcz7AgsD36j4=; b=s73/fCfCQa41eHocBRnsI5XINMlen3Z6ieWceut2jlWRFjiW73ui6FokXJ0L+RTHCf FrgmZrTCQ774bNhF/Mg5v+Qc9K6oo2RnC7Auc1rkqzcbcki2KUQtTtztqWA7L6oumfkm ara7kSj+cdNXyFI/0zWFc4E3TNgLDyPh/WiMQtElLOeYxmfVp/Cvo3+cGiF1iuHdIV+b dH5kvs0JWpGzd15/Sd+oFRjAxB39JxeEhhjsWDDQ5t4J0euqXIxkHv+kyWKoHCbKRGxg QtvgOtrHQGPvDUFwVaBxguUlt9z5sAyjwRVyeAAVgo8v0Xtpt9cNhMqqblVWkufXv+u9 1Dgw== X-Forwarded-Encrypted: i=1; AJvYcCX95aaq+Ro2V8W+0c+hOOhezCP586mBkqlYXSNho27LzE8DD2BB5wHwyGBc3k+kR9UrvIrimYQkvzscyes=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4OHpt6rn7Oaor69ivROZPTcxb7Z5Lulhz6n6c9Dll0PauXCBf 5gS8k5UE6WH90gEhUEt2zuVJQlmQmKWJkymMhl68G3PzxGDiqfhjvtG1 X-Gm-Gg: ATEYQzxkrPX0H9qEbonTufF9XbeA0WFJJGkxfdEiZpnavm9+PG+yM/Sc2yPhkGm9XsS V3qXspVbYBKh61E4V7Vw6uYBglI+qaDN2EegsJGwWyDrN6x3sQ+ZosgA4XVaG5EjPy+8rfgnfMY W3pkHzqBFsnHPvxLfZwfU+uJLUHdJaJipRwhl2WSVhW8+zxyfKevcT4Qe5qlhiRhXhyj8GJrr8S cNrWNgqBpE98sTCm05uWyl2MYPti+l2ahrPQsCoKCHyYlVfGDpjsolZrjN9RapSJf/FUCmq46PZ lX8ua4CSkNZB4WPLErSNnckqeQLf7yjCdMPieYapHCPSX3wHGBqzp403FEV9cAu7nr8TEcA2Kfs mhMNcAWut1Y/MXnoA0mPfMdhHemTu7Z3xG4i/sqC4Tv7SVykmidMI86Amk9rsdDme/bfhTrPMXt 88Syw0UkLjfIhc X-Received: by 2002:a05:600c:81c5:b0:46e:4e6d:79f4 with SMTP id 5b1f17b1804b1-48727e90ec7mr192177925e9.15.1774880247693; Mon, 30 Mar 2026 07:17:27 -0700 (PDT) Received: from nsa ([45.94.208.97]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-487270dd790sm172813455e9.5.2026.03.30.07.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 07:17:27 -0700 (PDT) Date: Mon, 30 Mar 2026 15:18:13 +0100 From: Nuno =?utf-8?B?U8Oh?= To: Radu Sabau Cc: Lars-Peter Clausen , Michael Hennerich , Nuno =?utf-8?B?U8Oh?= , David Lechner , Jonathan Cameron , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: adc: ad4695: Fix call ordering in offload buffer postenable Message-ID: References: <20260330-ad4696-fix-v1-1-e841e96451b2@analog.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260330-ad4696-fix-v1-1-e841e96451b2@analog.com> On Mon, Mar 30, 2026 at 04:34:39PM +0300, Radu Sabau wrote: > ad4695_enter_advanced_sequencer_mode() was called after > spi_offload_trigger_enable(), meaning a regular SPI transfer could be in > flight while the offload was already active. When the offload fires its > completion interrupt concurrently with the regular transfer, the SPI > engine interrupt handler is not designed to handle both at once, leading > to a kernel panic. > > Fix this by calling ad4695_enter_advanced_sequencer_mode() before > spi_offload_trigger_enable(), ensuring all SPI bus accesses are complete > before the offload becomes active. This is consistent with the same > constraint that already applies to the BUSY_GP_EN write above it. > > Update the error unwind labels accordingly: add err_exit_conversion_mode > so that a failure of spi_offload_trigger_enable() correctly exits > conversion mode before clearing BUSY_GP_EN. > > Fixes: f09f140e3ea8 ("iio: adc: ad4695: Add support for SPI offload") > Signed-off-by: Radu Sabau > --- > When enabling the IIO buffer for SPI offload operation on AD4695/AD4696, > ad4695_enter_advanced_sequencer_mode() was called after > spi_offload_trigger_enable(), resulting in a regular SPI transfer being > in flight while the offload was already active. This caused a kernel > panic in the SPI engine interrupt handler. > > This series fixes the call ordering so all SPI bus accesses complete > before the offload becomes active, consistent with the constraint that > was already documented for the BUSY_GP_EN write in the same function. > --- LGTM, Reviewed-by: Nuno Sá > drivers/iio/adc/ad4695.c | 31 ++++++++++++++----------------- > 1 file changed, 14 insertions(+), 17 deletions(-) > > diff --git a/drivers/iio/adc/ad4695.c b/drivers/iio/adc/ad4695.c > index cda419638d9a..c6721f5ac8af 100644 > --- a/drivers/iio/adc/ad4695.c > +++ b/drivers/iio/adc/ad4695.c > @@ -866,24 +866,24 @@ static int ad4695_offload_buffer_postenable(struct iio_dev *indio_dev) > return ret; > > /* > - * NB: technically, this is part the SPI offload trigger enable, but it > - * doesn't work to call it from the offload trigger enable callback > - * because it requires accessing the SPI bus. Calling it from the > - * trigger enable callback could cause a deadlock. > + * NB: these are technically part of the SPI offload trigger enable, but > + * they can't be called from the offload trigger enable callback because > + * they require accessing the SPI bus. Calling them from the trigger > + * enable callback could cause a deadlock. > */ > ret = regmap_set_bits(st->regmap, AD4695_REG_GP_MODE, > AD4695_REG_GP_MODE_BUSY_GP_EN); > if (ret) > goto err_unoptimize_message; > > - ret = spi_offload_trigger_enable(st->offload, st->offload_trigger, > - &config); > + ret = ad4695_enter_advanced_sequencer_mode(st, num_slots); > if (ret) > goto err_disable_busy_output; > > - ret = ad4695_enter_advanced_sequencer_mode(st, num_slots); > + ret = spi_offload_trigger_enable(st->offload, st->offload_trigger, > + &config); > if (ret) > - goto err_offload_trigger_disable; > + goto err_exit_conversion_mode; > > mutex_lock(&st->cnv_pwm_lock); > pwm_get_state(st->cnv_pwm, &state); > @@ -895,22 +895,19 @@ static int ad4695_offload_buffer_postenable(struct iio_dev *indio_dev) > ret = pwm_apply_might_sleep(st->cnv_pwm, &state); > mutex_unlock(&st->cnv_pwm_lock); > if (ret) > - goto err_offload_exit_conversion_mode; > + goto err_trigger_disable; > > return 0; > > -err_offload_exit_conversion_mode: > +err_trigger_disable: > /* > - * We have to unwind in a different order to avoid triggering offload. > - * ad4695_exit_conversion_mode() triggers a conversion, so it has to be > - * done after spi_offload_trigger_disable(). > + * ad4695_exit_conversion_mode() triggers a conversion, so the offload > + * must be disabled first to avoid capturing a spurious sample. > */ > spi_offload_trigger_disable(st->offload, st->offload_trigger); > - ad4695_exit_conversion_mode(st); > - goto err_disable_busy_output; > > -err_offload_trigger_disable: > - spi_offload_trigger_disable(st->offload, st->offload_trigger); > +err_exit_conversion_mode: > + ad4695_exit_conversion_mode(st); > > err_disable_busy_output: > regmap_clear_bits(st->regmap, AD4695_REG_GP_MODE, > > --- > base-commit: 11439c4635edd669ae435eec308f4ab8a0804808 > change-id: 20260330-ad4696-fix-186955a8c511 > > Best regards, > -- > Radu Sabau >