dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: linux-renesas-soc@vger.kernel.org,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	Kieran Bingham <kieran.bingham@ideasonboard.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 5/9] drm: rcar-du: Use DRM-managed allocation for encoders
Date: Mon, 14 Dec 2020 15:28:56 +0200	[thread overview]
Message-ID: <X9domDvwBxTw5npR@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20201214103750.bpwmxe4icjtika4v@uno.localdomain>

Hi Jacopo,

On Mon, Dec 14, 2020 at 11:37:50AM +0100, Jacopo Mondi wrote:
> On Sat, Dec 05, 2020 at 12:01:35AM +0200, Laurent Pinchart wrote:
> > devm_kzalloc() is the wrong API to allocate encoders, as the lifetime of
> > the encoders is tied to the DRM device, not the device to driver
> > binding. drmm_kzalloc() isn't a good option either, as it would result
> > in the encoder being freed before being unregistered during the managed
> > cleanup of the DRM objects. Use a plain kzalloc(), and register a drmm
> > action to cleanup the encoder.
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> >  drivers/gpu/drm/rcar-du/rcar_du_encoder.c | 47 ++++++++++++++---------
> >  1 file changed, 29 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/rcar-du/rcar_du_encoder.c b/drivers/gpu/drm/rcar-du/rcar_du_encoder.c
> > index 0edce24f2053..7c491ff72cd2 100644
> > --- a/drivers/gpu/drm/rcar-du/rcar_du_encoder.c
> > +++ b/drivers/gpu/drm/rcar-du/rcar_du_encoder.c
> > @@ -8,12 +8,13 @@
> >   */
> >
> >  #include <linux/export.h>
> > +#include <linux/slab.h>
> >
> >  #include <drm/drm_bridge.h>
> >  #include <drm/drm_crtc.h>
> > +#include <drm/drm_managed.h>
> >  #include <drm/drm_modeset_helper_vtables.h>
> >  #include <drm/drm_panel.h>
> > -#include <drm/drm_simple_kms_helper.h>
> >
> >  #include "rcar_du_drv.h"
> >  #include "rcar_du_encoder.h"
> > @@ -44,6 +45,17 @@ static unsigned int rcar_du_encoder_count_ports(struct device_node *node)
> >  	return num_ports;
> >  }
> >
> > +static const struct drm_encoder_funcs rcar_du_encoder_funcs = {
> > +};
> > +
> > +static void rcar_du_encoder_release(struct drm_device *dev, void *res)
> > +{
> > +	struct rcar_du_encoder *renc = res;
> > +
> > +	drm_encoder_cleanup(&renc->base);
> > +	kfree(renc);
> > +}
> > +
> >  int rcar_du_encoder_init(struct rcar_du_device *rcdu,
> >  			 enum rcar_du_output output,
> >  			 struct device_node *enc_node)
> > @@ -53,7 +65,7 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu,
> >  	struct drm_bridge *bridge;
> >  	int ret;
> >
> > -	renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL);
> > +	renc = kzalloc(sizeof(*renc), GFP_KERNEL);
> >  	if (renc == NULL)
> >  		return -ENOMEM;
> >
> > @@ -76,20 +88,20 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu,
> >
> >  		if (IS_ERR(panel)) {
> >  			ret = PTR_ERR(panel);
> > -			goto done;
> > +			goto error;
> >  		}
> >
> >  		bridge = devm_drm_panel_bridge_add_typed(rcdu->dev, panel,
> >  							 DRM_MODE_CONNECTOR_DPI);
> >  		if (IS_ERR(bridge)) {
> >  			ret = PTR_ERR(bridge);
> > -			goto done;
> > +			goto error;
> >  		}
> >  	} else {
> >  		bridge = of_drm_find_bridge(enc_node);
> >  		if (!bridge) {
> >  			ret = -EPROBE_DEFER;
> > -			goto done;
> > +			goto error;
> >  		}
> >
> >  		if (output == RCAR_DU_OUTPUT_LVDS0 ||
> > @@ -104,28 +116,27 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu,
> >  	if (rcdu->info->gen >= 3 && output == RCAR_DU_OUTPUT_LVDS1) {
> >  		if (rcar_lvds_dual_link(bridge)) {
> >  			ret = -ENOLINK;
> > -			goto done;
> > +			goto error;
> >  		}
> >  	}
> >
> > -	ret = drm_simple_encoder_init(rcdu->ddev, encoder,
> > -				      DRM_MODE_ENCODER_NONE);
> > +	ret = drm_encoder_init(rcdu->ddev, encoder, &rcar_du_encoder_funcs,
> > +			       DRM_MODE_ENCODER_NONE, NULL);
> 
> I might have missed the reason for this.
> Why add an action later instead of making rcar_du_encoder_release part
> of rcar_du_encoder_funcs ?

Because the subsystem is moving towards drmm_* instead of manual release
callbacks (I don't mind the manual release callbacks personally). Note
that there's "[PATCH v4 02/19] drm: add drmm_encoder_alloc()" that
should be merged soon, which will allow simplifying this.

> >  	if (ret < 0)
> > -		goto done;
> > +		goto error;
> > +
> > +	ret = drmm_add_action_or_reset(rcdu->ddev, rcar_du_encoder_release,
> > +				       renc);
> > +	if (ret)
> > +		return ret;
> >
> >  	/*
> >  	 * Attach the bridge to the encoder. The bridge will create the
> >  	 * connector.
> >  	 */
> > -	ret = drm_bridge_attach(encoder, bridge, NULL, 0);
> > -	if (ret) {
> > -		drm_encoder_cleanup(encoder);
> > -		return ret;
> > -	}
> > -
> > -done:
> > -	if (ret < 0)
> > -		devm_kfree(rcdu->dev, renc);
> > +	return drm_bridge_attach(encoder, bridge, NULL, 0);
> >
> > +error:
> > +	kfree(renc);
> >  	return ret;
> >  }

-- 
Regards,

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

  reply	other threads:[~2020-12-14 13:29 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04 22:01 [PATCH 0/9] drm: rcar-du: Fix LVDS-related crash Laurent Pinchart
2020-12-04 22:01 ` [PATCH 1/9] drm: rcar-du: Fix crash when using LVDS1 clock for CRTC Laurent Pinchart
2020-12-07  8:15   ` Geert Uytterhoeven
2020-12-08  0:42     ` Laurent Pinchart
2020-12-14  9:43   ` Jacopo Mondi
2020-12-14 15:36   ` Kieran Bingham
2020-12-04 22:01 ` [PATCH 2/9] drm: rcar-du: Release vsp device reference in all error paths Laurent Pinchart
2020-12-14 10:03   ` Jacopo Mondi
2020-12-14 15:42   ` Kieran Bingham
2020-12-04 22:01 ` [PATCH 3/9] drm: rcar-du: Drop unneeded encoder cleanup in error path Laurent Pinchart
2020-12-14 10:11   ` Jacopo Mondi
2020-12-14 13:19     ` Laurent Pinchart
2020-12-14 15:59   ` Kieran Bingham
2020-12-04 22:01 ` [PATCH 4/9] drm: rcar-du: Use DRM-managed allocation for VSP planes Laurent Pinchart
2020-12-14 16:20   ` Kieran Bingham
2020-12-14 16:26     ` Laurent Pinchart
2020-12-15 15:42       ` Geert Uytterhoeven
2020-12-04 22:01 ` [PATCH 5/9] drm: rcar-du: Use DRM-managed allocation for encoders Laurent Pinchart
2020-12-14 10:37   ` Jacopo Mondi
2020-12-14 13:28     ` Laurent Pinchart [this message]
2020-12-04 22:01 ` [PATCH 6/9] drm: rcar-du: Embed drm_device in rcar_du_device Laurent Pinchart
2020-12-14 10:55   ` Jacopo Mondi
2020-12-14 17:02   ` Kieran Bingham
2020-12-04 22:01 ` [PATCH 7/9] drm: rcar-du: Replace dev_private with container_of Laurent Pinchart
2020-12-14 10:58   ` Jacopo Mondi
2020-12-14 17:11     ` Kieran Bingham
2020-12-04 22:01 ` [PATCH 8/9] drm: rcar-du: Skip encoder allocation for LVDS1 in dual-link mode Laurent Pinchart
2020-12-14 11:04   ` Jacopo Mondi
2020-12-14 13:32     ` Laurent Pinchart
2020-12-14 17:21   ` Kieran Bingham
2020-12-04 22:01 ` [PATCH 9/9] drm: rcar-du: Drop local encoder variable Laurent Pinchart
2020-12-14 11:05   ` Jacopo Mondi
2020-12-14 17:16   ` Kieran Bingham

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=X9domDvwBxTw5npR@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jacopo@jmondi.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-renesas-soc@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox