<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/spi/spi.c, branch linux-4.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2021-06-03T06:22:06Z</updated>
<entry>
<title>spi: Fix use-after-free with devm_spi_alloc_*</title>
<updated>2021-06-03T06:22:06Z</updated>
<author>
<name>William A. Kennington III</name>
</author>
<published>2021-04-07T09:55:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=62bb2c7f2411a0045c24831f11ecacfc35610815'/>
<id>urn:sha1:62bb2c7f2411a0045c24831f11ecacfc35610815</id>
<content type='text'>
commit 794aaf01444d4e765e2b067cba01cc69c1c68ed9 upstream.

We can't rely on the contents of the devres list during
spi_unregister_controller(), as the list is already torn down at the
time we perform devres_find() for devm_spi_release_controller. This
causes devices registered with devm_spi_alloc_{master,slave}() to be
mistakenly identified as legacy, non-devm managed devices and have their
reference counters decremented below 0.

------------[ cut here ]------------
WARNING: CPU: 1 PID: 660 at lib/refcount.c:28 refcount_warn_saturate+0x108/0x174
[&lt;b0396f04&gt;] (refcount_warn_saturate) from [&lt;b03c56a4&gt;] (kobject_put+0x90/0x98)
[&lt;b03c5614&gt;] (kobject_put) from [&lt;b0447b4c&gt;] (put_device+0x20/0x24)
 r4:b6700140
[&lt;b0447b2c&gt;] (put_device) from [&lt;b07515e8&gt;] (devm_spi_release_controller+0x3c/0x40)
[&lt;b07515ac&gt;] (devm_spi_release_controller) from [&lt;b045343c&gt;] (release_nodes+0x84/0xc4)
 r5:b6700180 r4:b6700100
[&lt;b04533b8&gt;] (release_nodes) from [&lt;b0454160&gt;] (devres_release_all+0x5c/0x60)
 r8:b1638c54 r7:b117ad94 r6:b1638c10 r5:b117ad94 r4:b163dc10
[&lt;b0454104&gt;] (devres_release_all) from [&lt;b044e41c&gt;] (__device_release_driver+0x144/0x1ec)
 r5:b117ad94 r4:b163dc10
[&lt;b044e2d8&gt;] (__device_release_driver) from [&lt;b044f70c&gt;] (device_driver_detach+0x84/0xa0)
 r9:00000000 r8:00000000 r7:b117ad94 r6:b163dc54 r5:b1638c10 r4:b163dc10
[&lt;b044f688&gt;] (device_driver_detach) from [&lt;b044d274&gt;] (unbind_store+0xe4/0xf8)

Instead, determine the devm allocation state as a flag on the
controller which is guaranteed to be stable during cleanup.

Fixes: 5e844cc37a5c ("spi: Introduce device-managed SPI controller allocation")
Signed-off-by: William A. Kennington III &lt;wak@google.com&gt;
Link: https://lore.kernel.org/r/20210407095527.2771582-1-wak@google.com
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
[lukas: backport to v4.4.270]
Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>spi: Prevent adding devices below an unregistering controller</title>
<updated>2020-12-29T12:42:31Z</updated>
<author>
<name>Lukas Wunner</name>
</author>
<published>2020-08-03T11:09:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=56ea79388d144a868cffa1b90538e721d7c3cb4e'/>
<id>urn:sha1:56ea79388d144a868cffa1b90538e721d7c3cb4e</id>
<content type='text'>
commit ddf75be47ca748f8b12d28ac64d624354fddf189 upstream

CONFIG_OF_DYNAMIC and CONFIG_ACPI allow adding SPI devices at runtime
using a DeviceTree overlay or DSDT patch.  CONFIG_SPI_SLAVE allows the
same via sysfs.

But there are no precautions to prevent adding a device below a
controller that's being removed.  Such a device is unusable and may not
even be able to unbind cleanly as it becomes inaccessible once the
controller has been torn down.  E.g. it is then impossible to quiesce
the device's interrupt.

of_spi_notify() and acpi_spi_notify() do hold a ref on the controller,
but otherwise run lockless against spi_unregister_controller().

Fix by holding the spi_add_lock in spi_unregister_controller() and
bailing out of spi_add_device() if the controller has been unregistered
concurrently.

