All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Maxime Ripard <maxime@cerno.tech>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, David Airlie <airlied@linux.ie>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	dri-devel@lists.freedesktop.org, Chen-Yu Tsai <wens@csie.org>,
	Rob Herring <robh+dt@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Frank Rowand <frowand.list@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RESEND v3 1/6] drm/of: Change the prototype of drm_of_lvds_get_dual_link_pixel_order
Date: Mon, 12 Oct 2020 02:00:30 +0300	[thread overview]
Message-ID: <20201011230030.GD3944@pendragon.ideasonboard.com> (raw)
In-Reply-To: <6169dd15782627c8415583881fa94ba39c4f5221.1601910923.git-series.maxime@cerno.tech>

Hi Maxime,

Thank you for the patch.

On Mon, Oct 05, 2020 at 05:15:39PM +0200, Maxime Ripard wrote:
> The drm_of_lvds_get_dual_link_pixel_order() function took so far the
> device_node of the two ports used together to make up a dual-link LVDS
> output.
> 
> This assumes that a binding would use an entire port for the LVDS output.
> However, some bindings have used endpoints instead and thus we need to
> operate at the endpoint level. Change slightly the arguments to allow that.
> 
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---
>  drivers/gpu/drm/drm_of.c            | 98 +++++++++++++++---------------
>  drivers/gpu/drm/rcar-du/rcar_lvds.c |  8 +--
>  include/drm/drm_of.h                | 16 +++--
>  3 files changed, 63 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
> index b50b44e76279..2dcb49b0401b 100644
> --- a/drivers/gpu/drm/drm_of.c
> +++ b/drivers/gpu/drm/drm_of.c
> @@ -291,50 +291,34 @@ static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node)
>  	       (odd_pixels ? DRM_OF_LVDS_ODD : 0);
>  }
>  
> -static int drm_of_lvds_get_remote_pixels_type(
> -			const struct device_node *port_node)
> +static int drm_of_lvds_get_remote_pixels_type(const struct device_node *endpoint)
>  {
> -	struct device_node *endpoint = NULL;
> -	int pixels_type = -EPIPE;
> +	struct device_node *remote_port;
> +	int pixels_type;
>  
> -	for_each_child_of_node(port_node, endpoint) {
> -		struct device_node *remote_port;
> -		int current_pt;
> -
> -		if (!of_node_name_eq(endpoint, "endpoint"))
> -			continue;
> -
> -		remote_port = of_graph_get_remote_port(endpoint);
> -		if (!remote_port) {
> -			of_node_put(remote_port);
> -			return -EPIPE;
> -		}
> -
> -		current_pt = drm_of_lvds_get_port_pixels_type(remote_port);
> +	remote_port = of_graph_get_remote_port(endpoint);
> +	if (!remote_port) {
>  		of_node_put(remote_port);

You can drop this line.

> -		if (pixels_type < 0)
> -			pixels_type = current_pt;
> -
> -		/*
> -		 * Sanity check, ensure that all remote endpoints have the same
> -		 * pixel type. We may lift this restriction later if we need to
> -		 * support multiple sinks with different dual-link
> -		 * configurations by passing the endpoints explicitly to
> -		 * drm_of_lvds_get_dual_link_pixel_order().
> -		 */

Shouldn't we keep this check when endpoint_id is -1 in
drm_of_lvds_get_dual_link_pixel_order() ?

> -		if (!current_pt || pixels_type != current_pt) {
> -			of_node_put(remote_port);
> -			return -EINVAL;
> -		}
> +		return -EPIPE;
>  	}
>  
> +	pixels_type = drm_of_lvds_get_port_pixels_type(remote_port);
> +	of_node_put(remote_port);
> +
> +	if (pixels_type < 0)
> +		pixels_type = -EPIPE;
> +
>  	return pixels_type;
>  }
>  
>  /**
>   * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order
> - * @port1: First DT port node of the Dual-link LVDS source
> - * @port2: Second DT port node of the Dual-link LVDS source
> + * @dev1: First DT device node of the Dual-Link LVDS source
> + * @port1_id: ID of the first DT port node of the Dual-Link LVDS source
> + * @endpoint1_id: ID of the first DT port node of the Dual-Link LVDS source

The port1_id and endpoint1_id parameters have the exact same
documentation. Same for port2.

I would shorten port1_id to port1 and endpoint1_id to endpoint1, but
that's up to you.

> + * @dev2: First DT device node of the Dual-Link LVDS source
> + * @port2_id: ID of the first DT port node of the Dual-Link LVDS source
> + * @endpoint2_id: ID of the first DT port node of the Dual-Link LVDS source
>   *
>   * An LVDS dual-link connection is made of two links, with even pixels
>   * transitting on one link, and odd pixels on the other link. This function
> @@ -348,32 +332,48 @@ static int drm_of_lvds_get_remote_pixels_type(
>   *
>   * If either port is not connected, this function returns -EPIPE.
>   *
> - * @port1 and @port2 are typically DT sibling nodes, but may have different
> - * parents when, for instance, two separate LVDS encoders carry the even and odd
> - * pixels.
> + * @port1_id and @port2_id are typically DT sibling nodes, but may have
> + * different parents when, for instance, two separate LVDS encoders carry the
> + * even and odd pixels.
> + *
> + * If @port1_id, @port2_id, @endpoint1_id or @endpoint2_id are set to -1, their
> + * value is going to be ignored.

And what happens when they're ignored ? :-) You should document that
the first endpoint / port is then used.

>   *
>   * Return:
> - * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2
> - *   carries odd pixels
> - * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2
> - *   carries even pixels
> - * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or
> - *   the sink configuration is invalid
> - * * -EPIPE - when @port1 or @port2 are not connected
> + * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @endpoint1_id carries even pixels and
> + *   @endpoint2_id carries odd pixels
> + * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @endpoint1_id carries odd pixels and
> + *   @endpoint2_id carries even pixels
> + * * -EINVAL - @endpoint1_id and @endpoint2_id are not connected to a dual-link
> + *   LVDS sink, or the sink configuration is invalid
> + * * -EPIPE - when @endpoint1_id or @endpoint2_id are not connected
>   */
> -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -					  const struct device_node *port2)
> +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +					  int port1_id,
> +					  int endpoint1_id,
> +					  const struct device_node *dev2,
> +					  int port2_id,
> +					  int endpoint2_id)
>  {
> +	struct device_node *endpoint1, *endpoint2;
>  	int remote_p1_pt, remote_p2_pt;
>  
> -	if (!port1 || !port2)
> +	if (!dev1 || !dev2)
> +		return -EINVAL;
> +
> +	endpoint1 = of_graph_get_endpoint_by_regs(dev1, port1_id, endpoint1_id);
> +	if (!endpoint1)
> +		return -EINVAL;
> +
> +	endpoint2 = of_graph_get_endpoint_by_regs(dev2, port2_id, endpoint2_id);
> +	if (!endpoint2)
>  		return -EINVAL;

YOu're leaking a reference to endpoint1 here, and to both endpoint1 and
endpoint2 in all the error paths (and the success path actually) below.

>  
> -	remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1);
> +	remote_p1_pt = drm_of_lvds_get_remote_pixels_type(endpoint1);
>  	if (remote_p1_pt < 0)
>  		return remote_p1_pt;
>  
> -	remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2);
> +	remote_p2_pt = drm_of_lvds_get_remote_pixels_type(endpoint2);
>  	if (remote_p2_pt < 0)
>  		return remote_p2_pt;
>  
> diff --git a/drivers/gpu/drm/rcar-du/rcar_lvds.c b/drivers/gpu/drm/rcar-du/rcar_lvds.c
> index ab0d49618cf9..02d8c4ce820e 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_lvds.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_lvds.c
> @@ -715,7 +715,6 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
>  {
>  	const struct of_device_id *match;
>  	struct device_node *companion;
> -	struct device_node *port0, *port1;
>  	struct rcar_lvds *companion_lvds;
>  	struct device *dev = lvds->dev;
>  	int dual_link;
> @@ -743,11 +742,8 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
>  	 * connected to, if they are marked as expecting even pixels and
>  	 * odd pixels than we need to enable vertical stripe output.
>  	 */
> -	port0 = of_graph_get_port_by_id(dev->of_node, 1);
> -	port1 = of_graph_get_port_by_id(companion, 1);
> -	dual_link = drm_of_lvds_get_dual_link_pixel_order(port0, port1);
> -	of_node_put(port0);
> -	of_node_put(port1);
> +	dual_link = drm_of_lvds_get_dual_link_pixel_order(dev->of_node, 1, -1,
> +							  companion, 1, -1);
>  
>  	switch (dual_link) {
>  	case DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS:
> diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h
> index b9b093add92e..7bb1f6603beb 100644
> --- a/include/drm/drm_of.h
> +++ b/include/drm/drm_of.h
> @@ -47,8 +47,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
>  				int port, int endpoint,
>  				struct drm_panel **panel,
>  				struct drm_bridge **bridge);
> -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -					  const struct device_node *port2);
> +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +					  int port1_id,
> +					  int endpoint1_id,
> +					  const struct device_node *dev2,
> +					  int port2_id,
> +					  int endpoint2_id);
>  #else
>  static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
>  					  struct device_node *port)
> @@ -93,8 +97,12 @@ static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
>  }
>  
>  static inline int
> -drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -				      const struct device_node *port2)
> +drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +				      int port1_id,
> +				      int endpoint1_id,
> +				      const struct device_node *dev2,
> +				      int port2_id,
> +				      int endpoint2_id)
>  {
>  	return -EINVAL;
>  }

