Skip to contentSkip to conversation

Fix the shutdown callback of a drm component device

PATCH Applied Heiko Stuebner 3 participants 8 messages Feb 20, 2025 – Feb 27, 2025

Subsystems (6)
lore
Share & tools
lore

Heiko Stuebner

author maintainer
#0 lore raw

cover Fix the shutdown callback of a drm component device

Probe deferral can cause the platform-data we access to be freed already causing ugly splats on system shutdown.

Fix this via a small component-helper and adapting the rockchip-drm shutdown handler.

Heiko Stuebner (2):
drivers: base: component: add function to query the bound status drm/rockchip: Fix shutdown when no drm-device is set up

 drivers/base/component.c                    | 14 ++++++++++++++
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c |  6 ++++--
 include/linux/component.h                   |  4 +++-
 3 files changed, 21 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.2
author maintainer
#1 lore raw

PATCH 1/2 drivers: base: component: add function to query the bound status

The component helpers already expose the bound status in debugfs, but at times it might be necessary to also check that state in the kernel and act differently depending on the result.

For example the shutdown handler of a drm-driver might need to stop a whole output pipeline if the drm device is up and running, but may run into problems if that drm-device has never been set up before, for example because the binding deferred.

So add a little helper that returns the bound status for a componet device.

---
 drivers/base/component.c  | 14 ++++++++++++++
 include/linux/component.h |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/base/component.c +14 -0
index 741497324d78..d63e01f4851d 100644
@@ -569,6 +569,20 @@ void component_master_del(struct device *parent,
 }
 EXPORT_SYMBOL_GPL(component_master_del);
 
+bool component_master_is_bound(struct device *parent,
+	const struct component_master_ops *ops)
+{
+	struct aggregate_device *adev;
+
+	guard(mutex)(&component_mutex);
+	adev = __aggregate_find(parent, ops);
+	if (!adev)
+		return 0;
+
+	return adev->bound;
+}
+EXPORT_SYMBOL_GPL(component_master_is_bound);
+
 static void component_unbind(struct component *component,
 	struct aggregate_device *adev, void *data)
 {
include/linux/component.h +3 -1
index df4aa75c9e7c..9d6c66401280 100644
@@ -3,7 +3,7 @@
 #define COMPONENT_H
 
 #include <linux/stddef.h>
-
+#include <linux/types.h>
 
 struct device;
 
@@ -90,6 +90,8 @@ int component_compare_dev_name(struct device *dev, void *data);
 
 void component_master_del(struct device *,
 	const struct component_master_ops *);
+bool component_master_is_bound(struct device *parent,
+	const struct component_master_ops *ops);
 
 struct component_match;
 
Signature · 1 line
2.47.2
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] drivers: base: component: add function to query the bound status

Quoted 9 lines · Heiko Stuebner

The component helpers already expose the bound status in debugfs, but at times it might be necessary to also check that state in the kernel and act differently depending on the result.

For example the shutdown handler of a drm-driver might need to stop a whole output pipeline if the drm device is up and running, but may run into problems if that drm-device has never been set up before, for example because the binding deferred.

Quoted 8 lines

So add a little helper that returns the bound status for a componet device.

---
 drivers/base/component.c  | 14 ++++++++++++++
 include/linux/component.h |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)
author maintainer
#3 lore raw

Re: [PATCH 1/2] drivers: base: component: add function to query the bound status

Hi Greg,

Am Freitag, 21. Februar 2025, 07:14:07 MEZ schrieb Greg KH:

Quoted 13 lines · Heiko Stuebner
Quoted 12 lines

The component helpers already expose the bound status in debugfs, but at times it might be necessary to also check that state in the kernel and act differently depending on the result.

For example the shutdown handler of a drm-driver might need to stop a whole output pipeline if the drm device is up and running, but may run into problems if that drm-device has never been set up before, for example because the binding deferred.

So add a little helper that returns the bound status for a componet device.

Quoted 7 lines
Quoted 5 lines
---
 drivers/base/component.c  | 14 ++++++++++++++
 include/linux/component.h |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)

just for safety and not stepping on people's toes, does the Acked-by mean that this patch can go together with its user through the drm-misc tree?

