media: mediatek: vcodec: Add scp_put() to free the scp
Subsystems (3)
PATCH 1/1 media: mediatek: vcodec: Add scp_put() to free the scp
Add scp_put() to free the scp if devm_kzalloc() fails to avoid memory leak.
--- .../platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c +4 -1
@@ -79,8 +79,11 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use } fw =devm_kzalloc (&plat_dev->dev,sizeof (*fw),GFP_KERNEL ); -if (!fw) +if (!fw) { +scp_put (scp);return ERR_PTR (-ENOMEM ); + } + fw->type =SCP ; fw->ops = &mtk_vcodec_rproc_msg; fw->scp = scp;
Signature · 1 line
2.25.1
Hey Jiasheng,
---- On Fri, 31 Jan 2025 02:28:30 +0100 Jiasheng Jiang <[email protected]> wrote ---
Quoted 2 lines
Add
scp_put()to free the scp ifdevm_kzalloc()fails to avoid memory leak.
Your commit message sounds a bit like you copy-pasted your code into the commit message. What kind of memory is leaking here? Are we talking about SRAM memory?
I'd reword the commit message to something like this to give a bit more context:
On Mediatek devices with a system companion processor (SCP) the mtk_scp structure has to be removed explicitly to avoid a memory leak. Free the structure in case the allocation of the firmware structure fails during the firmware initialization.
---
Additionally, the commit title says close to nothing to the reader as well. How about: Fix memory leak in FW initialization
But as I stated above you should clarify what kind of memory we are talking about here.
Also just out of interest have you ever actually experienced issues with this? It seems to me that the situation where you run out of Kernel memory should be quite rare.
Regards,
Sebastian
Quoted 29 lines
Fixes 53dbe0850444 ("media: mtk-vcodec: potential null pointer deference in SCP")Signed-off-by Jiasheng Jiang <[email protected]>--- .../platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c +4
-1@@ -79,8 +79,11 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use } fw =devm_kzalloc (&plat_dev->dev,sizeof (*fw),GFP_KERNEL ); -if (!fw) +if (!fw) { +scp_put (scp);return ERR_PTR (-ENOMEM ); + } + fw->type =SCP ; fw->ops = &mtk_vcodec_rproc_msg; fw->scp = scp;Signature · 1 line
2.25.1
Hi Sebastian,
Quoted 16 lines · Sebastian Fricke
Hey Jiasheng,
---- On Fri, 31 Jan 2025 02:28:30 +0100 Jiasheng Jiang <[email protected]> wrote ---
Quoted 2 lines
Add
scp_put()to free the scp ifdevm_kzalloc()fails to avoid memory leak.Your commit message sounds a bit like you copy-pasted your code into the commit message. What kind of memory is leaking here? Are we talking about SRAM memory?
I'd reword the commit message to something like this to give a bit more context:On Mediatek devices with a system companion processor (SCP) the
mtk_scpstructure has to be removed explicitly to avoid a memory leak. Free the structure in case the allocation of the firmware structure fails during the firmware initialization.---
Quoted 7 lines
Additionally, the commit title says close to nothing to the reader as well. How about: Fix memory leak in FW initialization
But as I stated above you should clarify what kind of memory we are talking about here.
Also just out of interest have you ever actually experienced issues with this? It seems to me that the situation where you run out of Kernel memory should be quite rare.
Yes, I just detected such a bug with a static analysis tool and I have no idea how to trigger it.
I will submit a v2 to reword the commit message.
Thanks,
Jiasheng
Quoted 34 lines
Regards,
SebastianQuoted 29 lines
Fixes 53dbe0850444 ("media: mtk-vcodec: potential null pointer deference in SCP")Signed-off-by Jiasheng Jiang <[email protected]>--- .../platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c +4
-2@@ -79,8 +79,11 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use } fw =devm_kzalloc (&plat_dev->dev,sizeof (*fw),GFP_KERNEL ); -if (!fw) +if (!fw) { +scp_put (scp);return ERR_PTR (-ENOMEM ); + } + fw->type =SCP ; fw->ops = &mtk_vcodec_rproc_msg; fw->scp = scp; --2.25.1
PATCH v2 1/1 media: mediatek: vcodec: Fix a resource leak related to the scp device in FW initialization
In reply to Sebastian FrickeOn Mediatek devices with a system companion processor (SCP) the mtk_scp structure has to be removed explicitly to avoid a resource leak. Free the structure in case the allocation of the firmware structure fails during the firmware initialization.
---
Changelog:
v1 -> v2:
1. Reword the commit message to give more context.
--- .../platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_scp.c +4 -1
@@ -79,8 +79,11 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use } fw =devm_kzalloc (&plat_dev->dev,sizeof (*fw),GFP_KERNEL ); -if (!fw) +if (!fw) { +scp_put (scp);return ERR_PTR (-ENOMEM ); + } + fw->type =SCP ; fw->ops = &mtk_vcodec_rproc_msg; fw->scp = scp;
Signature · 1 line
2.25.1