-- 
Regards,

Laurent Pinchart

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Maxime Ripard <maxime@cerno.tech>
Cc: Chen-Yu Tsai <wens@csie.org>,
	dri-devel@lists.freedesktop.org,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Daniel Vetter <daniel.vetter@intel.com>,
	David Airlie <airlied@linux.ie>,
	devicetree@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
	Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RESEND v3 1/6] drm/of: Change the prototype of drm_of_lvds_get_dual_link_pixel_order
Date: Mon, 12 Oct 2020 02:00:30 +0300	[thread overview]
Message-ID: <20201011230030.GD3944@pendragon.ideasonboard.com> (raw)
In-Reply-To: <6169dd15782627c8415583881fa94ba39c4f5221.1601910923.git-series.maxime@cerno.tech>

Hi Maxime,

Thank you for the patch.

On Mon, Oct 05, 2020 at 05:15:39PM +0200, Maxime Ripard wrote:
> The drm_of_lvds_get_dual_link_pixel_order() function took so far the
> device_node of the two ports used together to make up a dual-link LVDS
> output.
> 
> This assumes that a binding would use an entire port for the LVDS output.
> However, some bindings have used endpoints instead and thus we need to
> operate at the endpoint level. Change slightly the arguments to allow that.
> 
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---
>  drivers/gpu/drm/drm_of.c            | 98 +++++++++++++++---------------
>  drivers/gpu/drm/rcar-du/rcar_lvds.c |  8 +--
>  include/drm/drm_of.h                | 16 +++--
>  3 files changed, 63 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
> index b50b44e76279..2dcb49b0401b 100644
> --- a/drivers/gpu/drm/drm_of.c
> +++ b/drivers/gpu/drm/drm_of.c
> @@ -291,50 +291,34 @@ static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node)
>  	       (odd_pixels ? DRM_OF_LVDS_ODD : 0);
>  }
>  
> -static int drm_of_lvds_get_remote_pixels_type(
> -			const struct device_node *port_node)
> +static int drm_of_lvds_get_remote_pixels_type(const struct device_node *endpoint)
>  {
> -	struct device_node *endpoint = NULL;
> -	int pixels_type = -EPIPE;
> +	struct device_node *remote_port;
> +	int pixels_type;
>  
> -	for_each_child_of_node(port_node, endpoint) {
> -		struct device_node *remote_port;
> -		int current_pt;
> -
> -		if (!of_node_name_eq(endpoint, "endpoint"))
> -			continue;
> -
> -		remote_port = of_graph_get_remote_port(endpoint);
> -		if (!remote_port) {
> -			of_node_put(remote_port);
> -			return -EPIPE;
> -		}
> -
> -		current_pt = drm_of_lvds_get_port_pixels_type(remote_port);
> +	remote_port = of_graph_get_remote_port(endpoint);
> +	if (!remote_port) {
>  		of_node_put(remote_port);

You can drop this line.

> -		if (pixels_type < 0)
> -			pixels_type = current_pt;
> -
> -		/*
> -		 * Sanity check, ensure that all remote endpoints have the same
> -		 * pixel type. We may lift this restriction later if we need to
> -		 * support multiple sinks with different dual-link
> -		 * configurations by passing the endpoints explicitly to
> -		 * drm_of_lvds_get_dual_link_pixel_order().
> -		 */

Shouldn't we keep this check when endpoint_id is -1 in
drm_of_lvds_get_dual_link_pixel_order() ?

> -		if (!current_pt || pixels_type != current_pt) {
> -			of_node_put(remote_port);
> -			return -EINVAL;
> -		}
> +		return -EPIPE;
>  	}
>  
> +	pixels_type = drm_of_lvds_get_port_pixels_type(remote_port);
> +	of_node_put(remote_port);
> +
> +	if (pixels_type < 0)
> +		pixels_type = -EPIPE;
> +
>  	return pixels_type;
>  }
>  
>  /**
>   * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order
> - * @port1: First DT port node of the Dual-link LVDS source
> - * @port2: Second DT port node of the Dual-link LVDS source
> + * @dev1: First DT device node of the Dual-Link LVDS source
> + * @port1_id: ID of the first DT port node of the Dual-Link LVDS source
> + * @endpoint1_id: ID of the first DT port node of the Dual-Link LVDS source

The port1_id and endpoint1_id parameters have the exact same
documentation. Same for port2.

I would shorten port1_id to port1 and endpoint1_id to endpoint1, but
that's up to you.

> + * @dev2: First DT device node of the Dual-Link LVDS source
> + * @port2_id: ID of the first DT port node of the Dual-Link LVDS source
> + * @endpoint2_id: ID of the first DT port node of the Dual-Link LVDS source
>   *
>   * An LVDS dual-link connection is made of two links, with even pixels
>   * transitting on one link, and odd pixels on the other link. This function
> @@ -348,32 +332,48 @@ static int drm_of_lvds_get_remote_pixels_type(
>   *
>   * If either port is not connected, this function returns -EPIPE.
>   *
> - * @port1 and @port2 are typically DT sibling nodes, but may have different
> - * parents when, for instance, two separate LVDS encoders carry the even and odd
> - * pixels.
> + * @port1_id and @port2_id are typically DT sibling nodes, but may have
> + * different parents when, for instance, two separate LVDS encoders carry the
> + * even and odd pixels.
> + *
> + * If @port1_id, @port2_id, @endpoint1_id or @endpoint2_id are set to -1, their
> + * value is going to be ignored.

And what happens when they're ignored ? :-) You should document that
the first endpoint / port is then used.

>   *
>   * Return:
> - * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2
> - *   carries odd pixels
> - * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2
> - *   carries even pixels
> - * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or
> - *   the sink configuration is invalid
> - * * -EPIPE - when @port1 or @port2 are not connected
> + * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @endpoint1_id carries even pixels and
> + *   @endpoint2_id carries odd pixels
> + * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @endpoint1_id carries odd pixels and
> + *   @endpoint2_id carries even pixels
> + * * -EINVAL - @endpoint1_id and @endpoint2_id are not connected to a dual-link
> + *   LVDS sink, or the sink configuration is invalid
> + * * -EPIPE - when @endpoint1_id or @endpoint2_id are not connected
>   */
> -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -					  const struct device_node *port2)
> +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +					  int port1_id,
> +					  int endpoint1_id,
> +					  const struct device_node *dev2,
> +					  int port2_id,
> +					  int endpoint2_id)
>  {
> +	struct device_node *endpoint1, *endpoint2;
>  	int remote_p1_pt, remote_p2_pt;
>  
> -	if (!port1 || !port2)
> +	if (!dev1 || !dev2)
> +		return -EINVAL;
> +
> +	endpoint1 = of_graph_get_endpoint_by_regs(dev1, port1_id, endpoint1_id);
> +	if (!endpoint1)
> +		return -EINVAL;
> +
> +	endpoint2 = of_graph_get_endpoint_by_regs(dev2, port2_id, endpoint2_id);
> +	if (!endpoint2)
>  		return -EINVAL;

YOu're leaking a reference to endpoint1 here, and to both endpoint1 and
endpoint2 in all the error paths (and the success path actually) below.

>  
> -	remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1);
> +	remote_p1_pt = drm_of_lvds_get_remote_pixels_type(endpoint1);
>  	if (remote_p1_pt < 0)
>  		return remote_p1_pt;
>  
> -	remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2);
> +	remote_p2_pt = drm_of_lvds_get_remote_pixels_type(endpoint2);
>  	if (remote_p2_pt < 0)
>  		return remote_p2_pt;
>  
> diff --git a/drivers/gpu/drm/rcar-du/rcar_lvds.c b/drivers/gpu/drm/rcar-du/rcar_lvds.c
> index ab0d49618cf9..02d8c4ce820e 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_lvds.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_lvds.c
> @@ -715,7 +715,6 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
>  {
>  	const struct of_device_id *match;
>  	struct device_node *companion;
> -	struct device_node *port0, *port1;
>  	struct rcar_lvds *companion_lvds;
>  	struct device *dev = lvds->dev;
>  	int dual_link;
> @@ -743,11 +742,8 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
>  	 * connected to, if they are marked as expecting even pixels and
>  	 * odd pixels than we need to enable vertical stripe output.
>  	 */
> -	port0 = of_graph_get_port_by_id(dev->of_node, 1);
> -	port1 = of_graph_get_port_by_id(companion, 1);
> -	dual_link = drm_of_lvds_get_dual_link_pixel_order(port0, port1);
> -	of_node_put(port0);
> -	of_node_put(port1);
> +	dual_link = drm_of_lvds_get_dual_link_pixel_order(dev->of_node, 1, -1,
> +							  companion, 1, -1);
>  
>  	switch (dual_link) {
>  	case DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS:
> diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h
> index b9b093add92e..7bb1f6603beb 100644
> --- a/include/drm/drm_of.h
> +++ b/include/drm/drm_of.h
> @@ -47,8 +47,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
>  				int port, int endpoint,
>  				struct drm_panel **panel,
>  				struct drm_bridge **bridge);
> -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -					  const struct device_node *port2);
> +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +					  int port1_id,
> +					  int endpoint1_id,
> +					  const struct device_node *dev2,
> +					  int port2_id,
> +					  int endpoint2_id);
>  #else
>  static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
>  					  struct device_node *port)
> @@ -93,8 +97,12 @@ static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
>  }
>  
>  static inline int
> -drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -				      const struct device_node *port2)
> +drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +				      int port1_id,
> +				      int endpoint1_id,
> +				      const struct device_node *dev2,
> +				      int port2_id,
> +				      int endpoint2_id)
>  {
>  	return -EINVAL;
>  }

