<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-stable.git/drivers/gpio, branch v3.2.83</title>
<subtitle>Linux kernel stable tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/'/>
<entry>
<title>gpio: sysfs: fix memory leaks and device hotplug</title>
<updated>2015-08-06T23:32:09+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-04-21T15:42:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=5e3a0d7c5c5f3bac1c35595d6b16f2f638e42b53'/>
<id>5e3a0d7c5c5f3bac1c35595d6b16f2f638e42b53</id>
<content type='text'>
commit 483d821108791092798f5d230686868112927044 upstream.

Unregister GPIOs requested through sysfs at chip remove to avoid leaking
the associated memory and sysfs entries.

The stale sysfs entries prevented the gpio numbers from being exported
when the gpio range was later reused (e.g. at device reconnect).

This also fixes the related module-reference leak.

Note that kernfs makes sure that any on-going sysfs operations finish
before the class devices are unregistered and that further accesses
fail.

The chip exported flag is used to prevent gpiod exports during removal.
This also makes it harder to trigger, but does not fix, the related race
between gpiochip_remove and export_store, which is really a race with
gpiod_request that needs to be addressed separately.

Also note that this would prevent the crashes (e.g. NULL-dereferences)
at reconnect that affects pre-3.18 kernels, as well as use-after-free on
operations on open attribute files on pre-3.14 kernels (prior to
kernfs).

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2:
 - Adjust filename, context
 - Move up initialisation of 'desc' in gpio_export()
 - Use global 'gpio_desc' array and gpio_free() function in
   gpiochip_unexport()]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 483d821108791092798f5d230686868112927044 upstream.

Unregister GPIOs requested through sysfs at chip remove to avoid leaking
the associated memory and sysfs entries.

The stale sysfs entries prevented the gpio numbers from being exported
when the gpio range was later reused (e.g. at device reconnect).

This also fixes the related module-reference leak.

Note that kernfs makes sure that any on-going sysfs operations finish
before the class devices are unregistered and that further accesses
fail.

The chip exported flag is used to prevent gpiod exports during removal.
This also makes it harder to trigger, but does not fix, the related race
between gpiochip_remove and export_store, which is really a race with
gpiod_request that needs to be addressed separately.

Also note that this would prevent the crashes (e.g. NULL-dereferences)
at reconnect that affects pre-3.18 kernels, as well as use-after-free on
operations on open attribute files on pre-3.14 kernels (prior to
kernfs).

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2:
 - Adjust filename, context
 - Move up initialisation of 'desc' in gpio_export()
 - Use global 'gpio_desc' array and gpio_free() function in
   gpiochip_unexport()]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: unregister gpiochip device before removing it</title>
<updated>2015-08-06T23:32:08+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-01-12T16:12:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=c833e96de15cb46c8587271a32c651c0acc40dd3'/>
<id>c833e96de15cb46c8587271a32c651c0acc40dd3</id>
<content type='text'>
commit 01cca93a9491ed95992523ff7e79dd9bfcdea8e0 upstream.

Unregister gpiochip device (used to export information through sysfs)
before removing it internally. This way removal will reverse addition.

Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 01cca93a9491ed95992523ff7e79dd9bfcdea8e0 upstream.

Unregister gpiochip device (used to export information through sysfs)
before removing it internally. This way removal will reverse addition.

Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: tps65912: fix wrong container_of arguments</title>
<updated>2015-05-09T22:16:20+00:00</updated>
<author>
<name>Nicolas Saenz Julienne</name>
<email>nicolassaenzj@gmail.com</email>
</author>
<published>2015-02-19T01:52:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=974c554a808b30effcc2a2b235b3bd2a75f173ce'/>
<id>974c554a808b30effcc2a2b235b3bd2a75f173ce</id>
<content type='text'>
commit 2f97c20e5f7c3582c7310f65a04465bfb0fd0e85 upstream.

The gpio_chip operations receive a pointer the gpio_chip struct which is
contained in the driver's private struct, yet the container_of call in those
functions point to the mfd struct defined in include/linux/mfd/tps65912.h.

Signed-off-by: Nicolas Saenz Julienne &lt;nicolassaenzj@gmail.com&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 2f97c20e5f7c3582c7310f65a04465bfb0fd0e85 upstream.