Fixes: ce79d54ae447 ("spi/of: Add OF notifier handler")
Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Cc: stable@vger.kernel.org # v3.19+
Cc: Geert Uytterhoeven &lt;geert+renesas@glider.be&gt;
Cc: Octavian Purdila &lt;octavian.purdila@intel.com&gt;
Cc: Pantelis Antoniou &lt;pantelis.antoniou@konsulko.com&gt;
Link: https://lore.kernel.org/r/a8c3205088a969dc8410eec1eba9aface60f36af.1596451035.git.lukas@wunner.de
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
[sudip: adjust context]
Signed-off-by: Sudip Mukherjee &lt;sudipm.mukherjee@gmail.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>spi: Introduce device-managed SPI controller allocation</title>
<updated>2020-12-11T12:36:45Z</updated>
<author>
<name>Lukas Wunner</name>
</author>
<published>2020-12-06T12:53:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a4add022c1552b0d51a0b89a4781919d6ebac4f9'/>
<id>urn:sha1:a4add022c1552b0d51a0b89a4781919d6ebac4f9</id>
<content type='text'>
[ Upstream commit 5e844cc37a5cbaa460e68f9a989d321d63088a89 ]

SPI driver probing currently comprises two steps, whereas removal
comprises only one step:

    spi_alloc_master()
    spi_register_master()

    spi_unregister_master()

That's because spi_unregister_master() calls device_unregister()
instead of device_del(), thereby releasing the reference on the
spi_master which was obtained by spi_alloc_master().

An SPI driver's private data is contained in the same memory allocation
as the spi_master struct.  Thus, once spi_unregister_master() has been
called, the private data is inaccessible.  But some drivers need to
access it after spi_unregister_master() to perform further teardown
steps.

Introduce devm_spi_alloc_master(), which releases a reference on the
spi_master struct only after the driver has unbound, thereby keeping the
memory allocation accessible.  Change spi_unregister_master() to not
release a reference if the spi_master was allocated by the new devm
function.

The present commit is small enough to be backportable to stable.
It allows fixing drivers which use the private data in their -&gt;remove()
hook after it's been freed.  It also allows fixing drivers which neglect
to release a reference on the spi_master in the probe error path.

Long-term, most SPI drivers shall be moved over to the devm function
introduced herein.  The few that can't shall be changed in a treewide
commit to explicitly release the last reference on the master.
That commit shall amend spi_unregister_master() to no longer release
a reference, thereby completing the migration.

As a result, the behaviour will be less surprising and more consistent
with subsystems such as IIO, which also includes the private data in the
allocation of the generic iio_dev struct, but calls device_del() in
iio_device_unregister().

Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Link: https://lore.kernel.org/r/272bae2ef08abd21388c98e23729886663d19192.1605121038.git.lukas@wunner.de
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>spi: unbinding slave before calling spi_destroy_queue</title>
<updated>2020-10-17T09:03:31Z</updated>
<author>
<name>yangerkun</name>
</author>
<published>2020-10-15T14:38:34Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=71ad780260089a19b8563096d64fd7588ccb0a0d'/>
<id>urn:sha1:71ad780260089a19b8563096d64fd7588ccb0a0d</id>
<content type='text'>
We make a mistake while backport 'commit 84855678add8 ("spi: Fix
controller unregister order")'. What we should do is call __unreigster
for each device before spi_destroy_queue. This problem exist in
linux-4.4.y/linux-4.9.y.

Signed-off-by: yangerkun &lt;yangerkun@huawei.com&gt;
</content>
</entry>
<entry>
<title>spi: Fix controller unregister order</title>
<updated>2020-06-20T08:23:17Z</updated>
<author>
<name>Lukas Wunner</name>
</author>
<published>2020-05-15T15:58:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b4c6230bb0babe04d135d5c2d7343b7fb7ee9e4b'/>
<id>urn:sha1:b4c6230bb0babe04d135d5c2d7343b7fb7ee9e4b</id>
<content type='text'>
[ Upstream commit 84855678add8aba927faf76bc2f130a40f94b6f7 ]

When an SPI controller unregisters, it unbinds all its slave devices.
For this, their drivers may need to access the SPI bus, e.g. to quiesce
interrupts.