Thanks a lot
Heiko

maintainer
#4 lore raw

Re: [PATCH 1/2] drivers: base: component: add function to query the bound status

Quoted 22 lines · Heiko Stübner

Hi Greg,

Am Freitag, 21. Februar 2025, 07:14:07 MEZ schrieb Greg KH:

Quoted 19 lines · Heiko Stuebner
Quoted 17 lines

The component helpers already expose the bound status in debugfs, but at times it might be necessary to also check that state in the kernel and act differently depending on the result.

For example the shutdown handler of a drm-driver might need to stop a whole output pipeline if the drm device is up and running, but may run into problems if that drm-device has never been set up before, for example because the binding deferred.

So add a little helper that returns the bound status for a componet device.

---
 drivers/base/component.c  | 14 ++++++++++++++
 include/linux/component.h |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)
Quoted 4 lines
Quoted 1 line

just for safety and not stepping on people's toes, does the Acked-by mean that this patch can go together with its user through the drm-misc tree?

Yup, merge away!

author maintainer
#5 lore raw

PATCH 2/2 drm/rockchip: Fix shutdown when no drm-device is set up

In reply to Heiko Stuebner

When the drm-driver probes, it mainly creates the component device, where all the sub-drivers (vops, hdmi, etc) hook into.

This will cause the shutdown handler to get called on shutdown, even though the drm-device might not have been set up, or the component bind might have failed.

So use the new component helper to check whether the drm-device is up and only then call the drm-atomic helper to release all the drm magic.

This prevents failures when the drm-device is never set, or has been freed up already for example by a probe-defer during the component bind.

---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_drv.c +4 -2
index 439edc165ff6..285b721ff28a 100644
@@ -484,9 +484,11 @@ static void rockchip_drm_platform_remove(struct platform_device *pdev)
 
 static void rockchip_drm_platform_shutdown(struct platform_device *pdev)
 {
-	struct drm_device *drm = platform_get_drvdata(pdev);
+	if (component_master_is_bound(&pdev->dev, &rockchip_drm_ops)) {
+		struct drm_device *drm = platform_get_drvdata(pdev);
 
-	drm_atomic_helper_shutdown(drm);
+		drm_atomic_helper_shutdown(drm);
+	}
 }
 
 static const struct of_device_id rockchip_drm_dt_ids[] = {
Signature · 1 line
2.47.2
Reviewed-by Tested-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] drm/rockchip: Fix shutdown when no drm-device is set up

Quoted 10 lines · On Friday, 21 February 2025 00:41:41 Central European Standard Time Heiko…

When the drm-driver probes, it mainly creates the component device, where all the sub-drivers (vops, hdmi, etc) hook into.

This will cause the shutdown handler to get called on shutdown, even though the drm-device might not have been set up, or the component bind might have failed.

So use the new component helper to check whether the drm-device is up and only then call the drm-atomic helper to release all the drm magic.

Quoted 7 lines

This prevents failures when the drm-device is never set, or has been freed up already for example by a probe-defer during the component bind.

---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Tested on a RK3588 ROCK5B by adding a return -EPROBE_DEFER into the middle of rockchip_drm_bind after component_bind_all already ran. Without the patch, I get a stacktrace in drm_atomic_helper_shutdown. With the patch, I don't get one.

author maintainer Applied
#7 lore raw
In reply to Heiko Stuebner
Quoted 11 lines · Heiko Stuebner

Probe deferral can cause the platform-data we access to be freed already causing ugly splats on system shutdown.

Fix this via a small component-helper and adapting the rockchip-drm shutdown handler.

Heiko Stuebner (2):
drivers: base: component: add function to query the bound status drm/rockchip: Fix shutdown when no drm-device is set up

[...]

Applied, thanks!

[1/2] drivers: base: component: add function to query the bound status

      commit: a6ba2dad0aa4f623ab0def8b6e6888ac00639055
[2/2] drm/rockchip: Fix shutdown when no drm-device is set up
      commit: 4444e4d789d64f053435713e5984f0ef31a7633b

Best regards,

Signature · 1 line
Heiko Stuebner <[email protected]>