-- 
Regards,

Laurent Pinchart

WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Maxime Ripard <maxime@cerno.tech>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, David Airlie <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org, Chen-Yu Tsai <wens@csie.org>,
	Rob Herring <robh+dt@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Frank Rowand <frowand.list@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RESEND v3 1/6] drm/of: Change the prototype of drm_of_lvds_get_dual_link_pixel_order
Date: Mon, 12 Oct 2020 02:00:30 +0300	[thread overview]
Message-ID: <20201011230030.GD3944@pendragon.ideasonboard.com> (raw)
In-Reply-To: <6169dd15782627c8415583881fa94ba39c4f5221.1601910923.git-series.maxime@cerno.tech>

Hi Maxime,

Thank you for the patch.

On Mon, Oct 05, 2020 at 05:15:39PM +0200, Maxime Ripard wrote:
> The drm_of_lvds_get_dual_link_pixel_order() function took so far the
> device_node of the two ports used together to make up a dual-link LVDS
> output.
> 
> This assumes that a binding would use an entire port for the LVDS output.
> However, some bindings have used endpoints instead and thus we need to
> operate at the endpoint level. Change slightly the arguments to allow that.
> 
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---
>  drivers/gpu/drm/drm_of.c            | 98 +++++++++++++++---------------
>  drivers/gpu/drm/rcar-du/rcar_lvds.c |  8 +--
>  include/drm/drm_of.h                | 16 +++--
>  3 files changed, 63 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
> index b50b44e76279..2dcb49b0401b 100644
> --- a/drivers/gpu/drm/drm_of.c
> +++ b/drivers/gpu/drm/drm_of.c
> @@ -291,50 +291,34 @@ static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node)
>  	       (odd_pixels ? DRM_OF_LVDS_ODD : 0);
>  }
>  
> -static int drm_of_lvds_get_remote_pixels_type(
> -			const struct device_node *port_node)
> +static int drm_of_lvds_get_remote_pixels_type(const struct device_node *endpoint)
>  {
> -	struct device_node *endpoint = NULL;
> -	int pixels_type = -EPIPE;
> +	struct device_node *remote_port;
> +	int pixels_type;
>  
> -	for_each_child_of_node(port_node, endpoint) {
> -		struct device_node *remote_port;
> -		int current_pt;
> -
> -		if (!of_node_name_eq(endpoint, "endpoint"))
> -			continue;
> -
> -		remote_port = of_graph_get_remote_port(endpoint);
> -		if (!remote_port) {
> -			of_node_put(remote_port);
> -			return -EPIPE;
> -		}
> -
> -		current_pt = drm_of_lvds_get_port_pixels_type(remote_port);
> +	remote_port = of_graph_get_remote_port(endpoint);
> +	if (!remote_port) {
>  		of_node_put(remote_port);

You can drop this line.

> -		if (pixels_type < 0)
> -			pixels_type = current_pt;
> -
> -		/*
> -		 * Sanity check, ensure that all remote endpoints have the same
> -		 * pixel type. We may lift this restriction later if we need to
> -		 * support multiple sinks with different dual-link
> -		 * configurations by passing the endpoints explicitly to
> -		 * drm_of_lvds_get_dual_link_pixel_order().
> -		 */

Shouldn't we keep this check when endpoint_id is -1 in
drm_of_lvds_get_dual_link_pixel_order() ?

> -		if (!current_pt || pixels_type != current_pt) {
> -			of_node_put(remote_port);
> -			return -EINVAL;
> -		}
> +		return -EPIPE;
>  	}
>  
> +	pixels_type = drm_of_lvds_get_port_pixels_type(remote_port);
> +	of_node_put(remote_port);
> +
> +	if (pixels_type < 0)
> +		pixels_type = -EPIPE;
> +
>  	return pixels_type;
>  }
>  
>  /**
>   * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order
> - * @port1: First DT port node of the Dual-link LVDS source
> - * @port2: Second DT port node of the Dual-link LVDS source
> + * @dev1: First DT device node of the Dual-Link LVDS source
> + * @port1_id: ID of the first DT port node of the Dual-Link LVDS source
> + * @endpoint1_id: ID of the first DT port node of the Dual-Link LVDS source

The port1_id and endpoint1_id parameters have the exact same
documentation. Same for port2.

I would shorten port1_id to port1 and endpoint1_id to endpoint1, but
that's up to you.

> + * @dev2: First DT device node of the Dual-Link LVDS source
> + * @port2_id: ID of the first DT port node of the Dual-Link LVDS source
> + * @endpoint2_id: ID of the first DT port node of the Dual-Link LVDS source
>   *
>   * An LVDS dual-link connection is made of two links, with even pixels
>   * transitting on one link, and odd pixels on the other link. This function
> @@ -348,32 +332,48 @@ static int drm_of_lvds_get_remote_pixels_type(
>   *
>   * If either port is not connected, this function returns -EPIPE.
>   *
> - * @port1 and @port2 are typically DT sibling nodes, but may have different
> - * parents when, for instance, two separate LVDS encoders carry the even and odd
> - * pixels.
> + * @port1_id and @port2_id are typically DT sibling nodes, but may have
> + * different parents when, for instance, two separate LVDS encoders carry the
> + * even and odd pixels.
> + *
> + * If @port1_id, @port2_id, @endpoint1_id or @endpoint2_id are set to -1, their
> + * value is going to be ignored.

And what happens when they're ignored ? :-) You should document that
the first endpoint / port is then used.

>   *
>   * Return:
> - * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2
> - *   carries odd pixels
> - * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2
> - *   carries even pixels
> - * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or
> - *   the sink configuration is invalid
> - * * -EPIPE - when @port1 or @port2 are not connected
> + * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @endpoint1_id carries even pixels and
> + *   @endpoint2_id carries odd pixels
> + * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @endpoint1_id carries odd pixels and
> + *   @endpoint2_id carries even pixels
> + * * -EINVAL - @endpoint1_id and @endpoint2_id are not connected to a dual-link
> + *   LVDS sink, or the sink configuration is invalid
> + * * -EPIPE - when @endpoint1_id or @endpoint2_id are not connected
>   */
> -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -					  const struct device_node *port2)
> +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +					  int port1_id,
> +					  int endpoint1_id,
> +					  const struct device_node *dev2,
> +					  int port2_id,
> +					  int endpoint2_id)
>  {
> +	struct device_node *endpoint1, *endpoint2;
>  	int remote_p1_pt, remote_p2_pt;
>  
> -	if (!port1 || !port2)
> +	if (!dev1 || !dev2)
> +		return -EINVAL;
> +
> +	endpoint1 = of_graph_get_endpoint_by_regs(dev1, port1_id, endpoint1_id);
> +	if (!endpoint1)
> +		return -EINVAL;
> +
> +	endpoint2 = of_graph_get_endpoint_by_regs(dev2, port2_id, endpoint2_id);
> +	if (!endpoint2)
>  		return -EINVAL;

YOu're leaking a reference to endpoint1 here, and to both endpoint1 and
endpoint2 in all the error paths (and the success path actually) below.

>  
> -	remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1);
> +	remote_p1_pt = drm_of_lvds_get_remote_pixels_type(endpoint1);
>  	if (remote_p1_pt < 0)
>  		return remote_p1_pt;
>  
> -	remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2);
> +	remote_p2_pt = drm_of_lvds_get_remote_pixels_type(endpoint2);
>  	if (remote_p2_pt < 0)
>  		return remote_p2_pt;
>  
> diff --git a/drivers/gpu/drm/rcar-du/rcar_lvds.c b/drivers/gpu/drm/rcar-du/rcar_lvds.c
> index ab0d49618cf9..02d8c4ce820e 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_lvds.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_lvds.c
> @@ -715,7 +715,6 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
>  {
>  	const struct of_device_id *match;
>  	struct device_node *companion;
> -	struct device_node *port0, *port1;
>  	struct rcar_lvds *companion_lvds;
>  	struct device *dev = lvds->dev;
>  	int dual_link;
> @@ -743,11 +742,8 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
>  	 * connected to, if they are marked as expecting even pixels and
>  	 * odd pixels than we need to enable vertical stripe output.
>  	 */
> -	port0 = of_graph_get_port_by_id(dev->of_node, 1);
> -	port1 = of_graph_get_port_by_id(companion, 1);
> -	dual_link = drm_of_lvds_get_dual_link_pixel_order(port0, port1);
> -	of_node_put(port0);
> -	of_node_put(port1);
> +	dual_link = drm_of_lvds_get_dual_link_pixel_order(dev->of_node, 1, -1,
> +							  companion, 1, -1);
>  
>  	switch (dual_link) {
>  	case DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS:
> diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h
> index b9b093add92e..7bb1f6603beb 100644
> --- a/include/drm/drm_of.h
> +++ b/include/drm/drm_of.h
> @@ -47,8 +47,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
>  				int port, int endpoint,
>  				struct drm_panel **panel,
>  				struct drm_bridge **bridge);
> -int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -					  const struct device_node *port2);
> +int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +					  int port1_id,
> +					  int endpoint1_id,
> +					  const struct device_node *dev2,
> +					  int port2_id,
> +					  int endpoint2_id);
>  #else
>  static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
>  					  struct device_node *port)
> @@ -93,8 +97,12 @@ static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
>  }
>  
>  static inline int
> -drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
> -				      const struct device_node *port2)
> +drm_of_lvds_get_dual_link_pixel_order(const struct device_node *dev1,
> +				      int port1_id,
> +				      int endpoint1_id,
> +				      const struct device_node *dev2,
> +				      int port2_id,
> +				      int endpoint2_id)
>  {
>  	return -EINVAL;
>  }

