drm/bridge: panel: Check device dependency before managing device link

Message ID 20231123032615.3760488-1-victor.liu@nxp.com
State New
Headers
Series drm/bridge: panel: Check device dependency before managing device link |

Commit Message

Liu Ying Nov. 23, 2023, 3:26 a.m. UTC
  Some panel devices already depend on DRM device, like the panel in
arch/arm/boot/dts/st/ste-ux500-samsung-skomer.dts, because DRM device is
the ancestor of those panel devices.  device_link_add() would fail by
returning a NULL pointer for those panel devices because of the existing
dependency.  So, check the dependency by calling device_is_dependent()
before adding or deleting device link between panel device and DRM device
so that the link is managed only for independent panel devices.

Fixes: 887878014534 ("drm/bridge: panel: Fix device link for DRM_BRIDGE_ATTACH_NO_CONNECTOR")
Fixes: 199cf07ebd2b ("drm/bridge: panel: Add a device link between drm device and panel device")
Reported-by: Linus Walleij <linus.walleij@linaro.org>
Closes: https://lore.kernel.org/lkml/CACRpkdaGzXD6HbiX7mVUNJAJtMEPG00Pp6+nJ1P0JrfJ-ArMvQ@mail.gmail.com/T/
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Liu Ying <victor.liu@nxp.com>
---
 drivers/gpu/drm/bridge/panel.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
  

Comments

Linus Walleij Nov. 24, 2023, 11:48 p.m. UTC | #1
On Thu, Nov 23, 2023 at 4:22 AM Liu Ying <victor.liu@nxp.com> wrote:

> Some panel devices already depend on DRM device, like the panel in
> arch/arm/boot/dts/st/ste-ux500-samsung-skomer.dts, because DRM device is
> the ancestor of those panel devices.  device_link_add() would fail by
> returning a NULL pointer for those panel devices because of the existing
> dependency.  So, check the dependency by calling device_is_dependent()
> before adding or deleting device link between panel device and DRM device
> so that the link is managed only for independent panel devices.
>
> Fixes: 887878014534 ("drm/bridge: panel: Fix device link for DRM_BRIDGE_ATTACH_NO_CONNECTOR")
> Fixes: 199cf07ebd2b ("drm/bridge: panel: Add a device link between drm device and panel device")
> Reported-by: Linus Walleij <linus.walleij@linaro.org>
> Closes: https://lore.kernel.org/lkml/CACRpkdaGzXD6HbiX7mVUNJAJtMEPG00Pp6+nJ1P0JrfJ-ArMvQ@mail.gmail.com/T/
> Tested-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Liu Ying <victor.liu@nxp.com>

Patch applied to drm-misc-fixes.

Yours,
Linus Walleij
  
