drm/mediatek: fix kernel oops if no crtc is found
Subsystems (3)
PATCH v4 1/2 drm/mediatek: fix kernel oops if no crtc is found
drm_crtc_from_index(0) might return NULL if there are no CRTCs registered at all which will lead to a kernel oops in mtk_drm_crtc_dma_dev_get(). Add the missing return value check.
---
v4:
- collected tags
v3:
- none
v2:
- collected tags
- fixed typos
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +4 -1
@@ -420,6 +420,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)struct mtk_drm_private *private = drm->dev_private;struct mtk_drm_private *priv_n;struct device *dma_dev =NULL ; +struct drm_crtc *crtc;int ret, i, j;if (drm_firmware_drivers_only ())
@@ -494,7 +495,9 @@ static int mtk_drm_kms_init(struct drm_device *drm) }/* Use OVL device for all DMA memory allocations */ - dma_dev =mtk_drm_crtc_dma_dev_get (drm_crtc_from_index (drm,0 )); + crtc =drm_crtc_from_index (drm,0 ); +if (crtc) + dma_dev =mtk_drm_crtc_dma_dev_get (crtc);if (!dma_dev) { ret = -ENODEV ;dev_err (drm->dev,"Need at least one OVL device\n" );
Signature · 1 line
2.39.2
PATCH v4 2/2 drm/mediatek: dpi/dsi: fix possible_crtcs calculation
mtk_drm_find_possible_crtc_by_comp() assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment in mtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 0 and the third path will be 1.
To fix that, dynamically calculate the IDs by the presence of the paths.
While at it, make the return code a signed one and return -ENOENT if no path is found and handle the error in the callers.
---
v4:
- return -ENOENT if mtk_drm_find_possible_crtc_by_comp() doesn't find any path
v3:
- use data instead of priv_n->data
- fixed typos
- collected Rb and Tb tags
v2:
- iterate over all_drm_private[] to get any vdosys
- new check if a path is available
--- drivers/gpu/drm/mediatek/mtk_dpi.c | 5 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 75 ++++++++++++++++----- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 +- drivers/gpu/drm/mediatek/mtk_dsi.c | 5 +- 4 files changed, 68 insertions(+), 20 deletions(-)
drivers/gpu/drm/mediatek/mtk_dpi.c +4 -1
@@ -796,7 +796,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)return ret; } - dpi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); +if (ret <0 ) + goto err_cleanup; + dpi->encoder.possible_crtcs = ret; ret =drm_bridge_attach (&dpi->encoder, &dpi->bridge,NULL ,DRM_BRIDGE_ATTACH_NO_CONNECTOR );
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +59 -16
90 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +1 -2
@@ -277,8 +277,7 @@ static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct devint mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type); -unsigned int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm, -struct device *dev); +int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm,struct device *dev);int mtk_ddp_comp_init (struct device_node *comp_node,struct mtk_ddp_comp *comp,unsigned int comp_id);enum mtk_ddp_comp_type mtk_ddp_comp_get_type (unsigned int comp_id);
drivers/gpu/drm/mediatek/mtk_dsi.c +4 -1
@@ -843,7 +843,10 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)return ret; } - dsi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); +if (ret <0 ) + goto err_cleanup_encoder; + dsi->encoder.possible_crtcs = ret; ret =drm_bridge_attach (&dsi->encoder, &dsi->bridge,NULL ,DRM_BRIDGE_ATTACH_NO_CONNECTOR );
Signature · 1 line
2.39.2
Re: [PATCH v4 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation
Il 05/09/23 10:49, Michael Walle ha scritto:
Quoted 9 lines
mtk_drm_find_possible_crtc_by_comp()assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment inmtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 0 and the third path will be 1.To fix that, dynamically calculate the IDs by the presence of the paths.
Quoted 8 lines
While at it, make the return code a signed one and return
-ENOENTif no path is found and handle the error in the callers.Fixes 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way")Suggested-by Nícolas F. R. A. Prado <[email protected]>Signed-off-by Michael Walle <[email protected]>Reviewed-by Nícolas F. R. A. Prado <[email protected]>
Perfect!
Quoted 160 lines
---
v4:
- return-ENOENTifmtk_drm_find_possible_crtc_by_comp()doesn't find any path
v3:
- use data instead ofpriv_n->data
- fixed typos
- collected Rb and Tb tags
v2:
- iterate over all_drm_private[] to get any vdosys
- new check if a path is available--- drivers/gpu/drm/mediatek/mtk_dpi.c | 5 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 75 ++++++++++++++++----- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 +- drivers/gpu/drm/mediatek/mtk_dsi.c | 5 +- 4 files changed, 68 insertions(+), 20 deletions(-)drivers/gpu/drm/mediatek/mtk_dpi.c +4
-1@@ -796,7 +796,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)return ret; } - dpi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); +if (ret <0 ) + goto err_cleanup; + dpi->encoder.possible_crtcs = ret; ret =drm_bridge_attach (&dpi->encoder, &dpi->bridge,NULL ,DRM_BRIDGE_ATTACH_NO_CONNECTOR );drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +59
-16@@ -507,6 +507,27 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev,return false; } +static bool mtk_ddp_path_available (const unsigned int *path, +unsigned int path_len, +struct device_node **comp_node) +{ +unsigned int i; + +if (!path) +return false; + +for (i =0U ; i < path_len; i++) { +/* OVL_ADAPTOR doesn't have a device node */ +if (path[i] ==DDP_COMPONENT_DRM_OVL_ADAPTOR ) +continue ; + +if (!comp_node[path[i]]) +return false; + } + +return true; +} +int mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type) {@@ -522,25 +543,47 @@ int mtk_ddp_comp_get_id(struct device_node *node,return -EINVAL ; } -unsigned int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm, -struct device *dev) +int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm,struct device *dev) {struct mtk_drm_private *private = drm->dev_private; -unsigned int ret =0 ; - -if (mtk_drm_find_comp_in_ddp (dev, private->data->main_path, private->data->main_len, - private->ddp_comp)) - ret =BIT (0 ); -else if (mtk_drm_find_comp_in_ddp (dev, private->data->ext_path, - private->data->ext_len, private->ddp_comp)) - ret =BIT (1 ); -else if (mtk_drm_find_comp_in_ddp (dev, private->data->third_path, - private->data->third_len, private->ddp_comp)) - ret =BIT (2 ); -else -DRM_INFO ("Failed to find comp in ddp table\n" ); +const struct mtk_mmsys_driver_data *data; +struct mtk_drm_private *priv_n; +int i =0 , j; + +for (j =0 ; j < private->data->mmsys_dev_num; j++) { + priv_n = private->all_drm_private[j]; + data = priv_n->data; + +if (mtk_ddp_path_available (data->main_path, data->main_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->main_path, + data->main_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + +if (mtk_ddp_path_available (data->ext_path, data->ext_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->ext_path, + data->ext_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + +if (mtk_ddp_path_available (data->third_path, data->third_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->third_path, + data->third_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + } -return ret; +DRM_INFO ("Failed to find comp in ddp table\n" ); +return -ENOENT ; } int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +1
-2@@ -277,8 +277,7 @@ static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct devint mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type); -unsigned int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm, -struct device *dev); +int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm,struct device *dev);int mtk_ddp_comp_init (struct device_node *comp_node,struct mtk_ddp_comp *comp,unsigned int comp_id);enum mtk_ddp_comp_type mtk_ddp_comp_get_type (unsigned int comp_id);drivers/gpu/drm/mediatek/mtk_dsi.c +4
-1@@ -843,7 +843,10 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)return ret; } - dsi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); +if (ret <0 ) + goto err_cleanup_encoder; + dsi->encoder.possible_crtcs = ret; ret =drm_bridge_attach (&dsi->encoder, &dsi->bridge,NULL ,DRM_BRIDGE_ATTACH_NO_CONNECTOR );
Re: [PATCH v4 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation
In reply to Michael WalleHi,
Quoted 9 lines
mtk_drm_find_possible_crtc_by_comp()assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment inmtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 0 and the third path will be 1.To fix that, dynamically calculate the IDs by the presence of the paths.
Quoted 8 lines
While at it, make the return code a signed one and return
-ENOENTif no path is found and handle the error in the callers.Fixes 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way")Suggested-by Nícolas F. R. A. Prado <[email protected]>Signed-off-by Michael Walle <[email protected]>Reviewed-by Nícolas F. R. A. Prado <[email protected]>
Is there anything wrong with these two patches? They are now lingering around for more than two months.
Unfortunately, patch 2/2 won't apply anymore because of commit 01389b324c97 ("drm/mediatek: Add connector dynamic selection capability). And I'm a bit puzzled for what the crtc_id is used there because I guess it will have the same problem this patch fixes.
-michael
Quoted 173 lines
---
v4:
- return-ENOENTifmtk_drm_find_possible_crtc_by_comp()doesn't find any path
v3:
- use data instead ofpriv_n->data
- fixed typos
- collected Rb and Tb tags
v2:
- iterate over all_drm_private[] to get any vdosys
- new check if a path is available--- drivers/gpu/drm/mediatek/mtk_dpi.c | 5 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 75 ++++++++++++++++----- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 +- drivers/gpu/drm/mediatek/mtk_dsi.c | 5 +- 4 files changed, 68 insertions(+), 20 deletions(-)drivers/gpu/drm/mediatek/mtk_dpi.c +4
-1@@ -796,7 +796,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)return ret; } - dpi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); +if (ret <0 ) + goto err_cleanup; + dpi->encoder.possible_crtcs = ret;drivers/gpu/drm/mediatek/mtk_dpi.c +0
-0ret =drm_bridge_attach (&dpi->encoder, &dpi->bridge,NULL ,DRM_BRIDGE_ATTACH_NO_CONNECTOR );drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +21
-0@@ -507,6 +507,27 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev, return false; } +static bool mtk_ddp_path_available (const unsigned int *path, +unsigned int path_len, +struct device_node **comp_node) +{ +unsigned int i; + +if (!path) +return false; + +for (i =0U ; i < path_len; i++) { +/* OVL_ADAPTOR doesn't have a device node */ +if (path[i] ==DDP_COMPONENT_DRM_OVL_ADAPTOR ) +continue ; + +if (!comp_node[path[i]]) +return false; + } + +return true; +} +int mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type){
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +38
-16@@ -522,25 +543,47 @@ int mtk_ddp_comp_get_id(struct device_node *node,return -EINVAL ; } -unsigned int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm, -struct device *dev) +int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm,struct device *dev) {struct mtk_drm_private *private = drm->dev_private; -unsigned int ret =0 ; - -if (mtk_drm_find_comp_in_ddp (dev, private->data->main_path, private->data->main_len, - private->ddp_comp)) - ret =BIT (0 ); -else if (mtk_drm_find_comp_in_ddp (dev, private->data->ext_path, - private->data->ext_len, private->ddp_comp)) - ret =BIT (1 ); -else if (mtk_drm_find_comp_in_ddp (dev, private->data->third_path, - private->data->third_len, private->ddp_comp)) - ret =BIT (2 ); -else -DRM_INFO ("Failed to find comp in ddp table\n" ); + const struct mtk_mmsys_driver_data *data; +struct mtk_drm_private *priv_n; +int i =0 , j; + +for (j =0 ; j < private->data->mmsys_dev_num; j++) { + priv_n = private->all_drm_private[j]; + data = priv_n->data; + +if (mtk_ddp_path_available (data->main_path, data->main_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->main_path, + data->main_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + +if (mtk_ddp_path_available (data->ext_path, data->ext_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->ext_path, + data->ext_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + +if (mtk_ddp_path_available (data->third_path, data->third_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->third_path, + data->third_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + } -return ret; +DRM_INFO ("Failed to find comp in ddp table\n" ); +return -ENOENT ;}
int mtk_ddp_comp_init(struct
device_node*node, structmtk_ddp_comp
*comp,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0
-0@@ -277,8 +277,7 @@ static inline bool mtk_ddp_comp_disconnect(struct
mtk_ddp_comp*comp, struct devint mtk_ddp_comp_get_id(struct
device_node*node,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0
-1enum mtk_ddp_comp_type comp_type); -unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device*drm,
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +1
-1- struct device *dev); +int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm, structdevice *dev);
int mtk_ddp_comp_init(structdevice_node*comp_node, structmtk_ddp_comp*comp,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0
-0unsigned int comp_id);enum mtk_ddp_comp_type mtk_ddp_comp_get_type (unsigned int comp_id);drivers/gpu/drm/mediatek/mtk_dsi.c +4
-1@@ -843,7 +843,10 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)return ret; } - dsi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); +if (ret <0 ) + goto err_cleanup_encoder; + dsi->encoder.possible_crtcs = ret;drivers/gpu/drm/mediatek/mtk_dsi.c +0
-0ret =drm_bridge_attach (&dsi->encoder, &dsi->bridge,NULL ,DRM_BRIDGE_ATTACH_NO_CONNECTOR );
Chun-Kuang Hu
maintainerRe: [PATCH v4 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation
Hi, Michael:
Michael Walle <[email protected]> 於 2023年11月21日 週二 下午10:44寫道:
Quoted 24 lines
Hi,
Quoted 14 lines
mtk_drm_find_possible_crtc_by_comp()assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see
also comment inmtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 0 and the third path will be 1.To fix that, dynamically calculate the IDs by the presence of the paths.
While at it, make the return code a signed one and return
-ENOENTif no path is found and handle the error in the callers.Quoted 6 lines
Fixes 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting
possible_crtcway")Suggested-by Nícolas F. R. A. Prado <[email protected]>Signed-off-by Michael Walle <[email protected]>Reviewed-by Nícolas F. R. A. Prado <[email protected]>
Quoted 8 lines
Is there anything wrong with these two patches? They are now lingering around for more than two months.
Unfortunately, patch 2/2 won't apply anymore because of commit
01389b324c97("drm/mediatek: Add connector dynamic selection capability). And I'm a bit puzzled for what thecrtc_idis used there because I guess it will have the same problem this patch fixes.
Please base on the latest kernel version to fix.
Regards,
Chun-Kuang.
Quoted 180 lines
-michael
Quoted 177 lines
---
v4:
- return-ENOENTifmtk_drm_find_possible_crtc_by_comp()doesn't find any path
v3:
- use data instead ofpriv_n->data
- fixed typos
- collected Rb and Tb tags
v2:
- iterate over all_drm_private[] to get any vdosys
- new check if a path is available--- drivers/gpu/drm/mediatek/mtk_dpi.c | 5 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 75 ++++++++++++++++----- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 +- drivers/gpu/drm/mediatek/mtk_dsi.c | 5 +- 4 files changed, 68 insertions(+), 20 deletions(-)drivers/gpu/drm/mediatek/mtk_dpi.c +4
-1@@ -796,7 +796,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)return ret; } - dpi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm_dev, dpi->dev); +if (ret <0 ) + goto err_cleanup; + dpi->encoder.possible_crtcs = ret;ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +21
-0@@ -507,6 +507,27 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev, return false; } +static bool mtk_ddp_path_available (const unsigned int *path, +unsigned int path_len, +struct device_node **comp_node) +{ +unsigned int i; + +if (!path) +return false; + +for (i =0U ; i < path_len; i++) { +/* OVL_ADAPTOR doesn't have a device node */ +if (path[i] ==DDP_COMPONENT_DRM_OVL_ADAPTOR ) +continue ; + +if (!comp_node[path[i]]) +return false; + } + +return true; +} +int mtk_ddp_comp_get_id (struct device_node *node,enum mtk_ddp_comp_type comp_type){
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +38
-16@@ -522,25 +543,47 @@ int mtk_ddp_comp_get_id(struct device_node *node,return -EINVAL ; } -unsigned int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm, -struct device *dev) +int mtk_drm_find_possible_crtc_by_comp (struct drm_device *drm,struct device *dev) {struct mtk_drm_private *private = drm->dev_private; -unsigned int ret =0 ; - -if (mtk_drm_find_comp_in_ddp (dev, private->data->main_path, private->data->main_len, - private->ddp_comp)) - ret =BIT (0 ); -else if (mtk_drm_find_comp_in_ddp (dev, private->data->ext_path, - private->data->ext_len, private->ddp_comp)) - ret =BIT (1 ); -else if (mtk_drm_find_comp_in_ddp (dev, private->data->third_path, - private->data->third_len, private->ddp_comp)) - ret =BIT (2 ); -else -DRM_INFO ("Failed to find comp in ddp table\n" ); + const struct mtk_mmsys_driver_data *data; +struct mtk_drm_private *priv_n; +int i =0 , j; + +for (j =0 ; j < private->data->mmsys_dev_num; j++) { + priv_n = private->all_drm_private[j]; + data = priv_n->data; + +if (mtk_ddp_path_available (data->main_path, data->main_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->main_path, + data->main_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + +if (mtk_ddp_path_available (data->ext_path, data->ext_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->ext_path, + data->ext_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + +if (mtk_ddp_path_available (data->third_path, data->third_len, + priv_n->comp_node)) { +if (mtk_drm_find_comp_in_ddp (dev, data->third_path, + data->third_len, + priv_n->ddp_comp)) +return BIT (i); + i++; + } + } -return ret; +DRM_INFO ("Failed to find comp in ddp table\n" ); +return -ENOENT ;}
int mtk_ddp_comp_init(struct
device_node*node, structmtk_ddp_comp
*comp,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0
-0@@ -277,8 +277,7 @@ static inline bool mtk_ddp_comp_disconnect(struct
mtk_ddp_comp*comp, struct devint mtk_ddp_comp_get_id(struct
device_node*node,enum mtk_ddp_comp_type comp_type);-unsigned int mtk_drm_find_possible_crtc_by_comp(struct
drm_device*drm,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +1
-1- struct device *dev); +int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm, structdevice *dev);
int mtk_ddp_comp_init(structdevice_node*comp_node, structmtk_ddp_comp*comp,unsigned int comp_id);enum
mtk_ddp_comp_typemtk_ddp_comp_get_type(unsigned int comp_id);drivers/gpu/drm/mediatek/mtk_dsi.c +4
-1@@ -843,7 +843,10 @@ static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)return ret; } - dsi->encoder.possible_crtcs =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); + ret =mtk_drm_find_possible_crtc_by_comp (drm, dsi->host.dev); +if (ret <0 ) + goto err_cleanup_encoder; + dsi->encoder.possible_crtcs = ret;ret = drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
Re: [PATCH v4 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation
Hi,
Quoted 24 lines
Quoted 24 lines
Quoted 14 lines
mtk_drm_find_possible_crtc_by_comp()assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see
also comment inmtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 0 and the third path will be 1.To fix that, dynamically calculate the IDs by the presence of the paths.
While at it, make the return code a signed one and return
-ENOENTif no path is found and handle the error in the callers.Quoted 6 lines
Fixes 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting
possible_crtcway")Suggested-by Nícolas F. R. A. Prado <[email protected]>Signed-off-by Michael Walle <[email protected]>Reviewed-by Nícolas F. R. A. Prado <[email protected]>Is there anything wrong with these two patches? They are now lingering around for more than two months.
Quoted 7 lines
Quoted 5 lines
Unfortunately, patch 2/2 won't apply anymore because of commit
01389b324c97("drm/mediatek: Add connector dynamic selection capability). And I'm a bit puzzled for what thecrtc_idis used there because I guess it will have the same problem this patch fixes.Please base on the latest kernel version to fix.
Of course, but the question is how to fix it. Maybe Jason-JH.Lin can help here.
In any case, please pick patch 1/2, it's independent of the second patch and should still apply.
-michael
Quoted 9 lines · Michael Walle
drm_crtc_from_index(0)might return NULL if there are no CRTCs registered at all which will lead to a kernel oops inmtk_drm_crtc_dma_dev_get(). Add the missing return value check.Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")Signed-off-by Michael Walle <[email protected]>Reviewed-by Nícolas F. R. A. Prado <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
I tried this patch as well, hit the crash during my tests. I also reviewed your changes
Eugen
Quoted 35 lines
---
v4:
- collected tags
v3:
- none
v2:
- collected tags
- fixed typos--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +4
-1@@ -420,6 +420,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)struct mtk_drm_private *private = drm->dev_private;struct mtk_drm_private *priv_n;struct device *dma_dev =NULL ; +struct drm_crtc *crtc;int ret, i, j;if (drm_firmware_drivers_only ())@@ -494,7 +495,9 @@ static int mtk_drm_kms_init(struct drm_device *drm) }/* Use OVL device for all DMA memory allocations */ - dma_dev =mtk_drm_crtc_dma_dev_get (drm_crtc_from_index (drm,0 )); + crtc =drm_crtc_from_index (drm,0 ); +if (crtc) + dma_dev =mtk_drm_crtc_dma_dev_get (crtc);if (!dma_dev) { ret = -ENODEV ;dev_err (drm->dev,"Need at least one OVL device\n" );
Hi, Michael:
Michael Walle <[email protected]> 於 2023年9月5日 週二 下午4:49寫道:
Quoted 4 lines
drm_crtc_from_index(0)might return NULL if there are no CRTCs registered at all which will lead to a kernel oops inmtk_drm_crtc_dma_dev_get(). Add the missing return value check.
Applied to mediatek-drm-fixes [1], thanks.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-fixes
Regards,
Chun-Kuang.
Quoted 44 lines
Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")Signed-off-by Michael Walle <[email protected]>Reviewed-by Nícolas F. R. A. Prado <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>---
v4:
- collected tags
v3:
- none
v2:
- collected tags
- fixed typos--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +4
-2@@ -420,6 +420,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)struct mtk_drm_private *private = drm->dev_private;struct mtk_drm_private *priv_n;struct device *dma_dev =NULL ; +struct drm_crtc *crtc;int ret, i, j;if (drm_firmware_drivers_only ())@@ -494,7 +495,9 @@ static int mtk_drm_kms_init(struct drm_device *drm) }/* Use OVL device for all DMA memory allocations */ - dma_dev =mtk_drm_crtc_dma_dev_get (drm_crtc_from_index (drm,0 )); + crtc =drm_crtc_from_index (drm,0 ); +if (crtc) + dma_dev =mtk_drm_crtc_dma_dev_get (crtc);if (!dma_dev) { ret = -ENODEV ;dev_err (drm->dev,"Need at least one OVL device\n" ); --2.39.2