Skip to contentSkip to conversation

drm/mediatek: fix uninitialized symbol

PATCH Superseded Nancy.Lin 4 participants 7 messages Apr 21, 2023 – Aug 3, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nancy.Lin

author
#0 lore raw

PATCH v2 1/1 drm/mediatek: fix uninitialized symbol

fix Smatch static checker warning
- uninitialized symbol comp_pdev in mtk_ddp_comp_init.

Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")

---
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
index f114da4d36a9..e987ac4481bc 100644
@@ -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
Reviewed-by on v2 1/1
#2 lore raw
In reply to Nancy.Lin
Quoted 6 lines · Nancy.Lin

fix Smatch static checker warning
- uninitialized symbol comp_pdev in mtk_ddp_comp_init.

Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")

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
index f114da4d36a9..e987ac4481bc 100644
@@ -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

#3 lore raw
In reply to Nancy.Lin

Hi, Nancy:

Quoted 29 lines · Nancy.Lin

fix Smatch static checker warning
- uninitialized symbol comp_pdev in mtk_ddp_comp_init.

Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver

for MT8195")

---
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
index f114da4d36a9..e987ac4481bc 100644
@@ -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 -0
 	struct 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;

#4 lore raw

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_adaptoer has 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

#5 lore raw

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_adaptoer has 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 ||
...
```
Quoted 4 lines

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?).

This solution also looks good to me.

Regards,
CK

Quoted 6 lines

[1]: commit 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")

Regards,
Fei

#6 lore raw

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_adaptoer has 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 ||
...
```
Quoted 4 lines

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?).

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 drm ovl_adaptor sub driver for MT8195")

Regards,
Fei