From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795996879; b=mAZJs/yKPAj3bNUYUAcj8HBtFX6xruBy4GWUuLrAR63MLb1MMYnfIaz4nRdyWlTVeRow 9qIiZCPqZBdMUw+w54KYz6qCYCKthvZWe2A36Axoi48vAwKLShnlBvH4snK2xe35IAvYT WWJbiYCVnWh5NXfndrKAXU1spLxQX05DzES7fENgjr5r2P2B1YPJzoJV0KYfe3vQfeXiM zIHno5JI9K1dxNqAzWEbqD8ZZNEiH1ryLkOITGBWyLkTq5XjEGs9NOpMcgI37/0ofcEWx 2Vaes8fJORZRXW9MEigOouDJq9263HWnNtVtkYxb8vfuXvHcxys8RpNI4CCS225yg4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795996879; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=Cw08wRlhFLguJjQbKcW+1316jrndBYBra1dUYjls6H0=; b=Y+LcWl76JDn4l010pWeIIBQtQCdkubi5N+9zvd/u6QSxd1P1QNTPwh7R5yRjLUG5vO/9 1UoxslvyA5GM5uNNPneI9soXk2YPXMzK8h4wMwEkqRjbGSWotIvC0gDxeYmzG5MfyqRcU FL4TPwTl84J60OVCVVLIL300Ms+xwI11tQEOKlzvgIwFX6OTF2zxtR9yF+kN5UF4VdKZ5 M+uvXm13d08RJvgBXdi9d70kvutPJtrxn/GKlUQCjpnKaXfxjDBix1S7vsO/x3vFaUrJE On+NSGaeoopcd6mm54W45Q1ZVD7s6udCig6sYSvcSpYBKHPpdzYXYsHcXztGdRdtEVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G9A8IdUz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 139A4606A327; Mon, 30 Nov 2026 00:01:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G9A8IdUz Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE02F1F00897; Mon, 30 Nov 2026 00:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795996878; bh=Cw08wRlhFLguJjQbKcW+1316jrndBYBra1dUYjls6H0=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=G9A8IdUzZePby9m6FqYLX9BuU5OHFCGSxwVDxPpiDpURmGfwEYhWoQIId/oBRRN/E JXk2m7gW8Fu+sPhwOVmv3IXy/WxfJrAtFTVhAnKRUgGZT4l6xQOnyvYyDqC52OmvrZ mEctMI4Uukz4K/9yw2AOmzg9F7+tzgvBfQ4LXg0tfGcBG/0wGOW6QFtKhzf66Crn9A J/aajR0zZeZwmqVUJHtmPOJfJVF8E/qWGZhGJMmOYZ8RPR5hPT5skk6Tb9YVs5tuz6 NoeR2KFYzRb8BptlKU6SoV+z0zdm84y3f9I+F+48av4fMHjYJ5DWegwiEgzrT11BrF VrbGvw9fFAzsQ== Date: Mon, 30 Nov 2026 00:01:10 +0000 From: Jonathan Cameron To: Jonathan Cameron , David Lechner , Nuno =?UTF-8?B?U8Oh?= , Andy Shevchenko , Tomislav Denis , Matt Ranostay , Abhash Jha , Petre Rodan , =?UTF-8?B?TcOlcnRlbg==?= Lindahl , Dan Murphy , Sean Nyekjaer , Tomas Melin , Michael Hennerich , Lars-Peter Clausen , Leonard Crestez , Peter Meerwald-Stadler , Neil Armstrong , Dixit Parmar , Matti Vaittinen , Stepan Ionichev , Srinivas Pandruvada , Joachim Eastwood , Tiberiu Breana , Maxwell Doose , Tomasz Duszynski , Alison Schofield , Christian Eggers , Andreas Klinger , linux-iio@vger.kernel.org, linux@analog.com Cc: Jonathan Cameron , stable@vger.kernel.org Subject: Re: [PATCH 02/25] iio: potentiostat: lmp91000: fix NULL deref setting immutable trigger Message-ID: <20261130000110.00d93fc0@jic23-hlaptop> In-Reply-To: <20261129-messing-fixes3323-v1-2-f01aa73aa628@oss.qualcomm.com> References: <20261129-messing-fixes3323-v1-0-f01aa73aa628@oss.qualcomm.com> <20261129-messing-fixes3323-v1-2-f01aa73aa628@oss.qualcomm.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 29 Nov 2026 21:06:13 +0000 Jonathan Cameron wrote: > From: Jonathan Cameron > > lmp91000_probe() calls iio_channel_cb_get_iio_dev(data->cb_buffer) to > find the ADC device on which to set the immutable trigger, but > data->cb_buffer is only assigned later by iio_channel_get_all_cb(). At > that point it is still NULL, so iio_channel_cb_get_iio_dev() dereferences > a NULL pointer. > > The call also took place before the trigger was registered, which > triggers the WARN_ONCE() in iio_trigger_get() for an unregistered > trigger. > > Move the call to after the callback buffer has been obtained, when the > trigger is also registered, and unwind the callback buffer on failure. > > Fixes: 67e17300dc1d ("iio: potentiostat: add LMP91000 support") > Cc: stable@vger.kernel.org > Signed-off-by: Jonathan Cameron > FWIW the sashiko comment on this one about leaking the immutable trigger reference is entirely correct. It is addressed in the series that follows which focuses on immutable triggers in general. For now, just leak it. > --- > > LLM found this one whilst I was working on a broader cleanup. > Note despite this being a nasty bug I'll most likely take it for > the next merge window as I have a large series coming on top > of this. > --- > drivers/iio/potentiostat/lmp91000.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c > index 53f181cbc0b8..676e5e962a93 100644 > --- a/drivers/iio/potentiostat/lmp91000.c > +++ b/drivers/iio/potentiostat/lmp91000.c > @@ -330,13 +330,6 @@ static int lmp91000_probe(struct i2c_client *client) > if (ret) > return ret; > > - ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer), > - data->trig); > - if (ret) { > - dev_err(dev, "cannot set immutable trigger.\n"); > - return ret; > - } > - > ret = iio_trigger_register(data->trig); > if (ret) { > dev_err(dev, "cannot register iio trigger.\n"); > @@ -363,6 +356,13 @@ static int lmp91000_probe(struct i2c_client *client) > > data->adc_chan = iio_channel_cb_get_channels(data->cb_buffer); > > + ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer), > + data->trig); > + if (ret) { > + dev_err(dev, "cannot set immutable trigger.\n"); > + goto error_unreg_cb_buffer; > + } > + > ret = iio_device_register(indio_dev); > if (ret) > goto error_unreg_cb_buffer; >