-- 
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-10-11 23:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05 15:15 [PATCH RESEND v3 0/6] drm/sun4i: Add support for dual-link LVDS on the A20 Maxime Ripard
2020-10-05 15:15 ` Maxime Ripard
2020-10-05 15:15 ` Maxime Ripard
2020-10-05 15:15 ` [PATCH RESEND v3 1/6] drm/of: Change the prototype of drm_of_lvds_get_dual_link_pixel_order Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-11 23:00   ` Laurent Pinchart [this message]
2020-10-11 23:00     ` Laurent Pinchart
2020-10-11 23:00     ` Laurent Pinchart
2020-11-18 17:48     ` Maxime Ripard
2020-11-18 17:48       ` Maxime Ripard
2020-11-18 17:48       ` Maxime Ripard
2021-01-26 14:10       ` Laurent Pinchart
2021-01-26 14:10         ` Laurent Pinchart
2021-01-26 14:10         ` Laurent Pinchart
2020-10-05 15:15 ` [PATCH RESEND v3 2/6] dt-bindings: display: sun4i: Add LVDS Dual-Link property Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-07 15:50   ` Rob Herring
2020-10-07 15:50     ` Rob Herring
2020-10-07 15:50     ` Rob Herring
2020-10-05 15:15 ` [PATCH RESEND v3 3/6] drm/sun4i: tcon: Refactor the LVDS and panel probing Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15 ` [PATCH RESEND v3 4/6] drm/sun4i: tcon: Support the LVDS Dual-Link Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-09 15:23   ` Chen-Yu Tsai
2020-10-09 15:23     ` Chen-Yu Tsai
2020-10-09 15:23     ` Chen-Yu Tsai
2020-10-05 15:15 ` [PATCH RESEND v3 5/6] drm/sun4i: tcon: Enable the A20 dual-link output Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-09 15:20   ` Chen-Yu Tsai
2020-10-09 15:20     ` Chen-Yu Tsai
2020-10-09 15:20     ` Chen-Yu Tsai
2020-10-05 15:15 ` [PATCH RESEND v3 6/6] [DO NOT MERGE] ARM: dts: sun7i: Enable LVDS Dual-Link on the Cubieboard Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard
2020-10-05 15:15   ` Maxime Ripard

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=20201011230030.GD3944@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mark.rutland@arm.com \
    --cc=maxime@cerno.tech \
    --cc=robh+dt@kernel.org \
    --cc=tzimmermann@suse.de \
    --cc=wens@csie.org \
    /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.