The gpio_chip operations receive a pointer the gpio_chip struct which is
contained in the driver's private struct, yet the container_of call in those
functions point to the mfd struct defined in include/linux/mfd/tps65912.h.

Signed-off-by: Nicolas Saenz Julienne &lt;nicolassaenzj@gmail.com&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: sysfs: fix memory leak in gpiod_sysfs_set_active_low</title>
<updated>2015-03-06T00:39:18+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-01-26T11:02:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=4a5233cccf2599f8ae122ae6327cb2a2dce8c429'/>
<id>4a5233cccf2599f8ae122ae6327cb2a2dce8c429</id>
<content type='text'>
commit 49d2ca84e433dab854c7a866bc6add09cfab682d upstream.

Fix memory leak in the gpio sysfs interface due to failure to drop
reference to device returned by class_find_device when setting the
gpio-line polarity.

Fixes: 0769746183ca ("gpiolib: add support for changing value polarity
in sysfs")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 49d2ca84e433dab854c7a866bc6add09cfab682d upstream.

Fix memory leak in the gpio sysfs interface due to failure to drop
reference to device returned by class_find_device when setting the
gpio-line polarity.

Fixes: 0769746183ca ("gpiolib: add support for changing value polarity
in sysfs")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: sysfs: fix memory leak in gpiod_export_link</title>
<updated>2015-03-06T00:39:18+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-01-26T11:02:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=67cb64715f1edfa5e05812bf70913c18d065421c'/>
<id>67cb64715f1edfa5e05812bf70913c18d065421c</id>
<content type='text'>
commit 0f303db08df0df9bd0966443ad6001e63960af16 upstream.

Fix memory leak in the gpio sysfs interface due to failure to drop
reference to device returned by class_find_device when creating a link.

Fixes: a4177ee7f1a8 ("gpiolib: allow exported GPIO nodes to be named
using sysfs links")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 0f303db08df0df9bd0966443ad6001e63960af16 upstream.

Fix memory leak in the gpio sysfs interface due to failure to drop
reference to device returned by class_find_device when creating a link.

Fixes: a4177ee7f1a8 ("gpiolib: allow exported GPIO nodes to be named
using sysfs links")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: sysfs: fix gpio attribute-creation race</title>
<updated>2015-02-20T00:49:38+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-01-13T12:00:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=a10ff58e82582898690f3f2328ef5ef772c2a0b1'/>
<id>a10ff58e82582898690f3f2328ef5ef772c2a0b1</id>
<content type='text'>
commit ebbeba120ab2ec6ac5f3afc1425ec6ff0b77ad6f upstream.

Fix attribute-creation race with userspace by using the default group
to create also the contingent gpio device attributes.

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2:
 - Adjust filenames, context
 - Use gpio_to_desc(), not gpiod_to_desc(), in gpio_is_visible()
 - gpio_is_visible() must return mode_t]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit ebbeba120ab2ec6ac5f3afc1425ec6ff0b77ad6f upstream.

Fix attribute-creation race with userspace by using the default group
to create also the contingent gpio device attributes.

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2:
 - Adjust filenames, context
 - Use gpio_to_desc(), not gpiod_to_desc(), in gpio_is_visible()
 - gpio_is_visible() must return mode_t]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: sysfs: fix gpio device-attribute leak</title>
<updated>2015-02-20T00:49:38+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-01-13T12:00:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=91111b535d9d2b7927b59639e738d395a9f835c0'/>
<id>91111b535d9d2b7927b59639e738d395a9f835c0</id>
<content type='text'>
commit 0915e6feb38de8d3601819992a5bd050201a56fa upstream.

The gpio device attributes were never destroyed when the gpio was
unexported (or on export failures).

Use device_create_with_groups() to create the default device attributes
of the gpio class device. Note that this also fixes the
attribute-creation race with userspace for these attributes.

Remove contingent attributes in export error path and on unexport.

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename, context]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 0915e6feb38de8d3601819992a5bd050201a56fa upstream.

The gpio device attributes were never destroyed when the gpio was
unexported (or on export failures).

Use device_create_with_groups() to create the default device attributes
of the gpio class device. Note that this also fixes the
attribute-creation race with userspace for these attributes.

Remove contingent attributes in export error path and on unexport.

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename, context]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix circular locking dependency (3.3-rc2)</title>
<updated>2015-02-20T00:49:37+00:00</updated>
<author>
<name>Ming Lei</name>
<email>tom.leiming@gmail.com</email>
</author>
<published>2012-02-13T14:53:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=2465975fd5538c4cc17778e9622cbffbd2f0b109'/>
<id>2465975fd5538c4cc17778e9622cbffbd2f0b109</id>
<content type='text'>
commit 864533ceb6db336dead389577c102a8b792a121a upstream.

