Message ID | 20241104084529.2113302-1-joe@pf.is.s.u-tokyo.ac.jp |
---|---|
State | Superseded |
Headers | show |
Series | media: platform: exynos4-is: Fix memory leak in fimc_md_is_isp_available | expand |
On 04/11/2024 09:45, Joe Hattori wrote: > In fimc_md_is_isp_available(), of_get_child_by_name() is called to check Subject: We do not call it a memory leak. This is an OF node reference leak. > if FIMC-IS is available. Current code does not decrement the refcount of > the returned device node, which causes memory leak. Fix the bug by Same here. > calling of_node_put() at the end of the variable scope. > > Fixes: e781bbe3fecf ("[media] exynos4-is: Add fimc-is subdevs registration") > Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> > --- > drivers/media/platform/samsung/exynos4-is/media-dev.h | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/platform/samsung/exynos4-is/media-dev.h b/drivers/media/platform/samsung/exynos4-is/media-dev.h > index 786264cf79dc..3bbcab9eed6b 100644 > --- a/drivers/media/platform/samsung/exynos4-is/media-dev.h > +++ b/drivers/media/platform/samsung/exynos4-is/media-dev.h > @@ -178,8 +178,9 @@ int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); > #ifdef CONFIG_OF > static inline bool fimc_md_is_isp_available(struct device_node *node) > { > - node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME); > - return node ? of_device_is_available(node) : false; > + struct device_node *fimc_is __free(device_node) = The name convention is in such case 'child', not 'fimc_is' (since 'node' is taken). Best regards, Krzysztof
diff --git a/drivers/media/platform/samsung/exynos4-is/media-dev.h b/drivers/media/platform/samsung/exynos4-is/media-dev.h index 786264cf79dc..3bbcab9eed6b 100644 --- a/drivers/media/platform/samsung/exynos4-is/media-dev.h +++ b/drivers/media/platform/samsung/exynos4-is/media-dev.h @@ -178,8 +178,9 @@ int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); #ifdef CONFIG_OF static inline bool fimc_md_is_isp_available(struct device_node *node) { - node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME); - return node ? of_device_is_available(node) : false; + struct device_node *fimc_is __free(device_node) = + of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME); + return fimc_is ? of_device_is_available(fimc_is) : false; } #else #define fimc_md_is_isp_available(node) (false)
In fimc_md_is_isp_available(), of_get_child_by_name() is called to check if FIMC-IS is available. Current code does not decrement the refcount of the returned device node, which causes memory leak. Fix the bug by calling of_node_put() at the end of the variable scope. Fixes: e781bbe3fecf ("[media] exynos4-is: Add fimc-is subdevs registration") Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> --- drivers/media/platform/samsung/exynos4-is/media-dev.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)