* [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found
@ 2023-09-01 17:45 Michael Walle
2023-09-01 17:45 ` [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation Michael Walle
2023-09-05 7:50 ` [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found AngeloGioacchino Del Regno
0 siblings, 2 replies; 6+ messages in thread
From: Michael Walle @ 2023-09-01 17:45 UTC (permalink / raw)
To: Nícolas F . R . A . Prado, Chun-Kuang Hu, Philipp Zabel,
David Airlie, Daniel Vetter, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: Nancy . Lin, Frank Wunderlich, Jitao Shi, Stu Hsieh, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, 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 in
mtk_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 <mwalle@kernel.org>
Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
v3:
- none
v2:
- collected tags
- fixed typos
---
drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 93552d76b6e7..2c582498817e 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -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
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation 2023-09-01 17:45 [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found Michael Walle @ 2023-09-01 17:45 ` Michael Walle 2023-09-05 7:55 ` AngeloGioacchino Del Regno 2023-09-05 7:50 ` [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found AngeloGioacchino Del Regno 1 sibling, 1 reply; 6+ messages in thread From: Michael Walle @ 2023-09-01 17:45 UTC (permalink / raw) To: Nícolas F . R . A . Prado, Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger, AngeloGioacchino Del Regno Cc: Nancy . Lin, Frank Wunderlich, Jitao Shi, Stu Hsieh, dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel, Michael Walle 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. Fixes: 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way") Suggested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Signed-off-by: Michael Walle <mwalle@kernel.org> Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> --- 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_drm_ddp_comp.c | 72 +++++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c index 771f4e173353..c00f4669cc50 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -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) { @@ -526,21 +547,44 @@ unsigned 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 0; } int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp, -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation 2023-09-01 17:45 ` [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation Michael Walle @ 2023-09-05 7:55 ` AngeloGioacchino Del Regno 2023-09-05 7:58 ` Michael Walle 0 siblings, 1 reply; 6+ messages in thread From: AngeloGioacchino Del Regno @ 2023-09-05 7:55 UTC (permalink / raw) To: Michael Walle, Nícolas F . R . A . Prado, Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger Cc: Nancy . Lin, Frank Wunderlich, Jitao Shi, Stu Hsieh, dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel Il 01/09/23 19:45, Michael Walle ha scritto: > 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. > > Fixes: 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way") > Suggested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > Signed-off-by: Michael Walle <mwalle@kernel.org> > Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > --- > 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_drm_ddp_comp.c | 72 +++++++++++++++++---- > 1 file changed, 58 insertions(+), 14 deletions(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c > index 771f4e173353..c00f4669cc50 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c > @@ -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) > { > @@ -526,21 +547,44 @@ unsigned 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 0; At this point, I think that it would be sane to change this function to return a signed type, so that we can return -ENOENT if we couldn't find any DDP path (so, if we couldn't find any possible crtc). This function is called only twice, once in DPI, once in DSI - so the change should also be pretty straightforward to do. Cheers, Angelo > } > > int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp, _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation 2023-09-05 7:55 ` AngeloGioacchino Del Regno @ 2023-09-05 7:58 ` Michael Walle 2023-09-05 8:03 ` AngeloGioacchino Del Regno 0 siblings, 1 reply; 6+ messages in thread From: Michael Walle @ 2023-09-05 7:58 UTC (permalink / raw) To: AngeloGioacchino Del Regno Cc: Nícolas F . R . A . Prado, Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger, Nancy . Lin, Frank Wunderlich, Jitao Shi, Stu Hsieh, dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel > At this point, I think that it would be sane to change this function to > return a signed type, so that we can return -ENOENT if we couldn't find > any DDP path (so, if we couldn't find any possible crtc). Fair enough, but should it be part of the fixes commit or a different one? -michael _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation 2023-09-05 7:58 ` Michael Walle @ 2023-09-05 8:03 ` AngeloGioacchino Del Regno 0 siblings, 0 replies; 6+ messages in thread From: AngeloGioacchino Del Regno @ 2023-09-05 8:03 UTC (permalink / raw) To: Michael Walle Cc: Nícolas F . R . A . Prado, Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger, Nancy . Lin, Frank Wunderlich, Jitao Shi, Stu Hsieh, dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel Il 05/09/23 09:58, Michael Walle ha scritto: >> At this point, I think that it would be sane to change this function to >> return a signed type, so that we can return -ENOENT if we couldn't find >> any DDP path (so, if we couldn't find any possible crtc). > > Fair enough, but should it be part of the fixes commit or a different one? > > -michael I would say that this should be part of the Fixes commit: after all, you're fixing a case in which the possible_crtcs calculation *may fail*, so the error handling for this possible failure is, indeed, one part of the fix :-) Angelo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found 2023-09-01 17:45 [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found Michael Walle 2023-09-01 17:45 ` [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation Michael Walle @ 2023-09-05 7:50 ` AngeloGioacchino Del Regno 1 sibling, 0 replies; 6+ messages in thread From: AngeloGioacchino Del Regno @ 2023-09-05 7:50 UTC (permalink / raw) To: Michael Walle, Nícolas F . R . A . Prado, Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger Cc: Nancy . Lin, Frank Wunderlich, Jitao Shi, Stu Hsieh, dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel Il 01/09/23 19:45, Michael Walle ha scritto: > 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. > > Fixes: 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195") > Signed-off-by: Michael Walle <mwalle@kernel.org> > Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-09-05 8:03 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-01 17:45 [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found Michael Walle 2023-09-01 17:45 ` [PATCH v3 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation Michael Walle 2023-09-05 7:55 ` AngeloGioacchino Del Regno 2023-09-05 7:58 ` Michael Walle 2023-09-05 8:03 ` AngeloGioacchino Del Regno 2023-09-05 7:50 ` [PATCH v3 1/2] drm/mediatek: fix kernel oops if no crtc is found AngeloGioacchino Del Regno
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).