However since commit ffbbdd21329f ("spi: create a message queueing
infrastructure"), spi_destroy_queue() is executed before unbinding the
slaves.  It sets ctlr-&gt;running = false, thereby preventing SPI bus
access and causing unbinding of slave devices to fail.

Fix by unbinding slaves before calling spi_destroy_queue().

Fixes: ffbbdd21329f ("spi: create a message queueing infrastructure")
Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Cc: stable@vger.kernel.org # v3.4+
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Link: https://lore.kernel.org/r/8aaf9d44c153fe233b17bc2dec4eb679898d7e7b.1589557526.git.lukas@wunner.de
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>spi: No need to assign dummy value in spi_unregister_controller()</title>
<updated>2020-06-20T08:23:17Z</updated>
<author>
<name>Andy Shevchenko</name>
</author>
<published>2019-06-15T17:41:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fccbb6523d8757d230ed27194906d4e46ae9a7d5'/>
<id>urn:sha1:fccbb6523d8757d230ed27194906d4e46ae9a7d5</id>
<content type='text'>
[ Upstream commit ebc37af5e0a134355ea2b62ed4141458bdbd5389 ]

The device_for_each_child() doesn't require the returned value to be checked.
Thus, drop the dummy variable completely and have no warning anymore:

drivers/spi/spi.c: In function ‘spi_unregister_controller’:
drivers/spi/spi.c:2480:6: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]
  int dummy;
      ^~~~~

Signed-off-by: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>spi: Fix zero length xfer bug</title>
<updated>2019-06-11T10:24:06Z</updated>
<author>
<name>Chris Lesiak</name>
</author>
<published>2019-03-07T20:39:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0984cb76d2942dd0bf6da77799b931802d8af678'/>
<id>urn:sha1:0984cb76d2942dd0bf6da77799b931802d8af678</id>
<content type='text'>
[ Upstream commit 5442dcaa0d90fc376bdfc179a018931a8f43dea4 ]

This fixes a bug for messages containing both zero length and
unidirectional xfers.

The function spi_map_msg will allocate dummy tx and/or rx buffers
for use with unidirectional transfers when the hardware can only do
a bidirectional transfer.  That dummy buffer will be used in place
of a NULL buffer even when the xfer length is 0.

Then in the function __spi_map_msg, if he hardware can dma,
the zero length xfer will have spi_map_buf called on the dummy
buffer.

Eventually, __sg_alloc_table is called and returns -EINVAL
because nents == 0.

This fix prevents the error by not using the dummy buffer when
the xfer length is zero.

Signed-off-by: Chris Lesiak &lt;chris.lesiak@licor.com&gt;
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>spi: Fix scatterlist elements size in spi_map_buf</title>
<updated>2018-07-03T09:21:35Z</updated>
<author>
<name>Maxime Chevallier</name>
</author>
<published>2018-03-02T14:55:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9b46e5e9a300a4a01d422e9d21f694b54d6c2f5f'/>
<id>urn:sha1:9b46e5e9a300a4a01d422e9d21f694b54d6c2f5f</id>
<content type='text'>
commit ce99319a182fe766be67f96338386f3ec73e321c upstream.

When SPI transfers can be offloaded using DMA, the SPI core need to
build a scatterlist to make sure that the buffer to be transferred is
dma-able.

This patch fixes the scatterlist entry size computation in the case
where the maximum acceptable scatterlist entry supported by the DMA
controller is less than PAGE_SIZE, when the buffer is vmalloced.

For each entry, the actual size is given by the minimum between the
desc_len (which is the max buffer size supported by the DMA controller)
and the remaining buffer length until we cross a page boundary.

Fixes: 65598c13fd66 ("spi: Fix per-page mapping of unaligned vmalloc-ed buffer")
Signed-off-by: Maxime Chevallier &lt;maxime.chevallier@bootlin.com&gt;
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Sudip Mukherjee &lt;sudipm.mukherjee@gmail.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Merge remote-tracking branch 'spi/fix/core' into spi-linus</title>
<updated>2015-12-16T13:28:31Z</updated>
<author>
<name>Mark Brown</name>
</author>
<published>2015-12-16T13:28:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9ce5db27f4a959ca58d768c5c8e5c98a47361e67'/>
<id>urn:sha1:9ce5db27f4a959ca58d768c5c8e5c98a47361e67</id>
<content type='text'>
</content>
</entry>
<entry>
<title>spi: fix parent-device reference leak</title>
<updated>2015-12-16T12:28:25Z</updated>
<author>
<name>Johan Hovold</name>
</author>
<published>2015-12-14T15:16:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=157f38f993919b648187ba341bfb05d0e91ad2f6'/>
<id>urn:sha1:157f38f993919b648187ba341bfb05d0e91ad2f6</id>
<content type='text'>
Fix parent-device reference leak due to SPI-core taking an unnecessary
reference to the parent when allocating the master structure, a
reference that was never released.

Note that driver core takes its own reference to the parent when the
master device is registered.

Fixes: 49dce689ad4e ("spi doesn't need class_device")
Signed-off-by: Johan Hovold &lt;johan@kernel.org&gt;
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Cc: stable@vger.kernel.org
</content>
</entry>
</feed>
