Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/genalloc: fix device leak in of_gen_pool_get()

Make sure to drop the reference taken when looking up the genpool platform
device in of_gen_pool_get() before returning the pool.

Note that holding a reference to a device does typically not prevent its
devres managed resources from being released so there is no point in
keeping the reference.

Link: https://lkml.kernel.org/r/20250924080207.18006-1-johan@kernel.org
Fixes: 9375db07adea ("genalloc: add devres support, allow to find a managed pool by device")
Signed-off-by: Johan Hovold <johan@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: <stable@vger.kernel.org> [3.10+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Johan Hovold and committed by
Andrew Morton
1260cbcf 1daf3759

+4 -1
+4 -1
lib/genalloc.c
··· 899 899 if (!name) 900 900 name = of_node_full_name(np_pool); 901 901 } 902 - if (pdev) 902 + if (pdev) { 903 903 pool = gen_pool_get(&pdev->dev, name); 904 + put_device(&pdev->dev); 905 + } 906 + 904 907 of_node_put(np_pool); 905 908 906 909 return pool;