All of lore.kernel.org
 help / color / mirror / Atom feed
From: Osama Abdelkader <osama.abdelkader@gmail.com>
To: Anitha Chrisanthus <anitha.chrisanthus@intel.com>,
	Edmund Dea <edmund.j.dea@intel.com>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] drm/kmb: reset DSI host singleton state on teardown
Date: Wed, 6 May 2026 15:18:18 +0200	[thread overview]
Message-ID: <afs_moGTJaQfqmUt@osama> (raw)
In-Reply-To: <20260420150658.165734-1-osama.abdelkader@gmail.com>

On Mon, Apr 20, 2026 at 05:06:57PM +0200, Osama Abdelkader wrote:
> Tear down and clear the global DSI host/device/bridge singleton state
> when unregistering the host so probe retries and remove/reprobe cycles
> start from a clean state.
> 
> Guard the clock-disable path in kmb_dsi_host_unregister() to avoid
> dereferencing error pointers from early probe failure paths.
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
>  drivers/gpu/drm/kmb/kmb_dsi.c | 44 ++++++++++++++++++++++++++++++-----
>  1 file changed, 38 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/kmb/kmb_dsi.c b/drivers/gpu/drm/kmb/kmb_dsi.c
> index aeb2f9f98f23..500dc00ba6ae 100644
> --- a/drivers/gpu/drm/kmb/kmb_dsi.c
> +++ b/drivers/gpu/drm/kmb/kmb_dsi.c
> @@ -5,6 +5,7 @@
>  
>  #include <linux/clk.h>
>  #include <linux/delay.h>
> +#include <linux/err.h>
>  #include <linux/of.h>
>  #include <linux/of_graph.h>
>  #include <linux/mfd/syscon.h>
> @@ -182,8 +183,18 @@ static void kmb_dsi_clk_disable(struct kmb_dsi *kmb_dsi)
>  
>  void kmb_dsi_host_unregister(struct kmb_dsi *kmb_dsi)
>  {
> -	kmb_dsi_clk_disable(kmb_dsi);
> -	mipi_dsi_host_unregister(kmb_dsi->host);
> +	if (!IS_ERR_OR_NULL(kmb_dsi))
> +		kmb_dsi_clk_disable(kmb_dsi);
> +
> +	if (dsi_host) {
> +		mipi_dsi_host_unregister(dsi_host);
> +		kfree(dsi_host);
> +		dsi_host = NULL;
> +	}
> +
> +	kfree(dsi_device);
> +	dsi_device = NULL;
> +	adv_bridge = NULL;
>  }
>  
>  /*
> @@ -217,6 +228,8 @@ static const struct mipi_dsi_host_ops kmb_dsi_host_ops = {
>  int kmb_dsi_host_bridge_init(struct device *dev)
>  {
>  	struct device_node *encoder_node, *dsi_out;
> +	bool host_registered = false;
> +	int ret;
>  
>  	/* Create and register MIPI DSI host */
>  	if (!dsi_host) {
> @@ -230,25 +243,38 @@ int kmb_dsi_host_bridge_init(struct device *dev)
>  			dsi_device = kzalloc_obj(*dsi_device);
>  			if (!dsi_device) {
>  				kfree(dsi_host);
> +				dsi_host = NULL;
>  				return -ENOMEM;
>  			}
>  		}
>  
>  		dsi_host->dev = dev;
> -		mipi_dsi_host_register(dsi_host);
> +		ret = mipi_dsi_host_register(dsi_host);
> +		if (ret) {
> +			DRM_ERROR("failed to register dsi host\n");
> +			kfree(dsi_device);
> +			dsi_device = NULL;
> +			kfree(dsi_host);
> +			dsi_host = NULL;
> +			return ret;
> +		}
> +
> +		host_registered = true;
>  	}
>  
>  	/* Find ADV7535 node and initialize it */
>  	dsi_out = of_graph_get_endpoint_by_regs(dev->of_node, 0, 1);
>  	if (!dsi_out) {
>  		DRM_ERROR("Failed to get dsi_out node info from DT\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_unregister_host;
>  	}
>  	encoder_node = of_graph_get_remote_port_parent(dsi_out);
>  	if (!encoder_node) {
>  		of_node_put(dsi_out);
>  		DRM_ERROR("Failed to get bridge info from DT\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_unregister_host;
>  	}
>  	/* Locate drm bridge from the hdmi encoder DT node */
>  	adv_bridge = of_drm_find_bridge(encoder_node);
> @@ -256,10 +282,16 @@ int kmb_dsi_host_bridge_init(struct device *dev)
>  	of_node_put(encoder_node);
>  	if (!adv_bridge) {
>  		DRM_DEBUG("Wait for external bridge driver DT\n");
> -		return -EPROBE_DEFER;
> +		ret = -EPROBE_DEFER;
> +		goto err_unregister_host;
>  	}
>  
>  	return 0;
> +
> +err_unregister_host:
> +	if (host_registered)
> +		kmb_dsi_host_unregister(NULL);
> +	return ret;
>  }
>  
>  static u32 mipi_get_datatype_params(u32 data_type, u32 data_mode,
> -- 
> 2.43.0
> 
ping.

      parent reply	other threads:[~2026-05-06 13:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 15:06 [PATCH 1/2] drm/kmb: reset DSI host singleton state on teardown Osama Abdelkader
2026-04-20 15:06 ` [PATCH 2/2] drm/kmb: unwind partially enabled DSI clocks on error Osama Abdelkader
2026-05-06 13:18 ` Osama Abdelkader [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afs_moGTJaQfqmUt@osama \
    --to=osama.abdelkader@gmail.com \
    --cc=airlied@gmail.com \
    --cc=anitha.chrisanthus@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edmund.j.dea@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.