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=1795908194; b=BgEfMwaJBNRsoOxrk8O2hiKN+dMSXxPxh76ZmVVLE7MWvs19ccTUnhpx+CnSWhhkQoGR n9UFzxo2NKO5pd6jkDXB9cdi8iVfFkmVKitXs/T7pLjpZGAJ2zWm2xqKkUxfr5bXCakEL h3/vejOUFP386rBHznMmkCxELCu+O0WHu7WTEjppSD+eCghv3E8JObgskwwFT9KUDK2LM D5QxfK8c6rgo72tZ3INU30iDWNenG1ud+dMVvhT9t7Y/VfwK4eMgDwMfczNt9DoBz4pmI i8BN2BoY0iuXpUvpGsqebRWjkCPNuevZOIJhTAyQLarOqfeeaZSVyfLMNUfiUPee4Kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795908194; 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=vYkVd2p3Y5S3gaTOUsWPi96s52wg2iDxTk8T517wbgA=; b=d1yRyuMKVl31PUyiXJ3X+VPPH1x1UOvjTTJTcRY6GaYKDtMuIgAJqXcvP3GAogTTwMs8 8SKiX37REm+PID7KuazgIfJ9G8IVXllrl3+qD5xdruv+0Phz8jDAksQ42/wQGlISU5O02 GY8REMTd7rQ3Wp7zjS7yWDMiwD9hFX1W3tO2taUT5VoqZ82fqw/sI3vVl3qCgDRtrRn3m 8x4behOIHCU6TCP51U1pYw3pv4fINBSopq1NWBn+/KZbgbdtTnjxBx5bJAmZ9OEf8Fh18 PRVu8VRogHfxr/2Z60MrmfBVHypgr/oVoHLX77IXE8t1A2z9WrHr+5/4LS/ScqteVng== 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=lVhOIyjM; 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)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED6D6606A31C; Sat, 28 Nov 2026 23:23:13 +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=lVhOIyjM Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0F8D1F000C1; Sat, 28 Nov 2026 23:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795908193; bh=vYkVd2p3Y5S3gaTOUsWPi96s52wg2iDxTk8T517wbgA=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=lVhOIyjMihDmxIuneEjY55GcWGeeNCc/LI7v9kUoWfDQyJ18ojpTCxlRu7A1DqljH vbxYI6I/gTK8ktj1Ec/uUeUQEyQL0jzveMC4IAnaO6ZcYqoyajv+WXjxoKG1Lb6LAq 5aCD8FzufVbzvdiQxZgTTENlGqdEJSH0u8CLvJLR8z+IZh/epkNUDypdlyZ/okX9JD 9FzawDfa3COOCSjYZ+DuXwLYx9vvClEExaqeCS4Zrd2FvsGXZWkTUkvIPEaZJrO4W7 udIVYRvtIEnYr/Xk+Gge2P2VKqPwG4iIdsO2O2xP01Cb6IQJDkYd8gp6ShSnW7PQLb PoDZvYy6UihaQ== Date: Sat, 28 Nov 2026 23:23:07 +0000 From: Jonathan Cameron To: Lee Jones Cc: David Lechner , Nuno =?UTF-8?B?U8Oh?= , Andy Shevchenko , Jishnu Prakash , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Message-ID: <20261128232307.672c92ba@jic23-hlaptop> In-Reply-To: <20261123075122.373060-6-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> <20261123075122.373060-6-lee@kernel.org> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@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 Mon, 23 Nov 2026 07:50:31 +0000 Lee Jones wrote: > struct tm5_aux_dev_wrapper embeds a reference-counted struct > auxiliary_device, whose memory must be released from its dev.release > callback once the final device reference is dropped. > > Allocating the wrapper and its tm_props array with parent-managed > devm_*() helpers and providing an empty adc5_gen3_aux_device_release() > causes parent devres teardown to free both allocations immediately when > the parent unbinds, even if external references to the embedded struct > device are still held. It also leaks the OF node reference taken by > device_set_of_node_from_dev(). > > Allocate the wrapper and tm_props array without devm, release them > together with the OF node reference in adc5_gen3_aux_device_release(), > and register auxiliary_device_destroy() via devm_add_action_or_reset() > once the auxiliary device has been added. > > Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC") > Closes: https://sashiko.dev/#/bug/linux-b738d116-f32b-4edf-aa73-77827b79a407 > Cc: stable@vger.kernel.org > Signed-off-by: Lee Jones For this and next looking for a tag from Jishnu or someone else familiar with the part. thanks, Jonathan > --- > > v1 => v2: > - Allocate tm_props without devm and release it alongside the OF node > reference in adc5_gen3_aux_device_release() (Jonathan) > - Move auxiliary_device_init() earlier and register > auxiliary_device_destroy() via devm_add_action_or_reset(), avoiding > devm_release_action() (Andy, Jonathan) > - Note: is already included > > drivers/iio/adc/qcom-spmi-adc5-gen3.c | 57 +++++++++++++-------------- > 1 file changed, 27 insertions(+), 30 deletions(-) > > diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c > index a23eb5c9096d..85450aa37e65 100644 > --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c > +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c > @@ -21,9 +21,11 @@ > #include > #include > #include > +#include > #include > #include > #include > +#include > #include > #include > > @@ -598,24 +600,22 @@ static int adc5_get_fw_data(struct adc5_chip *adc) > return 0; > } > > -static void adc5_gen3_uninit_aux(void *data) > +static void adc5_gen3_aux_device_release(struct device *dev) > { > - auxiliary_device_uninit(data); > -} > + struct tm5_aux_dev_wrapper *aux_device = > + container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev); > > -static void adc5_gen3_delete_aux(void *data) > -{ > - auxiliary_device_delete(data); > + of_node_put(dev->of_node); > + kfree(aux_device->tm_props); > + kfree(aux_device); > } > > -static void adc5_gen3_aux_device_release(struct device *dev) {} > - > static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) > { > struct tm5_aux_dev_wrapper *aux_device; > int i, ret, i_tm = 0; > > - aux_device = devm_kzalloc(adc->dev, sizeof(*aux_device), GFP_KERNEL); > + aux_device = kzalloc_obj(*aux_device); > if (!aux_device) > return -ENOMEM; > > @@ -624,11 +624,20 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) > aux_device->aux_dev.dev.parent = adc->dev; > aux_device->aux_dev.dev.release = adc5_gen3_aux_device_release; > > - aux_device->tm_props = devm_kcalloc(adc->dev, adc->n_tm_channels, > - sizeof(*aux_device->tm_props), > - GFP_KERNEL); > - if (!aux_device->tm_props) > + ret = auxiliary_device_init(&aux_device->aux_dev); > + if (ret) { > + kfree(aux_device); > + return ret; > + } > + > + device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev); > + > + aux_device->tm_props = kzalloc_objs(*aux_device->tm_props, > + adc->n_tm_channels); > + if (!aux_device->tm_props) { > + auxiliary_device_uninit(&aux_device->aux_dev); > return -ENOMEM; > + } > > aux_device->dev_data = &adc->dev_data; > > @@ -639,28 +648,16 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) > i_tm++; > } > > - device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev); > - > aux_device->n_tm_channels = adc->n_tm_channels; > > - ret = auxiliary_device_init(&aux_device->aux_dev); > - if (ret) > - return ret; > - > - ret = devm_add_action_or_reset(adc->dev, adc5_gen3_uninit_aux, > - &aux_device->aux_dev); > - if (ret) > - return ret; > - > ret = auxiliary_device_add(&aux_device->aux_dev); > - if (ret) > - return ret; > - ret = devm_add_action_or_reset(adc->dev, adc5_gen3_delete_aux, > - &aux_device->aux_dev); > - if (ret) > + if (ret) { > + auxiliary_device_uninit(&aux_device->aux_dev); > return ret; > + } > > - return 0; > + return devm_add_action_or_reset(adc->dev, auxiliary_device_destroy, > + &aux_device->aux_dev); > } > > void adc5_gen3_mutex_lock(struct device *dev)