Skip to contentSkip to conversation

drm/bridge: ti-sn65dsi83: Fix null pointer dereference in remove callback

PATCH In review Jonathan Liu 3 participants 5 messages Jun 17, 2021 – Jun 18, 2021

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

PATCH 1/1 drm/bridge: ti-sn65dsi83: Fix null pointer dereference in remove callback

If attach has not been called, unloading the driver can result in a null pointer dereference in mipi_dsi_detach as ctx->dsi has not been assigned yet.

Fixes ceb515ba29ba6b ("drm/bridge: ti-sn65dsi83: Add TI SN65DSI83 and SN65DSI84 driver")
---
 drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +5 -2
index 750f2172ef08..8e9f45c5c7c1 100644
@@ -671,8 +671,11 @@ static int sn65dsi83_remove(struct i2c_client *client)
 {
 	struct sn65dsi83 *ctx = i2c_get_clientdata(client);
 
-	mipi_dsi_detach(ctx->dsi);
-	mipi_dsi_device_unregister(ctx->dsi);
+	if (ctx->dsi) {
+		mipi_dsi_detach(ctx->dsi);
+		mipi_dsi_device_unregister(ctx->dsi);
+	}
+
 	drm_bridge_remove(&ctx->bridge);
 	of_node_put(ctx->host_node);
 
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Jonathan Liu

If attach has not been called, unloading the driver can result in a null pointer dereference in mipi_dsi_detach as ctx->dsi has not been assigned yet.

Fixes ceb515ba29ba6b ("drm/bridge: ti-sn65dsi83: Add TI SN65DSI83 and SN65DSI84 driver")
---
  drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +0 -0
index 750f2172ef08..8e9f45c5c7c1 100644
@@ -671,8 +671,11 @@ static int sn65dsi83_remove(struct i2c_client *client)
  {
  	struct sn65dsi83 *ctx = i2c_get_clientdata(client);

drivers/gpu/drm/bridge/ti-sn65dsi83.c static int sn65dsi83_remove(struct i2c_client *client) · line 680

Quoted 10 lines
drivers/gpu/drm/bridge/ti-sn65dsi83.c +5 -2
 
-	mipi_dsi_detach(ctx->dsi);
-	mipi_dsi_device_unregister(ctx->dsi);
+	if (ctx->dsi) {
+		mipi_dsi_detach(ctx->dsi);
+		mipi_dsi_device_unregister(ctx->dsi);
+	}
+
  	drm_bridge_remove(&ctx->bridge);
  	of_node_put(ctx->host_node);

Looks OK to me.

Thanks !

#2 lore raw
In reply to Jonathan Liu

Hi Jonathan,

Thank you for the patch.

Quoted 3 lines · Jonathan Liu

If attach has not been called, unloading the driver can result in a null pointer dereference in mipi_dsi_detach as ctx->dsi has not been assigned yet.

Shouldn't this be done in a brige .detach() operation instead ?

Quoted 24 lines
Fixes ceb515ba29ba6b ("drm/bridge: ti-sn65dsi83: Add TI SN65DSI83 and SN65DSI84 driver")
---
 drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +5 -2
index 750f2172ef08..8e9f45c5c7c1 100644
@@ -671,8 +671,11 @@ static int sn65dsi83_remove(struct i2c_client *client)
 {
 	struct sn65dsi83 *ctx = i2c_get_clientdata(client);
 
-	mipi_dsi_detach(ctx->dsi);
-	mipi_dsi_device_unregister(ctx->dsi);
+	if (ctx->dsi) {
+		mipi_dsi_detach(ctx->dsi);
+		mipi_dsi_device_unregister(ctx->dsi);
+	}
+
 	drm_bridge_remove(&ctx->bridge);
 	of_node_put(ctx->host_node);
 
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

Hi Marek,

Quoted 12 lines · Laurent Pinchart

Hi Jonathan,

Thank you for the patch.

Quoted 3 lines · Jonathan Liu

If attach has not been called, unloading the driver can result in a null pointer dereference in mipi_dsi_detach as ctx->dsi has not been assigned yet.

Shouldn't this be done in a brige .detach() operation instead ?

Could you please take a look?
I don't have a working setup to test moving the code to detach.

Quoted 14 lines
Quoted 14 lines
Fixes ceb515ba29ba6b ("drm/bridge: ti-sn65dsi83: Add TI SN65DSI83 and SN65DSI84 driver")
---
 drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +0 -0
index 750f2172ef08..8e9f45c5c7c1 100644
@@ -671,8 +671,11 @@ static int sn65dsi83_remove(struct i2c_client *client)
 {
      struct sn65dsi83 *ctx = i2c_get_clientdata(client);
 
Quoted 10 lines

drivers/gpu/drm/bridge/ti-sn65dsi83.c static int sn65dsi83_remove(struct i2c_client *client) · line 681

Quoted 10 lines
drivers/gpu/drm/bridge/ti-sn65dsi83.c +5 -2
-     mipi_dsi_detach(ctx->dsi);
-     mipi_dsi_device_unregister(ctx->dsi);
+     if (ctx->dsi) {
+             mipi_dsi_detach(ctx->dsi);
+             mipi_dsi_device_unregister(ctx->dsi);
+     }
+
      drm_bridge_remove(&ctx->bridge);
      of_node_put(ctx->host_node);
 

Thanks.

Regards,
Jonathan

#4 lore raw
Quoted 1 line · Jonathan Liu

Hi Marek,

Hi,

Quoted 9 lines
Quoted 9 lines

Hi Jonathan,

Thank you for the patch.

Quoted 3 lines · Jonathan Liu

If attach has not been called, unloading the driver can result in a null pointer dereference in mipi_dsi_detach as ctx->dsi has not been assigned yet.

Quoted 5 lines
Quoted 2 lines

Shouldn't this be done in a brige .detach() operation instead ?

Could you please take a look?
I don't have a working setup to test moving the code to detach.

I just replied to your other email regarding bringing the chip up, so please bring your setup up first, then test this patch again, and then let's revisit this topic.