drm/mediatek: fix uninitialized symbol
Subsystems (3)
PATCH v2 1/1 drm/mediatek: fix uninitialized symbol
fix Smatch static checker warning
- uninitialized symbol comp_pdev in mtk_ddp_comp_init.
---
v2: add Fixes tag
--- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +4 -1
@@ -546,7 +546,7 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,int mtk_ddp_comp_init (struct device_node *node,struct mtk_ddp_comp *comp,unsigned int comp_id) { -struct platform_device *comp_pdev; +struct platform_device *comp_pdev =NULL ;enum mtk_ddp_comp_type type;struct mtk_ddp_comp_dev *priv;#if IS_REACHABLE (CONFIG_MTK_CMDQ )
@@ -588,6 +588,9 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp, type == MTK_DSI)return 0 ; +if (!comp_pdev) +return -EPROBE_DEFER ; + priv =devm_kzalloc (comp->dev,sizeof (*priv),GFP_KERNEL );if (!priv)return -ENOMEM ;
Signature · 1 line
2.18.0
Il 21/04/23 04:16, Nancy.Lin ha scritto:
Quoted 5 lines
fix Smatch static checker warning
- uninitialized symbolcomp_pdevinmtk_ddp_comp_init.Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")Signed-off-by Nancy.Lin <[email protected]>
Quoted 6 lines · Nancy.Lin
fix Smatch static checker warning
- uninitialized symbolcomp_pdevinmtk_ddp_comp_init.Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")Signed-off-by Nancy.Lin <[email protected]>
This seems to be unnoticed and I just want to get some attention for it. Any action items here?
Regards,
Fei
Quoted 33 lines
---
v2: add Fixes tag--- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +4
-2@@ -546,7 +546,7 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,int mtk_ddp_comp_init (struct device_node *node,struct mtk_ddp_comp *comp,unsigned int comp_id) { -struct platform_device *comp_pdev; +struct platform_device *comp_pdev =NULL ;enum mtk_ddp_comp_type type;struct mtk_ddp_comp_dev *priv;#if IS_REACHABLE (CONFIG_MTK_CMDQ )@@ -588,6 +588,9 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp, type == MTK_DSI)return 0 ; +if (!comp_pdev) +return -EPROBE_DEFER ; + priv =devm_kzalloc (comp->dev,sizeof (*priv),GFP_KERNEL );if (!priv)return -ENOMEM ; --2.18.0
Hi, Nancy:
Quoted 29 lines · Nancy.Lin
fix Smatch static checker warning
- uninitialized symbolcomp_pdevinmtk_ddp_comp_init.Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driverfor MT8195")
Signed-off-by Nancy.Lin <[email protected]>---
v2: add Fixes tag--- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +1
-1@@ -546,7 +546,7 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm, int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp, unsigned int comp_id) { - struct platform_device *comp_pdev; + struct platform_device *comp_pdev = NULL;enum mtk_ddp_comp_type type;drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +0
-0struct mtk_ddp_comp_dev *priv;#if IS_REACHABLE (CONFIG_MTK_CMDQ )
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c int mtk_ddp_comp_init(struct device_node *node, · line 593
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +2
-0@@ -588,6 +588,9 @@ int mtk_ddp_comp_init(struct device_node *node,struct mtk_ddp_comp *comp, type == MTK_DSI) return 0; +if (!comp_pdev) +return -EPROBE_DEFER ;
In line 566, the statement is
if (nodo) {
comp_pdev = ...
}The comment says that only ovl_adaptoer has no device node, so the checking should be
if (type != MTK_DISP_OVL_ADAPTOR) {
comp_pdev = ...
}and later it would return when type = MTK_DISP_OVL_ADAPTOR, so there would be no problem of uninitialized symbol.
Regards,
CK
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +1
-0+ priv =devm_kzalloc (comp->dev,sizeof (*priv),GFP_KERNEL );if (!priv)return
-ENOMEM;
Hi CK,
Quoted 4 lines · CK Hu (胡俊光)
Hi, Nancy:
On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
snip
Quoted 10 lines
In line 566, the statement is
if (nodo) { comp_pdev = ... }The comment says that only
ovl_adaptoerhas no device node, so the checking should be
Quoted 6 lines
if (type != MTK_DISP_OVL_ADAPTOR) { comp_pdev = ... }and later it would return when type =
MTK_DISP_OVL_ADAPTOR, so there would be no problem of uninitialized symbol.
That sounds fair, but IIUC what Nancy tries to resolve here is the false-positive Smatch warning.
How about this: given the if (node) block was exclusively added for ovl_adaptor in [1], plus the init function will immediately return after that in this case, it should be safe to do the following
```
/* Not all drm components have a DTS device node... */
if (node == NULL)
return 0;
comp_pdev = of_find_device_by_node(node);
...
if (type == MTK_DISP_AAL ||
...
```which is equivalent to adding a node == NULL check before [1]. This should suppress the Smatch warning because comp_pdev will be (again) unconditionally assigned to something, and the type == MTK_DISP_OVL_ADAPTOR line can be dropped also (optional?).
[1]: commit 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")
Regards,
Fei
Hi, Fei:
Quoted 47 lines · Fei Shao
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi CK,Quoted 4 lines · CK Hu (胡俊光)
Hi, Nancy:
On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
snip
Quoted 10 lines
In line 566, the statement is
if (nodo) { comp_pdev = ... }The comment says that only
ovl_adaptoerhas no device node, so the checking should beQuoted 6 lines
if (type != MTK_DISP_OVL_ADAPTOR) { comp_pdev = ... }and later it would return when type =
MTK_DISP_OVL_ADAPTOR, so there would be no problem of uninitialized symbol.That sounds fair, but IIUC what Nancy tries to resolve here is the false-positive Smatch warning.
How about this: given theif (node)block was exclusively added forovl_adaptorin [1], plus the init function will immediately return after that in this case, it should be safe to do the following``` /* Not all drm components have a DTS device node... */ if (node == NULL) return 0; comp_pdev = of_find_device_by_node(node); ... if (type == MTK_DISP_AAL || ... ```
Quoted 4 lines
which is equivalent to adding a
node == NULLcheck before [1]. This should suppress the Smatch warning becausecomp_pdevwill be (again) unconditionally assigned to something, and thetype == MTK_DISP_OVL_ADAPTORline can be dropped also (optional?).
This solution also looks good to me.
Regards,
CK
Quoted 6 lines
[1]: commit
0d9eee9118b7("drm/mediatek: Add drmovl_adaptorsub driver for MT8195")Regards,
Fei
Hi CK and Fei,
Thanks for the review.
Quoted 59 lines · CK Hu (胡俊光)
Hi, Fei:
Quoted 51 lines · Fei Shao
External email : Please do not click links or open attachments until
you have verified the sender or the content.
Hi CK,Quoted 4 lines · CK Hu (胡俊光)
Hi, Nancy:
On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
snip
Quoted 11 lines
In line 566, the statement is
if (nodo) { comp_pdev = ... }The comment says that only
ovl_adaptoerhas no device node, so the
checking should beQuoted 6 lines
if (type != MTK_DISP_OVL_ADAPTOR) { comp_pdev = ... }and later it would return when type =
MTK_DISP_OVL_ADAPTOR, so there would be no problem of uninitialized symbol.That sounds fair, but IIUC what Nancy tries to resolve here is the false-positive Smatch warning.
How about this: given theif (node)block was exclusively added forovl_adaptorin [1], plus the init function will immediately return after that in this case, it should be safe to do the following``` /* Not all drm components have a DTS device node... */ if (node == NULL) return 0; comp_pdev = of_find_device_by_node(node); ... if (type == MTK_DISP_AAL || ... ```Quoted 4 lines
which is equivalent to adding a
node == NULLcheck before [1]. This should suppress the Smatch warning becausecomp_pdevwill be (again) unconditionally assigned to something, and thetype == MTK_DISP_OVL_ADAPTORline can be dropped also (optional?).
Quoted 5 lines
This solution also looks good to me.
Regards,
CK
I will send the next version of modifications based on your suggestions.
Thanks,
Nancy
Quoted 6 lines
Quoted 6 lines
[1]: commit
0d9eee9118b7("drm/mediatek: Add drmovl_adaptorsub driver for MT8195")Regards,
Fei