All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: jmondi <jacopo@jmondi.org>
Cc: magnus.damm@gmail.com, linux-renesas-soc@vger.kernel.org
Subject: Re: [RFC v2 1/2] media: platform: Add SH CEU camera interface driver
Date: Tue, 02 May 2017 13:59:31 +0300	[thread overview]
Message-ID: <2385030.nbc1FUkfUQ@avalon> (raw)
In-Reply-To: <20170502094842.GC5814@w540>

Hi Jacopo,

On Tuesday 02 May 2017 11:48:42 jmondi wrote:
> On Thu, Apr 27, 2017 at 02:47:14PM +0300, Laurent Pinchart wrote:
> > Hi Jacopo,
> 
> [snip]
> 
> > > +	pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
> > 
> > devm_kzalloc() is harmful here. You're embedding a struct video_device
> > instead struct sh_ceu_dev, and the video device can outlive the platform
> > driver remove() call if the device node is kept open by userspace when
> > the device is removed. You should use kzalloc() and implement a .release
> > callback for the video_device to kfree() the memory.
> 
> Does this apply to video_unregister_device() as well?
> Should I keep it registered after platform driver removal?

No, the video device must be unregistered in the platform driver's remove() 
callback. As explained in my previous reply the driver private data structure 
can still be reachable if a userspace application has the device node opened 
when it gets unregistered, so you can't free it in the remove() callback.

> Other drivers (eg atmel-isc and pxa_camera) unregister the video
> device in their sensor unbind callbacks.
> As video device has pointer to fops embedded, if we unregister it at
> sensor unbind time, does the ipotetical application having an open
> reference to the device node lose the ability to properly close it?

An application will always be able to close an open file handle, and that will 
always end up in the v4l2_file_operations release() handler, which can access 
the driver's private data structure (including the video_device instance it 
embeds). That's why you can't free the memory before the last file handle is 
closed.

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2017-05-02 10:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27  8:42 [RFC v2 0/2] SH CEU camera driver Jacopo Mondi
2017-04-27  8:42 ` [RFC v2 1/2] media: platform: Add SH CEU camera interface driver Jacopo Mondi
2017-04-27 11:47   ` Laurent Pinchart
2017-05-01 14:37     ` jmondi
2017-05-02  7:58       ` Geert Uytterhoeven
2017-05-02 10:55       ` Laurent Pinchart
2017-05-02  9:48     ` jmondi
2017-05-02 10:59       ` Laurent Pinchart [this message]
2017-05-03  9:52     ` jmondi
2017-05-03 15:06       ` Laurent Pinchart
2017-05-03 16:14         ` jmondi
2017-05-03 16:20           ` Laurent Pinchart
2017-05-04 12:23       ` Chris Brandt
2017-05-04 12:54         ` Laurent Pinchart
2017-04-27  8:42 ` [RFC v2 2/2] media: platform: soc-camera: Remove SH CEU driver Jacopo Mondi
2017-04-27 13:10 ` [RFC v2 0/2] SH CEU camera driver Chris Brandt
2017-04-27 16:14   ` jmondi
2017-04-27 18:03     ` Chris Brandt
2017-05-15 14:37       ` jmondi

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=2385030.nbc1FUkfUQ@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=jacopo@jmondi.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.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.