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=1796242878; b=LYR7sGJ7wr+Ug6T/0lCTCLklPSTDvEYEoqfTVq0yLsFbFkRQj7IIKhynnabwAiwv+H31 qi5qhOpsh/MVI7cAzw1UzDsFD9bPBkJ1p/7vLx7pe59Pp/7dv8QGcKSic9YzEJJM6BoK3 Yi0O9iGAMwjiXrzc5QaRU/eABuDnP1BNB+Y2ssULnmXpGn5uZkwMwngIMf1C3DbfmODrE dRaxJ3NyDkx1J3ImbTDVXMNFi9cGbijtf9PXG6xG1J4+5IJhoiBnV0GYK6I22OHJ20Go7 tsTZY8IkD2VE5hzlIBfwf6fgPhHG6+atA2Gq+0eWItXF0FAa4w/1vkRDyD7wyQ0nHxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796242878; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=QeoWHI2wJSZdW3GSmHsr+KE5OreXfs4ohnaDNVhXLWY=; b=qi2ltbnQXn1IcIPfjkdY9JSae2Y0TDLEWgJvA05E8Io+HKEBneq+yzH0UL9/Oa6zOM0n J5CWjnJsNKk7gFIm1UeJBKxh3wwu710htg6M5SbGD209yOK2HJJvYWiADKuc0juW/EXP5 wUck8EkdVoUhvn9U95Eh++QPaVgyRpMkQ/AC78udtJbANWNc2mB99BSCNqyls5zvcRAo3 UzRbxVSr9K2hZmPibX1q2KRWMtkly/KLk6TlQMQ19sNqysWhcUE5t7+wrdcjKxXdfsrH+ jxypDUhWdlPzdIUPtlpiwXCBQgc/XPKv1WKE5kVH9NfykVSI7whBQIej1NJiElWidlg== 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=VUrUQurf; 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 B2E08606A336; Wed, 2 Dec 2026 20:21: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=VUrUQurf Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6D1B1F00897; Wed, 2 Dec 2026 20:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796242878; bh=QeoWHI2wJSZdW3GSmHsr+KE5OreXfs4ohnaDNVhXLWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VUrUQurfCAvpU5I4nQdqZpKJY71yYeOuzwRB+elYdES4DCVVybhxoJ0Fqtzc95+dX 1xVzl+OOwslmz9n//ywds/hHj+u8j16SDHmh+rcgjeNXRSmF9y+APnIuDhE6VmA+l0 mWLMguQgp6zL6HHxymTbBTY9sBNxEvLvvdLA6npbLcYOp7nnkPFEzljQjm9KIy4RnW H+WxLNtQwDOM+Kb4146kKlE4w8vheRjOpxxKI+ZLE/yauGvJ/aXkUzQhOY+p9LJUYi ZR/r900rjQ5FAtKakcekujZhApQu2rCR7xryICGYAsypoX3G7hJJY7QlA9ukwjGc4d vuJUkj3jYMwPw== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , David Lechner , Jishnu Prakash , Jonathan Cameron , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH v3 1/3] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Date: Wed, 2 Dec 2026 20:21:10 +0000 Message-ID: X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: linux-arm-msm@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=UTF-8 Content-Transfer-Encoding: 8bit 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 --- v2 => v3: - Rebase onto fixes-togreg (resolving devm_kzalloc_obj() conversion) v1 => v2: - Include linux/container_of.h (Andy) - Move auxiliary_device_init() earlier and drop devm_release_action() unwinding in favour of a single auxiliary_device_destroy() devm action (Jonathan, Andy) - Move tm_props allocation out of devm and free it alongside the wrapper and OF node reference in adc5_gen3_aux_device_release() (Jonathan) Cc: "Nuno Sá" Cc: Andy Shevchenko Cc: David Lechner Cc: Jishnu Prakash Cc: Jonathan Cameron Cc: linux-arm-msm@vger.kernel.org Cc: linux-iio@vger.kernel.org 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 308d431e6217..a9d3f93af6ac 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 @@ -597,24 +599,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_obj(adc->dev, *aux_device); + aux_device = kzalloc_obj(*aux_device); if (!aux_device) return -ENOMEM; @@ -623,11 +623,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_kzalloc_objs(adc->dev, - *aux_device->tm_props, - adc->n_tm_channels); - 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; @@ -638,28 +647,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) -- 2.56.1.911.g883d8bcb20-goog