Skip to contentSkip to conversation

drm/bridge/synopsys: dsi: Don't blindly call post_disable

PATCH In review Matt Redfearn 3 participants 6 messages Apr 24, 2019 – Apr 25, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge/synopsys: dsi: Don't blindly call post_disable

The DRM documentation states that post_disable is an optional callback. As such an implementing device may not populate it. To avoid panicing the kernel by calling a NULL function pointer, we should NULL check it before blindy calling it.

---

 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +2 -1
index 38e88071363..0ee440216b8 100644
@@ -805,7 +805,8 @@ static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge)
 	 * This needs to be fixed in the drm_bridge framework and the API
 	 * needs to be updated to manage our own call chains...
 	 */
-	dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
+	if (dsi->panel_bridge->funcs->post_disable)
+		dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
 
 	if (dsi->slave) {
 		dw_mipi_dsi_disable(dsi->slave);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Matt,

Thank you for the patch.

Quoted 6 lines · Matt Redfearn

The DRM documentation states that post_disable is an optional callback. As such an implementing device may not populate it. To avoid panicing the kernel by calling a NULL function pointer, we should NULL check it before blindy calling it.

Quoted 19 lines

---

 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +2 -1
index 38e88071363..0ee440216b8 100644
@@ -805,7 +805,8 @@ static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge)
 	 * This needs to be fixed in the drm_bridge framework and the API
 	 * needs to be updated to manage our own call chains...
 	 */
-	dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
+	if (dsi->panel_bridge->funcs->post_disable)
+		dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
 
 	if (dsi->slave) {
 		dw_mipi_dsi_disable(dsi->slave);
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw
In reply to Matt Redfearn
Quoted 17 lines · Matt Redfearn

The DRM documentation states that post_disable is an optional callback. As such an implementing device may not populate it. To avoid panicing the kernel by calling a NULL function pointer, we should NULL check it before blindy calling it.

---

 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +0 -0
index 38e88071363..0ee440216b8 100644

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge) · line 810

Quoted 7 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +2 -1
@@ -805,7 +805,8 @@ static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge)
 	 * This needs to be fixed in the drm_bridge framework and the API
 	 * needs to be updated to manage our own call chains...
 	 */
-	dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
+	if (dsi->panel_bridge->funcs->post_disable)
+		dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
 

Why not drm_bridge_post_disable ?

Regards

Andrzej

Quoted 2 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +0 -0
 	if (dsi->slave) {
 		dw_mipi_dsi_disable(dsi->slave);
#3 lore raw

Hi Andrzej,

Quoted 13 lines · Andrzej Hajda
Quoted 12 lines · Matt Redfearn

The DRM documentation states that post_disable is an optional callback. As such an implementing device may not populate it. To avoid panicing the kernel by calling a NULL function pointer, we should NULL check it before blindy calling it.

---

  drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge) · line 810

Quoted 12 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +2 -1
index 38e88071363..0ee440216b8 100644
@@ -805,7 +805,8 @@ static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge)
  	 * This needs to be fixed in the drm_bridge framework and the API
  	 * needs to be updated to manage our own call chains...
  	 */
-	dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
+	if (dsi->panel_bridge->funcs->post_disable)
+		dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
 

Why not drm_bridge_post_disable ?

Ah - that seems like a nicer fix! Do you think the comment above describing why this function pointer is called directly can be removed as well if we go this route?

If someone calls drm_bridge_post_disable() on the Synposys DSI drm_bridge it will go on to call post_disable on all other bridges in the chain, in addition to us calling them here. Is it an issue to call it multiple times?

Thanks,
Matt

Quoted 11 lines

Regards

Andrzej

Quoted 2 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +0 -0
  	if (dsi->slave) {
  		dw_mipi_dsi_disable(dsi->slave);
#4 lore raw

Hi Matt,

Quoted 29 lines · Matt Redfearn
Quoted 13 lines · Andrzej Hajda
Quoted 12 lines · Matt Redfearn

The DRM documentation states that post_disable is an optional callback. As such an implementing device may not populate it. To avoid panicing the kernel by calling a NULL function pointer, we should NULL check it before blindy calling it.

---

  drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge) · line 810

Quoted 12 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +2 -1
index 38e88071363..0ee440216b8 100644
@@ -805,7 +805,8 @@ static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge)
  	 * This needs to be fixed in the drm_bridge framework and the API
  	 * needs to be updated to manage our own call chains...
  	 */
-	dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
+	if (dsi->panel_bridge->funcs->post_disable)
+		dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
 

Why not drm_bridge_post_disable ?

Quoted 3 lines

Ah - that seems like a nicer fix! Do you think the comment above describing why this function pointer is called directly can be removed as well if we go this route?

It shouldn't be necessary to call ->post_disable manually here as the bridge core handles it internally. This is a hack to work around a problem, and should be fixed properly.

Quoted 4 lines

If someone calls drm_bridge_post_disable() on the Synposys DSI drm_bridge it will go on to call post_disable on all other bridges in the chain, in addition to us calling them here. Is it an issue to call it multiple times?

It depends on the panel implementation, but in general it's not a good idea. It may happen to work, but could break at any time in the future.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +0 -0
  	if (dsi->slave) {
  		dw_mipi_dsi_disable(dsi->slave);
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw
Quoted 38 lines · Laurent Pinchart
Quoted 29 lines · Matt Redfearn
Quoted 13 lines · Andrzej Hajda
Quoted 12 lines · Matt Redfearn

The DRM documentation states that post_disable is an optional callback. As such an implementing device may not populate it. To avoid panicing the kernel by calling a NULL function pointer, we should NULL check it before blindy calling it.

---

  drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge) · line 810

Quoted 12 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +2 -1
index 38e88071363..0ee440216b8 100644
@@ -805,7 +805,8 @@ static void dw_mipi_dsi_bridge_post_disable(struct drm_bridge *bridge)
  	 * This needs to be fixed in the drm_bridge framework and the API
  	 * needs to be updated to manage our own call chains...
  	 */
-	dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
+	if (dsi->panel_bridge->funcs->post_disable)
+		dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge);
 

Why not drm_bridge_post_disable ?

Quoted 3 lines

Ah - that seems like a nicer fix! Do you think the comment above describing why this function pointer is called directly can be removed as well if we go this route?

It shouldn't be necessary to call ->post_disable manually here as the bridge core handles it internally. This is a hack to work around a problem, and should be fixed properly.

Quoted 7 lines
Quoted 4 lines

If someone calls drm_bridge_post_disable() on the Synposys DSI drm_bridge it will go on to call post_disable on all other bridges in the chain, in addition to us calling them here. Is it an issue to call it multiple times?

It depends on the panel implementation, but in general it's not a good idea. It may happen to work, but could break at any time in the future.

Double-checking the driver, the .attach() operation doesn't propagate to the next bridge, so the bridge core will not know about it, and will not propagate .post_disable() either. I think this should be fixed in a way that uses the drm bridge core infrastructure.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +0 -0
  	if (dsi->slave) {
  		dw_mipi_dsi_disable(dsi->slave);
Signature · 3 lines
Regards,

Laurent Pinchart