public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Is devm_* broken ?
Date: Wed, 15 Jul 2015 17:51:28 +0200	[thread overview]
Message-ID: <s5hsi8pl8qn.wl-tiwai@suse.de> (raw)
In-Reply-To: <1503739.gVWYM3p8QD@avalon>

On Wed, 15 Jul 2015 00:34:53 +0200,
Laurent Pinchart wrote:
> 
> Hello,
> 
> I came to realize not too long ago that the following sequence of events will 
> lead to a crash with any platform driver that uses devm_* and creates device 
> nodes.
> 
> 1. Get a platform device bound it its driver
> 2. Open the corresponding device node in userspace and keep it open
> 3. Unbind the platform device from its driver through sysfs
> 
> echo <device-name> > /sys/bus/platform/drivers/<driver-name>/unbind
> 
> (or for hotpluggable devices just unplug the device)
> 
> 4. Close the device node
> 5. Enjoy the fireworks
> 
> While having a device node open prevents modules from being unloaded, it 
> doesn't prevent devices from being unbound from drivers. If the driver uses 
> devm_* helpers to allocate memory the memory will be freed when the device is 
> unbound from the driver, but that memory will still be used by any operation 
> touching an open device node.
> 
> Is devm_* inherently broken ? It's so widely used, tell me I'm missing 
> something obvious.

I don't think this is specific to devm_*() but it's about the resource
management in general.  After bus or driver's remove callback, all
device resources that have been assigned by the driver are supposed to
be freed, or ready to be freed.


Takashi

  reply	other threads:[~2015-07-15 15:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14 22:34 Is devm_* broken ? Laurent Pinchart
2015-07-15 15:51 ` Takashi Iwai [this message]
2015-07-15 16:08   ` Laurent Pinchart
2015-07-15 16:20     ` Takashi Iwai
2015-07-15 16:27       ` Laurent Pinchart
2015-07-15 16:34         ` Takashi Iwai
2015-07-28 14:10           ` Laurent Pinchart
2015-07-15 17:00 ` Dan Williams
2015-07-15 18:03   ` Tejun Heo
2015-07-28 14:16     ` Laurent Pinchart
2015-07-28 15:22       ` Tejun Heo
2015-07-28 17:05         ` Laurent Pinchart
2015-08-04 19:56           ` Pavel Machek
2015-08-04 21:26             ` Dmitry Torokhov

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=s5hsi8pl8qn.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@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