[PATCH] drm/mediatek: fix uninitialized symbol

8 views
Skip to first unread message

Nancy.Lin

unread,
Apr 20, 2023, 6:51:27 AM4/20/23
to Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, AngeloGioacchino Del Regno, David Airlie, Daniel Vetter, dri-...@lists.freedesktop.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Project_Global_Chr...@mediatek.com, singo...@mediatek.com, Nancy.Lin
fix Smatch static checker warning
- uninitialized symbol comp_pdev in mtk_ddp_comp_init.

Signed-off-by: Nancy.Lin <nanc...@mediatek.com>
---
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index f114da4d36a9..e987ac4481bc 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -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

AngeloGioacchino Del Regno

unread,
Apr 20, 2023, 8:02:03 AM4/20/23
to Nancy.Lin, Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, David Airlie, Daniel Vetter, dri-...@lists.freedesktop.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Project_Global_Chr...@mediatek.com, singo...@mediatek.com
Il 20/04/23 12:51, Nancy.Lin ha scritto:
> fix Smatch static checker warning
> - uninitialized symbol comp_pdev in mtk_ddp_comp_init.
>
> Signed-off-by: Nancy.Lin <nanc...@mediatek.com>

I agree with this commit, but please add a Fixes tag.

Thanks,
Angelo

Nancy Lin (林欣螢)

unread,
Apr 20, 2023, 10:11:53 PM4/20/23
to p.z...@pengutronix.de, matthi...@gmail.com, angelogioacc...@collabora.com, chunku...@kernel.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, Singo Chang (張興國), dan...@ffwll.ch, dri-...@lists.freedesktop.org, Project_Global_Chrome_Upstream_Group, air...@gmail.com, clang-bu...@googlegroups.com, linux-ar...@lists.infradead.org
Hi Angelo,

On Thu, 2023-04-20 at 14:01 +0200, AngeloGioacchino Del Regno wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> Il 20/04/23 12:51, Nancy.Lin ha scritto:
> > fix Smatch static checker warning
> >    - uninitialized symbol comp_pdev in mtk_ddp_comp_init.
> > 
> > Signed-off-by: Nancy.Lin <nanc...@mediatek.com>
> 
> I agree with this commit, but please add a Fixes tag.
> 
> Thanks,
> Angelo

Thanks for the review. I will resend it with Fixes tag.

Regards,
Nancy



************* MEDIATEK Confidentiality Notice
 ********************
The information contained in this e-mail message (including any 
attachments) may be confidential, proprietary, privileged, or otherwise
exempt from disclosure under applicable laws. It is intended to be 
conveyed only to the designated recipient(s). Any use, dissemination, 
distribution, printing, retaining or copying of this e-mail (including its 
attachments) by unintended recipient(s) is strictly prohibited and may 
be unlawful. If you are not an intended recipient of this e-mail, or believe
 
that you have received this e-mail in error, please notify the sender 
immediately (by replying to this e-mail), delete any and all copies of 
this e-mail (including any attachments) from your system, and do not
disclose the content of this e-mail to any other person. Thank you!

Nancy.Lin

unread,
Apr 20, 2023, 10:16:19 PM4/20/23
to Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, AngeloGioacchino Del Regno, David Airlie, Daniel Vetter, dri-...@lists.freedesktop.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Project_Global_Chr...@mediatek.com, singo...@mediatek.com, 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")
Signed-off-by: Nancy.Lin <nanc...@mediatek.com>
---
v2: add Fixes tag

AngeloGioacchino Del Regno

unread,
Apr 24, 2023, 3:04:06 AM4/24/23
to Nancy.Lin, Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, David Airlie, Daniel Vetter, dri-...@lists.freedesktop.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Project_Global_Chr...@mediatek.com, singo...@mediatek.com
Il 21/04/23 04:16, Nancy.Lin ha scritto:
> 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")
> Signed-off-by: Nancy.Lin <nanc...@mediatek.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacc...@collabora.com>


Fei Shao

unread,
Jul 12, 2023, 11:35:22 PM7/12/23
to Nancy.Lin, Chun-Kuang Hu, Philipp Zabel, Matthias Brugger, AngeloGioacchino Del Regno, David Airlie, Daniel Vetter, dri-...@lists.freedesktop.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Project_Global_Chr...@mediatek.com, singo...@mediatek.com
On Fri, Apr 21, 2023 at 10:16 AM Nancy.Lin <nanc...@mediatek.com> wrote:
>
> 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")
> Signed-off-by: Nancy.Lin <nanc...@mediatek.com>

