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

firmware: meson_sm: fix device leak at probe

Make sure to drop the reference to the secure monitor device taken by
of_find_device_by_node() when looking up its driver data on behalf of
other drivers (e.g. during probe).

Note that holding a reference to the platform device does not prevent
its driver data from going away so there is no point in keeping the
reference after the helper returns.

Fixes: 8cde3c2153e8 ("firmware: meson_sm: Rework driver as a proper platform driver")
Cc: stable@vger.kernel.org # 5.5
Cc: Carlo Caione <ccaione@baylibre.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Link: https://lore.kernel.org/r/20250725074019.8765-1-johan@kernel.org
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

authored by

Johan Hovold and committed by
Neil Armstrong
8ece3173 8f5ae30d

+6 -1
+6 -1
drivers/firmware/meson/meson_sm.c
··· 232 232 struct meson_sm_firmware *meson_sm_get(struct device_node *sm_node) 233 233 { 234 234 struct platform_device *pdev = of_find_device_by_node(sm_node); 235 + struct meson_sm_firmware *fw; 235 236 236 237 if (!pdev) 237 238 return NULL; 238 239 239 - return platform_get_drvdata(pdev); 240 + fw = platform_get_drvdata(pdev); 241 + 242 + put_device(&pdev->dev); 243 + 244 + return fw; 240 245 } 241 246 EXPORT_SYMBOL_GPL(meson_sm_get); 242 247