All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: tomi.valkeinen@ti.com, dri-devel@lists.freedesktop.org
Subject: Re: [RFC 1/7] drm/omap: Use devm_kzalloc() to allocate omap_drm_private
Date: Mon, 4 Sep 2017 12:13:40 +0300	[thread overview]
Message-ID: <fc81ff79-8444-c823-d69c-15aeccdbc34a@ti.com> (raw)
In-Reply-To: <4935903.PPgScnvqmu@avalon>


Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

On 2017-09-01 14:10, Laurent Pinchart wrote:
> Hi Peter,
> 
> Thank you for the patch.
> 
> On Tuesday, 29 August 2017 10:32:12 EEST Peter Ujfalusi wrote:
>> It makes the cleanup paths a bit cleaner.
> 
> But it also goes against a proper implementation of object lifetime management 
> :-( In DRM driver private structures are accessible from file operations, and 
> must thus be reference-counted and only freed when the last userspace user 
> goes away. This may be after the devm_* resources are released right after the 
> .remove() operation is called. Using devm_kzalloc() would thus make it 
> impossible to properly reference-count our data structures.

Hrm, not sure if I follow you on this.
Before this patch the 'priv' was freed up in pdev_remove(). With this
patch the 'priv' is going to be freed up after the pdev_remove() has
returned, so the 'priv' would be available longer than before as we
converted it as managed resource.

If what you are saying is true, then we already have the same issue and
I don't see how this could have been working or need to work. If you
remove the driver and you need to keep the private data available after
the driver has been unloaded, who is going to free that up?

> 
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>> ---
>>  drivers/gpu/drm/omapdrm/omap_drv.c | 19 +++++++------------
>>  1 file changed, 7 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c
>> b/drivers/gpu/drm/omapdrm/omap_drv.c index 9b3c36b48356..903510d8054e
>> 100644
>> --- a/drivers/gpu/drm/omapdrm/omap_drv.c
>> +++ b/drivers/gpu/drm/omapdrm/omap_drv.c
>> @@ -548,19 +548,17 @@ static int pdev_probe(struct platform_device *pdev)
>>  		return ret;
>>  	}
>>
>> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
>> +	if (!priv)
>> +		return -ENOMEM;
>> +
>>  	omap_crtc_pre_init();
>>
>>  	ret = omap_connect_dssdevs();
>>  	if (ret)
>>  		goto err_crtc_uninit;
>>
>> -	/* Allocate and initialize the driver private structure. */
>> -	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>> -	if (!priv) {
>> -		ret = -ENOMEM;
>> -		goto err_disconnect_dssdevs;
>> -	}
>> -
>> +	/* Initialize the driver private structure. */
>>  	priv->dispc_ops = dispc_get_ops();
>>
>>  	soc = soc_device_match(omapdrm_soc_devices);
>> @@ -574,7 +572,7 @@ static int pdev_probe(struct platform_device *pdev)
>>  	ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev);
>>  	if (IS_ERR(ddev)) {
>>  		ret = PTR_ERR(ddev);
>> -		goto err_free_priv;
>> +		goto err_destroy_wq;
>>  	}
>>
>>  	ddev->dev_private = priv;
>> @@ -624,10 +622,8 @@ static int pdev_probe(struct platform_device *pdev)
>>  err_free_drm_dev:
>>  	omap_gem_deinit(ddev);
>>  	drm_dev_unref(ddev);
>> -err_free_priv:
>> +err_destroy_wq:
>>  	destroy_workqueue(priv->wq);
>> -	kfree(priv);
>> -err_disconnect_dssdevs:
>>  	omap_disconnect_dssdevs();
>>  err_crtc_uninit:
>>  	omap_crtc_pre_uninit();
>> @@ -659,7 +655,6 @@ static int pdev_remove(struct platform_device *pdev)
>>  	drm_dev_unref(ddev);
>>
>>  	destroy_workqueue(priv->wq);
>> -	kfree(priv);
>>
>>  	omap_disconnect_dssdevs();
>>  	omap_crtc_pre_uninit();
> 
> 

- Péter

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

  reply	other threads:[~2017-09-04  9:13 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29  7:32 [RFC 0/7] drm/omap: Module parameter for display order configuration Peter Ujfalusi
2017-08-29  7:32 ` [RFC 1/7] drm/omap: Use devm_kzalloc() to allocate omap_drm_private Peter Ujfalusi
2017-09-01 11:10   ` Laurent Pinchart
2017-09-04  9:13     ` Peter Ujfalusi [this message]
2017-09-04  9:41       ` Laurent Pinchart
2017-09-04 11:16         ` Peter Ujfalusi
2017-09-04 14:19           ` Laurent Pinchart
2017-09-05  6:35             ` Peter Ujfalusi
2017-08-29  7:32 ` [RFC 2/7] drm/omap: Allocate drm_device earlier and unref it as last step Peter Ujfalusi
2017-09-01 11:12   ` Laurent Pinchart
2017-08-29  7:32 ` [RFC 3/7] drm/omap: Manage the usable omap_dss_device list within omap_drm_private Peter Ujfalusi
2017-09-01 11:27   ` Laurent Pinchart
2017-09-04  9:19     ` Peter Ujfalusi
2017-09-04  9:45       ` Laurent Pinchart
2017-08-29  7:32 ` [RFC 4/7] drm/omap: Separate the dssdevs array setup from the connect function Peter Ujfalusi
2017-08-29  7:32 ` [RFC 5/7] drm/omap: Do dss_device (display) ordering in omap_drv.c Peter Ujfalusi
2017-09-01 11:32   ` Laurent Pinchart
2017-09-04  9:26     ` Peter Ujfalusi
2017-09-04  9:46       ` Laurent Pinchart
2017-08-29  7:32 ` [RFC 6/7] drm/omap: dss: Remove display ordering from dss/display.c Peter Ujfalusi
2017-08-29  7:32 ` [RFC 7/7] drm/omap: Add kernel parameter to specify the desired display order Peter Ujfalusi
2017-09-01 11:36 ` [RFC 0/7] drm/omap: Module parameter for display order configuration Laurent Pinchart
2017-09-04 10:03   ` Peter Ujfalusi
2018-05-25 20:09     ` Laurent Pinchart
2017-10-05  9:56 ` Pekka Paalanen
2017-10-05 10:01   ` Tomi Valkeinen
2017-10-05 10:43     ` Pekka Paalanen
2017-10-05 11:24       ` Tomi Valkeinen
2017-10-05 11:54         ` Pekka Paalanen

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=fc81ff79-8444-c823-d69c-15aeccdbc34a@ti.com \
    --to=peter.ujfalusi@ti.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=tomi.valkeinen@ti.com \
    /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.