Reviewed-by: Fei Shao <fs...@chromium.org>

This seems to be unnoticed and I just want to get some attention for
it. Any action items here?

Regards,
Fei

CK Hu (胡俊光)

unread,
Jul 14, 2023, 5:27:26 AM7/14/23
to p.z...@pengutronix.de, Nancy Lin (林欣螢), matthi...@gmail.com, chunku...@kernel.org, angelogioacc...@collabora.com, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, linux-m...@lists.infradead.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Singo Chang (張興國), Project_Global_Chrome_Upstream_Group
Hi, Nancy:

On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
> 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")
> Signed-off-by: Nancy.Lin <nanc...@mediatek.com>
> ---
> v2: add Fixes tag
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index f114da4d36a9..e987ac4481bc 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -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;

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

> +
>  priv = devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL);
>  if (!priv)
>  return -ENOMEM;

Fei Shao

unread,
Jul 17, 2023, 12:00:17 AM7/17/23
to CK Hu (胡俊光), p.z...@pengutronix.de, Nancy Lin (林欣螢), matthi...@gmail.com, chunku...@kernel.org, angelogioacc...@collabora.com, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, linux-m...@lists.infradead.org, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, Singo Chang (張興國), Project_Global_Chrome_Upstream_Group
Hi CK,

On Fri, Jul 14, 2023 at 5:27 PM CK Hu (胡俊光) <ck...@mediatek.com> wrote:
>
> Hi, Nancy:
>
> On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
snip
>
> 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.

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

CK Hu (胡俊光)

unread,
Jul 20, 2023, 3:52:56 AM7/20/23
to fs...@chromium.org, linux-m...@lists.infradead.org, linux-...@vger.kernel.org, Singo Chang (張興國), chunku...@kernel.org, Nancy Lin (林欣螢), p.z...@pengutronix.de, dri-...@lists.freedesktop.org, Project_Global_Chrome_Upstream_Group, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, matthi...@gmail.com, angelogioacc...@collabora.com
Hi, Fei:

On Mon, 2023-07-17 at 11:59 +0800, Fei Shao wrote:
>   
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  Hi CK,
> 
> On Fri, Jul 14, 2023 at 5:27 PM CK Hu (胡俊光) <ck...@mediatek.com>
> wrote:
> >
> > Hi, Nancy:
> >
> > On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
> snip
> >
> > 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.
> 
> 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?).

This solution also looks good to me.

Regards,
CK

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

Nancy Lin (林欣螢)

unread,
Aug 3, 2023, 4:33:02 AM8/3/23
to CK Hu (胡俊光), fs...@chromium.org, linux-...@vger.kernel.org, linux-m...@lists.infradead.org, Singo Chang (張興國), chunku...@kernel.org, p.z...@pengutronix.de, dri-...@lists.freedesktop.org, Project_Global_Chrome_Upstream_Group, linux-ar...@lists.infradead.org, clang-bu...@googlegroups.com, matthi...@gmail.com, angelogioacc...@collabora.com
Hi CK and Fei,

Thanks for the review.

On Thu, 2023-07-20 at 07:52 +0000, CK Hu (胡俊光) wrote:
> Hi, Fei:
> 
> On Mon, 2023-07-17 at 11:59 +0800, Fei Shao wrote:
> >   
> > External email : Please do not click links or open attachments
> > until
> > you have verified the sender or the content.
> >  Hi CK,
> > 
> > On Fri, Jul 14, 2023 at 5:27 PM CK Hu (胡俊光) <ck...@mediatek.com>
> > wrote:
> > > 
> > > Hi, Nancy:
> > > 
> > > On Fri, 2023-04-21 at 10:16 +0800, Nancy.Lin wrote:
> > 
> > snip
> > > 
> > > 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.
> > 
> > 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?).
> 
> This solution also looks good to me.
> 
> Regards,
> CK
> 
I will send the next version of modifications based on your
suggestions.

Thanks,
Nancy

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

Reply all
Reply to author
Forward
0 new messages