ksummit.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: Tejun Heo <tj@kernel.org>, Shuah Khan <shuah.kh@samsung.com>,
	Johan Hovold <johan@kernel.org>,
	"ksummit-discuss@lists.linuxfoundation.org"
	<ksummit-discuss@lists.linuxfoundation.org>
Subject: Re: [Ksummit-discuss] [TECH TOPIC] Fix devm_kzalloc, its users, or both
Date: Tue, 11 Aug 2015 13:35:39 +0200	[thread overview]
Message-ID: <s5hbnee2h2s.wl-tiwai@suse.de> (raw)
In-Reply-To: <20150810102330.GQ7557@n2100.arm.linux.org.uk>

On Mon, 10 Aug 2015 12:23:30 +0200,
Russell King - ARM Linux wrote:
> 
> On Mon, Aug 10, 2015 at 09:58:25AM +0200, Linus Walleij wrote:
> > I've encountered it a few times in review, not in practice, a
> > relevant part of the question is whether your driver really cannot
> > live without the bind/unbind attributes in sysfs. I've realized that
> > I don't use them, and I suspect that for a largeish set of drivers
> > the developers don't use it.
> 
> >From the development point of view, it's useful to be able to unbind/rebind
> a driver after something has gone wrong as part of the debugging strategy,
> especially if the driver is built into the kernel.
> 
> > I've actually thought about trying to set that for *any* GPIO
> > driver if they enable the sysfs access to GPIOs as these
> > dangling userspace users is a common problem here, but since
> > we also want to have hotplug/unplug of these hosts it's maybe
> > a real bad idea, as these sysfs files are good for testing that.
> 
> sysfs itself should be fine - the problem is what you do with sysfs.
> I think sysfs's protection comes from kernfs's deactivation, tested by
> kernfs_get_active() before passing any operation up.
> 
> So, when kobject_del() has been called, which calls sysfs_remove_dir()
> and kernfs_remove(), this deactivates the file, and waits (via
> kernfs_drain()) for the active users to go away.  Once that returns,
> no further calls should occur via sysfs.
> 
> When you unexport a GPIO, you do this:
> 
>                 put_device(dev);
>                 device_unregister(dev);
> 
> device_unregister() calls device_del() which in turn calls kobject_del().
> So, by the time device_unregister() returns, you should no longer receive
> any calls to your attributes - and this figures, because the sysfs/kernfs
> code does not take a reference on the struct device anymore, so once
> you drop all other references to the struct device, it's freed, and the
> struct device which _would_ have been passed into your dev_attr code
> would no longer be valid.
> 
> So, I think provided you properly delete kobjects/devices or unregister
> the sysfs attributes prior to private data going away, there should not
> be any use-after-del cases with sysfs attributes.
> 
> Having read the fs/kernfs, fs/sysfs, lib/kobject code this morning, I'm
> now left wondering why people are saying that there's a problem here:
> it seems there isn't if your driver removes any attributes in the
> ->remove path which it registered in the ->probe path - either by
> deleting the attributes themselves, or by deleting the object they are
> attached to.

I thought that the original problem is about the normal device file
accesses.  So, if we have a drain function for normal device files, it
should work well like sysfs/kernfs, too.

Some subsystems have their own ways to do a similar thing, but a
generic framework wound be nice to have, IMO.


thanks,

Takashi

  reply	other threads:[~2015-08-11 11:35 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 15:14 Laurent Pinchart
2015-07-31 15:56 ` Russell King - ARM Linux
2015-07-31 16:34 ` Julia Lawall
2015-07-31 16:51   ` Dmitry Torokhov
2015-07-31 16:57     ` Julia Lawall
2015-07-31 17:03       ` Dmitry Torokhov
2015-07-31 16:53   ` Christoph Hellwig
2015-07-31 17:02     ` James Bottomley
2015-07-31 17:05       ` Dmitry Torokhov
2015-07-31 17:13         ` James Bottomley
2015-07-31 17:33           ` Dmitry Torokhov
2015-07-31 17:36             ` James Bottomley
2015-07-31 18:28               ` Dmitry Torokhov
2015-07-31 18:40                 ` James Bottomley
2015-07-31 19:41                   ` Dmitry Torokhov
2015-08-01 10:57                     ` Mark Brown
2015-08-02 14:05                     ` Russell King - ARM Linux
2015-08-02 14:21                       ` Julia Lawall
2015-08-01 11:04     ` Laurent Pinchart
2015-08-01 11:21       ` Julia Lawall
2015-08-04 12:55         ` Dan Carpenter
2015-08-04 14:01           ` Geert Uytterhoeven
2015-08-04 17:55           ` Dmitry Torokhov
2015-08-04 18:03             ` Julia Lawall
2015-08-04 18:07               ` Dmitry Torokhov
2015-08-04 19:49             ` Russell King - ARM Linux
2015-07-31 17:04 ` Mark Brown
2015-07-31 17:27   ` Russell King - ARM Linux
2015-08-01 10:55     ` Laurent Pinchart
2015-08-01 16:30       ` Russell King - ARM Linux
2015-08-02 23:33         ` Laurent Pinchart
2015-08-01 10:47   ` Laurent Pinchart
2015-08-01 10:55     ` Julia Lawall
2015-08-01 11:01       ` Laurent Pinchart
2015-08-01 15:18         ` Tejun Heo
2015-08-02  0:48           ` Guenter Roeck
2015-08-02 14:30             ` Russell King - ARM Linux
2015-08-02 16:04               ` Guenter Roeck
2015-08-04 10:40               ` Daniel Vetter
2015-08-04 11:18                 ` Russell King - ARM Linux
2015-08-04 11:56                   ` Daniel Vetter
2015-08-04 11:59                     ` Daniel Vetter
2015-08-04 14:48                     ` Tejun Heo
2015-08-04 22:44                     ` Laurent Pinchart
2015-08-05  9:41                       ` Daniel Vetter
2015-08-04 10:49               ` Takashi Iwai
2015-08-10  7:58 ` Linus Walleij
2015-08-10 10:23   ` Russell King - ARM Linux
2015-08-11 11:35     ` Takashi Iwai [this message]
2015-08-11 15:19       ` Daniel Vetter
2015-08-21  2:19 ` Dmitry Torokhov
2015-08-21 15:07   ` Julia Lawall
2015-08-21 16:14     ` Dmitry Torokhov
2015-08-21 16:58       ` Mark Brown
2015-08-21 17:30         ` Dmitry Torokhov
2015-08-21 17:41           ` Mark Brown
2015-08-21 17:52             ` Mark Brown
2015-08-21 18:05               ` Dmitry Torokhov
2015-08-21 18:18                 ` Mark Brown
2015-10-12 18:36                   ` Theodore Ts'o
2015-10-12 18:44                     ` Mark Brown
2015-10-14 15:58                       ` Theodore Ts'o

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=s5hbnee2h2s.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=johan@kernel.org \
    --cc=ksummit-discuss@lists.linuxfoundation.org \
    --cc=linux@arm.linux.org.uk \
    --cc=shuah.kh@samsung.com \
    --cc=tj@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