Ville Syrjälä Nov. 27, 2023, 1:35 p.m. UTC | #2
On Thu, Nov 23, 2023 at 11:26:15AM +0800, Liu Ying wrote:
> Some panel devices already depend on DRM device, like the panel in
> arch/arm/boot/dts/st/ste-ux500-samsung-skomer.dts, because DRM device is
> the ancestor of those panel devices.  device_link_add() would fail by
> returning a NULL pointer for those panel devices because of the existing
> dependency.  So, check the dependency by calling device_is_dependent()
> before adding or deleting device link between panel device and DRM device
> so that the link is managed only for independent panel devices.
> 
> Fixes: 887878014534 ("drm/bridge: panel: Fix device link for DRM_BRIDGE_ATTACH_NO_CONNECTOR")
> Fixes: 199cf07ebd2b ("drm/bridge: panel: Add a device link between drm device and panel device")
> Reported-by: Linus Walleij <linus.walleij@linaro.org>
> Closes: https://lore.kernel.org/lkml/CACRpkdaGzXD6HbiX7mVUNJAJtMEPG00Pp6+nJ1P0JrfJ-ArMvQ@mail.gmail.com/T/
> Tested-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Liu Ying <victor.liu@nxp.com>
> ---
>  drivers/gpu/drm/bridge/panel.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c
> index e48823a4f1ed..5e8980023407 100644
> --- a/drivers/gpu/drm/bridge/panel.c
> +++ b/drivers/gpu/drm/bridge/panel.c
> @@ -23,6 +23,7 @@ struct panel_bridge {
>  	struct drm_panel *panel;
>  	struct device_link *link;
>  	u32 connector_type;
> +	bool is_independent;
>  };
>  
>  static inline struct panel_bridge *
> @@ -67,12 +68,17 @@ static int panel_bridge_attach(struct drm_bridge *bridge,
>  	struct drm_device *drm_dev = bridge->dev;
>  	int ret;
>  
> -	panel_bridge->link = device_link_add(drm_dev->dev, panel->dev,
> -					     DL_FLAG_STATELESS);
> -	if (!panel_bridge->link) {
> -		DRM_ERROR("Failed to add device link between %s and %s\n",
> -			  dev_name(drm_dev->dev), dev_name(panel->dev));
> -		return -EINVAL;
> +	panel_bridge->is_independent = !device_is_dependent(drm_dev->dev,
> +							    panel->dev);

This broke the build. Looks like device_is_dependent() is not even exported.
ERROR: modpost: "device_is_dependent" [drivers/gpu/drm/drm_kms_helper.ko] undefined!

The recommended defconfigs in rerere-cache do seem to have CONFIG_DRM_KMS_HELPER=m
so this should have been caught before pushing. How did it slip through?

> +
> +	if (panel_bridge->is_independent) {
> +		panel_bridge->link = device_link_add(drm_dev->dev, panel->dev,
> +						     DL_FLAG_STATELESS);
> +		if (!panel_bridge->link) {
> +			DRM_ERROR("Failed to add device link between %s and %s\n",
> +				  dev_name(drm_dev->dev), dev_name(panel->dev));
> +			return -EINVAL;
> +		}
>  	}
>  
>  	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
> @@ -80,7 +86,8 @@ static int panel_bridge_attach(struct drm_bridge *bridge,
>  
>  	if (!bridge->encoder) {
>  		DRM_ERROR("Missing encoder\n");
> -		device_link_del(panel_bridge->link);
> +		if (panel_bridge->is_independent)
> +			device_link_del(panel_bridge->link);
>  		return -ENODEV;
>  	}
>  
> @@ -92,7 +99,8 @@ static int panel_bridge_attach(struct drm_bridge *bridge,
>  				 panel_bridge->connector_type);
>  	if (ret) {
>  		DRM_ERROR("Failed to initialize connector\n");
> -		device_link_del(panel_bridge->link);
> +		if (panel_bridge->is_independent)
> +			device_link_del(panel_bridge->link);
>  		return ret;
>  	}
>  
> @@ -115,7 +123,8 @@ static void panel_bridge_detach(struct drm_bridge *bridge)
>  	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
>  	struct drm_connector *connector = &panel_bridge->connector;
>  
> -	device_link_del(panel_bridge->link);
> +	if (panel_bridge->is_independent)
> +		device_link_del(panel_bridge->link);
>  
>  	/*
>  	 * Cleanup the connector if we know it was initialized.
> -- 
> 2.37.1
  
Linus Walleij Nov. 27, 2023, 4:08 p.m. UTC | #3
On Mon, Nov 27, 2023 at 2:36 PM Ville Syrjälä
<ville.syrjala@linux.intel.com> wrote:

> > +     panel_bridge->is_independent = !device_is_dependent(drm_dev->dev,
> > +                                                         panel->dev);
>
> This broke the build. Looks like device_is_dependent() is not even exported.
> ERROR: modpost: "device_is_dependent" [drivers/gpu/drm/drm_kms_helper.ko] undefined!

Yep Ying made a fix, I just applied and pushed it because it was obviously
correct.

> The recommended defconfigs in rerere-cache do seem to have CONFIG_DRM_KMS_HELPER=m
> so this should have been caught before pushing. How did it slip through?

My neglect.

Neglect may have something to do with my desktop being 10 years+
old. Building random defconfigs on this machine takes so long time
that invariably other stuff has been pushed to the branch before
the compiles even complete.

Yeah I know. I should buy a better computer.

Yours,
Linus Walleij
  

Patch

diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c
index e48823a4f1ed..5e8980023407 100644
--- a/drivers/gpu/drm/bridge/panel.c
+++ b/drivers/gpu/drm/bridge/panel.c
@@ -23,6 +23,7 @@  struct panel_bridge {
 	struct drm_panel *panel;
 	struct device_link *link;
 	u32 connector_type;
+	bool is_independent;
 };
 
 static inline struct panel_bridge *
@@ -67,12 +68,17 @@  static int panel_bridge_attach(struct drm_bridge *bridge,
 	struct drm_device *drm_dev = bridge->dev;
 	int ret;
 
-	panel_bridge->link = device_link_add(drm_dev->dev, panel->dev,
-					     DL_FLAG_STATELESS);
-	if (!panel_bridge->link) {
-		DRM_ERROR("Failed to add device link between %s and %s\n",
-			  dev_name(drm_dev->dev), dev_name(panel->dev));
-		return -EINVAL;
+	panel_bridge->is_independent = !device_is_dependent(drm_dev->dev,
+							    panel->dev);
+
+	if (panel_bridge->is_independent) {
+		panel_bridge->link = device_link_add(drm_dev->dev, panel->dev,
+						     DL_FLAG_STATELESS);
+		if (!panel_bridge->link) {
+			DRM_ERROR("Failed to add device link between %s and %s\n",
+				  dev_name(drm_dev->dev), dev_name(panel->dev));
+			return -EINVAL;
+		}
 	}
 
 	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
@@ -80,7 +86,8 @@  static int panel_bridge_attach(struct drm_bridge *bridge,
 
 	if (!bridge->encoder) {
 		DRM_ERROR("Missing encoder\n");
-		device_link_del(panel_bridge->link);
+		if (panel_bridge->is_independent)
+			device_link_del(panel_bridge->link);
 		return -ENODEV;
 	}
 
@@ -92,7 +99,8 @@  static int panel_bridge_attach(struct drm_bridge *bridge,
 				 panel_bridge->connector_type);
 	if (ret) {
 		DRM_ERROR("Failed to initialize connector\n");
-		device_link_del(panel_bridge->link);
+		if (panel_bridge->is_independent)
+			device_link_del(panel_bridge->link);
 		return ret;
 	}
 
@@ -115,7 +123,8 @@  static void panel_bridge_detach(struct drm_bridge *bridge)
 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
 	struct drm_connector *connector = &panel_bridge->connector;
 
-	device_link_del(panel_bridge->link);
+	if (panel_bridge->is_independent)
+		device_link_del(panel_bridge->link);
 
 	/*
 	 * Cleanup the connector if we know it was initialized.