Hi,

On Wed, Feb 8, 2012 at 8:41 PM, Felipe Balbi &lt;balbi@ti.com&gt; wrote:
&gt; Hi guys,
&gt;
&gt; I have just triggered the folllowing:
&gt;
&gt; [   84.860321] ======================================================
&gt; [   84.860321] [ INFO: possible circular locking dependency detected ]
&gt; [   84.860321] 3.3.0-rc2-00026-ge4e8a39 #474 Not tainted
&gt; [   84.860321] -------------------------------------------------------
&gt; [   84.860321] bash/949 is trying to acquire lock:
&gt; [   84.860321]  (sysfs_lock){+.+.+.}, at: [&lt;c0275358&gt;] gpio_value_store+0x24/0xcc
&gt; [   84.860321]
&gt; [   84.860321] but task is already holding lock:
&gt; [   84.860321]  (s_active#22){++++.+}, at: [&lt;c016996c&gt;] sysfs_write_file+0xdc/0x184
&gt; [   84.911468]
&gt; [   84.911468] which lock already depends on the new lock.
&gt; [   84.911468]
&gt; [   84.920043]
&gt; [   84.920043] the existing dependency chain (in reverse order) is:
&gt; [   84.920043]
&gt; [   84.927886] -&gt; #1 (s_active#22){++++.+}:
&gt; [   84.927886]        [&lt;c008f640&gt;] check_prevs_add+0xdc/0x150
&gt; [   84.927886]        [&lt;c008fc18&gt;] validate_chain.clone.24+0x564/0x694
&gt; [   84.927886]        [&lt;c0090cdc&gt;] __lock_acquire+0x49c/0x980
&gt; [   84.951660]        [&lt;c0091838&gt;] lock_acquire+0x98/0x100
&gt; [   84.951660]        [&lt;c016a8e8&gt;] sysfs_deactivate+0xb0/0x100
&gt; [   84.962982]        [&lt;c016b1b4&gt;] sysfs_addrm_finish+0x2c/0x6c
&gt; [   84.962982]        [&lt;c016b8bc&gt;] sysfs_remove_dir+0x84/0x98
&gt; [   84.962982]        [&lt;c02590d8&gt;] kobject_del+0x10/0x78
&gt; [   84.974670]        [&lt;c02c29e8&gt;] device_del+0x140/0x170
&gt; [   84.974670]        [&lt;c02c2a24&gt;] device_unregister+0xc/0x18
&gt; [   84.985382]        [&lt;c0276894&gt;] gpio_unexport+0xbc/0xdc
&gt; [   84.985382]        [&lt;c02768c8&gt;] gpio_free+0x14/0xfc
&gt; [   85.001708]        [&lt;c0276a28&gt;] unexport_store+0x78/0x8c
&gt; [   85.001708]        [&lt;c02c5af8&gt;] class_attr_store+0x18/0x24
&gt; [   85.007293]        [&lt;c0169990&gt;] sysfs_write_file+0x100/0x184
&gt; [   85.018981]        [&lt;c0109d48&gt;] vfs_write+0xb4/0x148
&gt; [   85.018981]        [&lt;c0109fd0&gt;] sys_write+0x40/0x70
&gt; [   85.018981]        [&lt;c0013cc0&gt;] ret_fast_syscall+0x0/0x3c
&gt; [   85.035003]
&gt; [   85.035003] -&gt; #0 (sysfs_lock){+.+.+.}:
&gt; [   85.035003]        [&lt;c008f54c&gt;] check_prev_add+0x680/0x698
&gt; [   85.035003]        [&lt;c008f640&gt;] check_prevs_add+0xdc/0x150
&gt; [   85.052093]        [&lt;c008fc18&gt;] validate_chain.clone.24+0x564/0x694
&gt; [   85.052093]        [&lt;c0090cdc&gt;] __lock_acquire+0x49c/0x980
&gt; [   85.052093]        [&lt;c0091838&gt;] lock_acquire+0x98/0x100
&gt; [   85.069885]        [&lt;c047e280&gt;] mutex_lock_nested+0x3c/0x2f4
&gt; [   85.069885]        [&lt;c0275358&gt;] gpio_value_store+0x24/0xcc
&gt; [   85.069885]        [&lt;c02c18dc&gt;] dev_attr_store+0x18/0x24
&gt; [   85.087158]        [&lt;c0169990&gt;] sysfs_write_file+0x100/0x184
&gt; [   85.087158]        [&lt;c0109d48&gt;] vfs_write+0xb4/0x148
&gt; [   85.098297]        [&lt;c0109fd0&gt;] sys_write+0x40/0x70
&gt; [   85.098297]        [&lt;c0013cc0&gt;] ret_fast_syscall+0x0/0x3c
&gt; [   85.109069]
&gt; [   85.109069] other info that might help us debug this:
&gt; [   85.109069]
&gt; [   85.117462]  Possible unsafe locking scenario:
&gt; [   85.117462]
&gt; [   85.117462]        CPU0                    CPU1
&gt; [   85.128417]        ----                    ----
&gt; [   85.128417]   lock(s_active#22);
&gt; [   85.128417]                                lock(sysfs_lock);
&gt; [   85.128417]                                lock(s_active#22);
&gt; [   85.142486]   lock(sysfs_lock);
&gt; [   85.151794]
&gt; [   85.151794]  *** DEADLOCK ***
&gt; [   85.151794]
&gt; [   85.151794] 2 locks held by bash/949:
&gt; [   85.158020]  #0:  (&amp;buffer-&gt;mutex){+.+.+.}, at: [&lt;c01698b8&gt;] sysfs_write_file+0x28/0x184
&gt; [   85.170349]  #1:  (s_active#22){++++.+}, at: [&lt;c016996c&gt;] sysfs_write_file+0xdc/0x184
&gt; [   85.170349]
&gt; [   85.178588] stack backtrace:
&gt; [   85.178588] [&lt;c001b824&gt;] (unwind_backtrace+0x0/0xf0) from [&lt;c008de64&gt;] (print_circular_bug+0x100/0x114)
&gt; [   85.193023] [&lt;c008de64&gt;] (print_circular_bug+0x100/0x114) from [&lt;c008f54c&gt;] (check_prev_add+0x680/0x698)
&gt; [   85.193023] [&lt;c008f54c&gt;] (check_prev_add+0x680/0x698) from [&lt;c008f640&gt;] (check_prevs_add+0xdc/0x150)
&gt; [   85.212524] [&lt;c008f640&gt;] (check_prevs_add+0xdc/0x150) from [&lt;c008fc18&gt;] (validate_chain.clone.24+0x564/0x694)
&gt; [   85.212524] [&lt;c008fc18&gt;] (validate_chain.clone.24+0x564/0x694) from [&lt;c0090cdc&gt;] (__lock_acquire+0x49c/0x980)
&gt; [   85.233306] [&lt;c0090cdc&gt;] (__lock_acquire+0x49c/0x980) from [&lt;c0091838&gt;] (lock_acquire+0x98/0x100)
&gt; [   85.233306] [&lt;c0091838&gt;] (lock_acquire+0x98/0x100) from [&lt;c047e280&gt;] (mutex_lock_nested+0x3c/0x2f4)
&gt; [   85.242614] [&lt;c047e280&gt;] (mutex_lock_nested+0x3c/0x2f4) from [&lt;c0275358&gt;] (gpio_value_store+0x24/0xcc)
&gt; [   85.261840] [&lt;c0275358&gt;] (gpio_value_store+0x24/0xcc) from [&lt;c02c18dc&gt;] (dev_attr_store+0x18/0x24)
&gt; [   85.261840] [&lt;c02c18dc&gt;] (dev_attr_store+0x18/0x24) from [&lt;c0169990&gt;] (sysfs_write_file+0x100/0x184)
&gt; [   85.271240] [&lt;c0169990&gt;] (sysfs_write_file+0x100/0x184) from [&lt;c0109d48&gt;] (vfs_write+0xb4/0x148)
&gt; [   85.290008] [&lt;c0109d48&gt;] (vfs_write+0xb4/0x148) from [&lt;c0109fd0&gt;] (sys_write+0x40/0x70)
&gt; [   85.298400] [&lt;c0109fd0&gt;] (sys_write+0x40/0x70) from [&lt;c0013cc0&gt;] (ret_fast_syscall+0x0/0x3c)
&gt; -bash: echo: write error: Operation not permitted
&gt;
&gt; the way to trigger is:
&gt;
&gt; root@legolas:~# cd /sys/class/gpio/
&gt; root@legolas:/sys/class/gpio# echo 2 &gt; export
&gt; root@legolas:/sys/class/gpio# echo 2 &gt; unexport
&gt; root@legolas:/sys/class/gpio# echo 2 &gt; export
&gt; root@legolas:/sys/class/gpio# cd gpio2/
&gt; root@legolas:/sys/class/gpio/gpio2# echo 1 &gt; value

Looks 'sysfs_lock' needn't to be held for unregister, so the patch below may
fix the problem.

Acked-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Grant Likely &lt;grant.likely@secretlab.ca&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 864533ceb6db336dead389577c102a8b792a121a upstream.

Hi,

On Wed, Feb 8, 2012 at 8:41 PM, Felipe Balbi &lt;balbi@ti.com&gt; wrote:
&gt; Hi guys,
&gt;
&gt; I have just triggered the folllowing:
&gt;
&gt; [   84.860321] ======================================================
&gt; [   84.860321] [ INFO: possible circular locking dependency detected ]
&gt; [   84.860321] 3.3.0-rc2-00026-ge4e8a39 #474 Not tainted
&gt; [   84.860321] -------------------------------------------------------
&gt; [   84.860321] bash/949 is trying to acquire lock:
&gt; [   84.860321]  (sysfs_lock){+.+.+.}, at: [&lt;c0275358&gt;] gpio_value_store+0x24/0xcc
&gt; [   84.860321]
&gt; [   84.860321] but task is already holding lock:
&gt; [   84.860321]  (s_active#22){++++.+}, at: [&lt;c016996c&gt;] sysfs_write_file+0xdc/0x184
&gt; [   84.911468]
&gt; [   84.911468] which lock already depends on the new lock.
&gt; [   84.911468]
&gt; [   84.920043]
&gt; [   84.920043] the existing dependency chain (in reverse order) is:
&gt; [   84.920043]
&gt; [   84.927886] -&gt; #1 (s_active#22){++++.+}:
&gt; [   84.927886]        [&lt;c008f640&gt;] check_prevs_add+0xdc/0x150
&gt; [   84.927886]        [&lt;c008fc18&gt;] validate_chain.clone.24+0x564/0x694
&gt; [   84.927886]        [&lt;c0090cdc&gt;] __lock_acquire+0x49c/0x980
&gt; [   84.951660]        [&lt;c0091838&gt;] lock_acquire+0x98/0x100
&gt; [   84.951660]        [&lt;c016a8e8&gt;] sysfs_deactivate+0xb0/0x100
&gt; [   84.962982]        [&lt;c016b1b4&gt;] sysfs_addrm_finish+0x2c/0x6c
&gt; [   84.962982]        [&lt;c016b8bc&gt;] sysfs_remove_dir+0x84/0x98
&gt; [   84.962982]        [&lt;c02590d8&gt;] kobject_del+0x10/0x78
&gt; [   84.974670]        [&lt;c02c29e8&gt;] device_del+0x140/0x170
&gt; [   84.974670]        [&lt;c02c2a24&gt;] device_unregister+0xc/0x18
&gt; [   84.985382]        [&lt;c0276894&gt;] gpio_unexport+0xbc/0xdc
&gt; [   84.985382]        [&lt;c02768c8&gt;] gpio_free+0x14/0xfc
&gt; [   85.001708]        [&lt;c0276a28&gt;] unexport_store+0x78/0x8c
&gt; [   85.001708]        [&lt;c02c5af8&gt;] class_attr_store+0x18/0x24
&gt; [   85.007293]        [&lt;c0169990&gt;] sysfs_write_file+0x100/0x184
&gt; [   85.018981]        [&lt;c0109d48&gt;] vfs_write+0xb4/0x148
&gt; [   85.018981]        [&lt;c0109fd0&gt;] sys_write+0x40/0x70
&gt; [   85.018981]        [&lt;c0013cc0&gt;] ret_fast_syscall+0x0/0x3c
&gt; [   85.035003]
&gt; [   85.035003] -&gt; #0 (sysfs_lock){+.+.+.}:
&gt; [   85.035003]        [&lt;c008f54c&gt;] check_prev_add+0x680/0x698
&gt; [   85.035003]        [&lt;c008f640&gt;] check_prevs_add+0xdc/0x150
&gt; [   85.052093]        [&lt;c008fc18&gt;] validate_chain.clone.24+0x564/0x694
&gt; [   85.052093]        [&lt;c0090cdc&gt;] __lock_acquire+0x49c/0x980
&gt; [   85.052093]        [&lt;c0091838&gt;] lock_acquire+0x98/0x100
&gt; [   85.069885]        [&lt;c047e280&gt;] mutex_lock_nested+0x3c/0x2f4
&gt; [   85.069885]        [&lt;c0275358&gt;] gpio_value_store+0x24/0xcc
&gt; [   85.069885]        [&lt;c02c18dc&gt;] dev_attr_store+0x18/0x24
&gt; [   85.087158]        [&lt;c0169990&gt;] sysfs_write_file+0x100/0x184
&gt; [   85.087158]        [&lt;c0109d48&gt;] vfs_write+0xb4/0x148
&gt; [   85.098297]        [&lt;c0109fd0&gt;] sys_write+0x40/0x70
&gt; [   85.098297]        [&lt;c0013cc0&gt;] ret_fast_syscall+0x0/0x3c
&gt; [   85.109069]
&gt; [   85.109069] other info that might help us debug this:
&gt; [   85.109069]
&gt; [   85.117462]  Possible unsafe locking scenario:
&gt; [   85.117462]
&gt; [   85.117462]        CPU0                    CPU1
&gt; [   85.128417]        ----                    ----
&gt; [   85.128417]   lock(s_active#22);
&gt; [   85.128417]                                lock(sysfs_lock);
&gt; [   85.128417]                                lock(s_active#22);
&gt; [   85.142486]   lock(sysfs_lock);
&gt; [   85.151794]
&gt; [   85.151794]  *** DEADLOCK ***
&gt; [   85.151794]
&gt; [   85.151794] 2 locks held by bash/949:
&gt; [   85.158020]  #0:  (&amp;buffer-&gt;mutex){+.+.+.}, at: [&lt;c01698b8&gt;] sysfs_write_file+0x28/0x184
&gt; [   85.170349]  #1:  (s_active#22){++++.+}, at: [&lt;c016996c&gt;] sysfs_write_file+0xdc/0x184
&gt; [   85.170349]
&gt; [   85.178588] stack backtrace:
&gt; [   85.178588] [&lt;c001b824&gt;] (unwind_backtrace+0x0/0xf0) from [&lt;c008de64&gt;] (print_circular_bug+0x100/0x114)
&gt; [   85.193023] [&lt;c008de64&gt;] (print_circular_bug+0x100/0x114) from [&lt;c008f54c&gt;] (check_prev_add+0x680/0x698)
&gt; [   85.193023] [&lt;c008f54c&gt;] (check_prev_add+0x680/0x698) from [&lt;c008f640&gt;] (check_prevs_add+0xdc/0x150)
&gt; [   85.212524] [&lt;c008f640&gt;] (check_prevs_add+0xdc/0x150) from [&lt;c008fc18&gt;] (validate_chain.clone.24+0x564/0x694)
&gt; [   85.212524] [&lt;c008fc18&gt;] (validate_chain.clone.24+0x564/0x694) from [&lt;c0090cdc&gt;] (__lock_acquire+0x49c/0x980)
&gt; [   85.233306] [&lt;c0090cdc&gt;] (__lock_acquire+0x49c/0x980) from [&lt;c0091838&gt;] (lock_acquire+0x98/0x100)
&gt; [   85.233306] [&lt;c0091838&gt;] (lock_acquire+0x98/0x100) from [&lt;c047e280&gt;] (mutex_lock_nested+0x3c/0x2f4)
&gt; [   85.242614] [&lt;c047e280&gt;] (mutex_lock_nested+0x3c/0x2f4) from [&lt;c0275358&gt;] (gpio_value_store+0x24/0xcc)
&gt; [   85.261840] [&lt;c0275358&gt;] (gpio_value_store+0x24/0xcc) from [&lt;c02c18dc&gt;] (dev_attr_store+0x18/0x24)
&gt; [   85.261840] [&lt;c02c18dc&gt;] (dev_attr_store+0x18/0x24) from [&lt;c0169990&gt;] (sysfs_write_file+0x100/0x184)
&gt; [   85.271240] [&lt;c0169990&gt;] (sysfs_write_file+0x100/0x184) from [&lt;c0109d48&gt;] (vfs_write+0xb4/0x148)
&gt; [   85.290008] [&lt;c0109d48&gt;] (vfs_write+0xb4/0x148) from [&lt;c0109fd0&gt;] (sys_write+0x40/0x70)
&gt; [   85.298400] [&lt;c0109fd0&gt;] (sys_write+0x40/0x70) from [&lt;c0013cc0&gt;] (ret_fast_syscall+0x0/0x3c)
&gt; -bash: echo: write error: Operation not permitted
&gt;
&gt; the way to trigger is:
&gt;
&gt; root@legolas:~# cd /sys/class/gpio/
&gt; root@legolas:/sys/class/gpio# echo 2 &gt; export
&gt; root@legolas:/sys/class/gpio# echo 2 &gt; unexport
&gt; root@legolas:/sys/class/gpio# echo 2 &gt; export
&gt; root@legolas:/sys/class/gpio# cd gpio2/
&gt; root@legolas:/sys/class/gpio/gpio2# echo 1 &gt; value

Looks 'sysfs_lock' needn't to be held for unregister, so the patch below may
fix the problem.

Acked-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Grant Likely &lt;grant.likely@secretlab.ca&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpiolib: Refactor gpio_export</title>
<updated>2015-02-20T00:49:37+00:00</updated>
<author>
<name>Ryan Mallon</name>
<email>rmallon@gmail.com</email>
</author>
<published>2012-10-22T00:39:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=0bebb361e467ab9d9a790523fede2f32272444d9'/>
<id>0bebb361e467ab9d9a790523fede2f32272444d9</id>
<content type='text'>
commit fc4e2514995d9cd7f3e1a67098ce65d72acf8ec7 upstream.

The gpio_export function uses nested if statements and the status
variable to handle the failure cases. This makes the function logic
difficult to follow. Refactor the code to abort immediately on failure
using goto. This makes the code slightly longer, but significantly
reduces the nesting and number of split lines and makes the code easier
to read.

Signed-off-by: Ryan Mallon &lt;rmallon@gmail.com&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit fc4e2514995d9cd7f3e1a67098ce65d72acf8ec7 upstream.

The gpio_export function uses nested if statements and the status
variable to handle the failure cases. This makes the function logic
difficult to follow. Refactor the code to abort immediately on failure
using goto. This makes the code slightly longer, but significantly
reduces the nesting and number of split lines and makes the code easier
to read.

Signed-off-by: Ryan Mallon &lt;rmallon@gmail.com&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>gpio: sysfs: fix gpio-chip device-attribute leak</title>
<updated>2015-02-20T00:49:37+00:00</updated>
<author>
<name>Johan Hovold</name>
<email>johan@kernel.org</email>
</author>
<published>2015-01-13T12:00:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=6f7c3121580136cfcdfb07cf9d3f6f81d78d39dc'/>
<id>6f7c3121580136cfcdfb07cf9d3f6f81d78d39dc</id>
<content type='text'>
commit 121b6a79955a3a3fd7bbb9b8cb88d5b9dad6283d upstream.

The gpio-chip device attributes were never destroyed when the device was
removed.

Fix by using device_create_with_groups() to create the device attributes
of the chip class device.

Note that this also fixes the attribute-creation race with userspace.

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 121b6a79955a3a3fd7bbb9b8cb88d5b9dad6283d upstream.

The gpio-chip device attributes were never destroyed when the device was
removed.

Fix by using device_create_with_groups() to create the device attributes
of the chip class device.

Note that this also fixes the attribute-creation race with userspace.

Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Linus Walleij &lt;linus.walleij@linaro.org&gt;
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
</pre>
</div>
</content>
</entry>
</feed>
