Commit Graph

613862 Commits

Author SHA1 Message Date
Heiner Kallweit
3e8809ffb6 UPSTREAM: [media] media: rc: remove unneeded mutex in rc_register_device
Access to dev->initialized is atomic and dev->initialized isn't
accessed in any other code protected by this mutex.
Therefore we don't need to get the mutex here.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 36ac2f3259)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Mauro Carvalho Chehab
21c5445593 UPSTREAM: [media] rc-core: allow calling rc_open with device not initialized
The device initialization completes only after calling
input_register_device(). However, rc_open() can be called while
the device is being registered by the input/evdev core. So, we
can't expect that rc_dev->initialized to be true.

Change the logic to don't require initialized == true at rc_open
and change the type of initialized to be atomic.

this way, we can check for it earlier where it is really needed,
without needing to lock the mutex just for testing it.

Tested with nuvoton_cir driver on a NUC5i7RYB with CIR integrated on it.

Reported-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 078600f514)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Mauro Carvalho Chehab
6e2e23c1f2 UPSTREAM: [media] lirc_dev: avoid double mutex unlock
We can only unlock if mutex_lock() succeeds.

Fixes the following warning:
	drivers/media/rc/lirc_dev.c:535 lirc_dev_fop_close() error: double unlock 'mutex:&lirc_dev_lock'

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit b64e10f3df)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Mauro Carvalho Chehab
aa598b0126 UPSTREAM: [media] rc-core: don't lock device at rc_register_device()
The mutex lock at rc_register_device() was added by commit 08aeb7c9a4
("[media] rc: add locking to fix register/show race").

It is meant to avoid race issues when trying to open a sysfs file while
the RC register didn't complete.

Adding a lock there causes troubles, as detected by the Kernel lock
debug instrumentation at the Kernel:

    ======================================================
    [ INFO: possible circular locking dependency detected ]
    4.5.0-rc3+ #46 Not tainted
    -------------------------------------------------------
    systemd-udevd/2681 is trying to acquire lock:
     (s_active#171){++++.+}, at: [<ffffffff8171a115>] kernfs_remove_by_name_ns+0x45/0xa0

    but task is already holding lock:
     (&dev->lock){+.+.+.}, at: [<ffffffffa0724def>] rc_register_device+0xb2f/0x1450 [rc_core]

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #1 (&dev->lock){+.+.+.}:
           [<ffffffff8124817d>] lock_acquire+0x13d/0x320
           [<ffffffff822de966>] mutex_lock_nested+0xb6/0x860
           [<ffffffffa0721f2b>] show_protocols+0x3b/0x3f0 [rc_core]
           [<ffffffff81cdaba5>] dev_attr_show+0x45/0xc0
           [<ffffffff8171f1b3>] sysfs_kf_seq_show+0x203/0x3c0
           [<ffffffff8171a6a1>] kernfs_seq_show+0x121/0x1b0
           [<ffffffff81617c71>] seq_read+0x2f1/0x1160
           [<ffffffff8171c911>] kernfs_fop_read+0x321/0x460
           [<ffffffff815abc20>] __vfs_read+0xe0/0x3d0
           [<ffffffff815ae90e>] vfs_read+0xde/0x2d0
           [<ffffffff815b1d01>] SyS_read+0x111/0x230
           [<ffffffff822e8636>] entry_SYSCALL_64_fastpath+0x16/0x76

    -> #0 (s_active#171){++++.+}:
           [<ffffffff81244f24>] __lock_acquire+0x4304/0x5990
           [<ffffffff8124817d>] lock_acquire+0x13d/0x320
           [<ffffffff81717d3a>] __kernfs_remove+0x58a/0x810
           [<ffffffff8171a115>] kernfs_remove_by_name_ns+0x45/0xa0
           [<ffffffff81721592>] remove_files.isra.0+0x72/0x190
           [<ffffffff8172174b>] sysfs_remove_group+0x9b/0x150
           [<ffffffff81721854>] sysfs_remove_groups+0x54/0xa0
           [<ffffffff81cd97d0>] device_remove_attrs+0xb0/0x140
           [<ffffffff81cdb27c>] device_del+0x38c/0x6b0
           [<ffffffffa0724b8b>] rc_register_device+0x8cb/0x1450 [rc_core]
           [<ffffffffa1326a7b>] dvb_usb_remote_init+0x66b/0x14d0 [dvb_usb]
           [<ffffffffa1321c81>] dvb_usb_device_init+0xf21/0x1860 [dvb_usb]
           [<ffffffffa13517dc>] dib0700_probe+0x14c/0x410 [dvb_usb_dib0700]
           [<ffffffff81dbb1dd>] usb_probe_interface+0x45d/0x940
           [<ffffffff81ce7e7a>] driver_probe_device+0x21a/0xc30
           [<ffffffff81ce89b1>] __driver_attach+0x121/0x160
           [<ffffffff81ce21bf>] bus_for_each_dev+0x11f/0x1a0
           [<ffffffff81ce6cdd>] driver_attach+0x3d/0x50
           [<ffffffff81ce5df9>] bus_add_driver+0x4c9/0x770
           [<ffffffff81cea39c>] driver_register+0x18c/0x3b0
           [<ffffffff81db6e98>] usb_register_driver+0x1f8/0x440
           [<ffffffffa074001e>] dib0700_driver_init+0x1e/0x1000 [dvb_usb_dib0700]
           [<ffffffff810021b1>] do_one_initcall+0x141/0x300
           [<ffffffff8144d8eb>] do_init_module+0x1d0/0x5ad
           [<ffffffff812f27b6>] load_module+0x6666/0x9ba0
           [<ffffffff812f5fe8>] SyS_finit_module+0x108/0x130
           [<ffffffff822e8636>] entry_SYSCALL_64_fastpath+0x16/0x76

    other info that might help us debug this:

     Possible unsafe locking scenario:

           CPU0                    CPU1
           ----                    ----
      lock(&dev->lock);
                                   lock(s_active#171);
                                   lock(&dev->lock);
      lock(s_active#171);

     *** DEADLOCK ***

    3 locks held by systemd-udevd/2681:
     #0:  (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
     #1:  (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
     #2:  (&dev->lock){+.+.+.}, at: [<ffffffffa0724def>] rc_register_device+0xb2f/0x1450 [rc_core]

In this specific case, some error happened during device init,
causing IR to be disabled.

Let's fix it by adding a var that will tell when the device is
initialized. Any calls before that will return a -EINVAL.

That should prevent the race issues.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit c73bbaa4ec)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
df04cf515c UPSTREAM: [media] media: rc: raw: improve FIFO handling
The FIFO is used for ir_raw_event records, however for some historic
reason the FIFO is used on a per byte basis. IMHO this adds unneeded
complexity. Therefore set up the FIFO for ir_raw_event records.

This also allows to define the FIFO statically as part of
ir_raw_event_ctrl instead of having to allocate the FIFO dynamically.
In addition:

- When writing into the FIFO and it's full return ENOSPC instead of
  ENOMEM thus making it easier to tell between "FIFO full" and
  "Dynamic memory allocation failed" when the error is propagated to
  a higher level.
  Also add an error message.

- When reading from the FIFO check whether it's empty.
  This is not strictly needed here but kfifo_out is annotated
  "must check" anyway.

Successfully tested it with the nuvoton-cir driver.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 464254e5db)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Mauro Carvalho Chehab
30419410be UPSTREAM: [media] ir-lirc-codec.c: don't leak lirc->drv-rbuf
As reported by kmemleak:

	unreferenced object 0xffff8802adae0ba0 (size 192):
	  comm "modprobe", pid 3024, jiffies 4296503588 (age 324.368s)
	  hex dump (first 32 bytes):
	    00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00  .....N..........
	    ff ff ff ff ff ff ff ff c0 48 25 a0 ff ff ff ff  .........H%.....
	  backtrace:
	    [<ffffffff82278c8e>] kmemleak_alloc+0x4e/0xb0
	    [<ffffffff8153c08c>] kmem_cache_alloc_trace+0x1ec/0x280
	    [<ffffffffa0250f0d>] ir_lirc_register+0x8d/0x7a0 [ir_lirc_codec]
	    [<ffffffffa07372b8>] ir_raw_event_register+0x318/0x4b0 [rc_core]
	    [<ffffffffa07351ed>] rc_register_device+0xf2d/0x1450 [rc_core]
	    [<ffffffffa13c5451>] au0828_rc_register+0x7d1/0xa10 [au0828]
	    [<ffffffffa13b0dc2>] au0828_usb_probe+0x6c2/0xcf0 [au0828]
	    [<ffffffff81d7619d>] usb_probe_interface+0x45d/0x940
	    [<ffffffff81ca7004>] driver_probe_device+0x454/0xd90
	    [<ffffffff81ca7a61>] __driver_attach+0x121/0x160
	    [<ffffffff81ca141f>] bus_for_each_dev+0x11f/0x1a0
	    [<ffffffff81ca5d4d>] driver_attach+0x3d/0x50
	    [<ffffffff81ca5039>] bus_add_driver+0x4c9/0x770
	    [<ffffffff81ca944c>] driver_register+0x18c/0x3b0
	    [<ffffffff81d71e58>] usb_register_driver+0x1f8/0x440
	    [<ffffffffa13680b7>] 0xffffffffa13680b7

	0xf3d is in ir_lirc_register (drivers/media/rc/ir-lirc-codec.c:348).
	343		drv = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
	344		if (!drv)
	345			return rc;
	346
	347		rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
	348		if (!rbuf)
	349			goto rbuf_alloc_failed;
	350
	351		rc = lirc_buffer_init(rbuf, sizeof(int), LIRCBUF_SIZE);
	352		if (rc)

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit c77adf214b)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Arnd Bergmann
227c413b76 UPSTREAM: [media] staging: media: lirc: Replace timeval with ktime_t in lirc_serial.c
'struct timeval tv' is used to get current time.
'static struct timeval lasttv' is used to get last interrupt time.

32-bit systems using 'struct timeval' will break in the year 2038,
so we have to replace that code with more appropriate types.
This patch changes the lirc_serial.c file of media: lirc to use
ktime_t.

ktime_get() is  better than using do_gettimeofday(),
because it uses the monotonic clock. ktime_sub is used
to subtract two ktime variables. The check to test time
going backwards is also removed. Intialization to static
variable is also removed. ktime_to_us() is used to convert
ktime_t to microsecond value. deltv is changed to delkt, a
ktime_t type varibale from long to assign the ktime_sub value
directly. ktime_compare is used to compare delkt with 15
seconds, which is changed to a nanosecond value by using
ktime_set().

Build tested it.

Signed-off-by: Tapasweni Pathak <tapaswenipathak@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 8459503295)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
a6bd3f29fc UPSTREAM: [media] media: rc: remove unneeded code
Now that that the decoder modules are loaded on-demand we can move
loading the lirc module to rc_register_device directly and remove
unneeded functions and comments.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
(cherry picked from commit c1500ba0b6)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
f76a8e230e UPSTREAM: [media] media: rc: improve RC_BIT_ constant definition
The RC_BIT_ constants are used in 64-bit bitmaps.
In case of > 32 RC_BIT_ constants the current code will fail
on 32-bit systems.
Therefore define the RC_BIT_ constants as unsigned long long.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit c278504d2a)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
8588c29848 UPSTREAM: [media] media: rc: move check whether a protocol is enabled to the core
Checking whether a protocol is enabled and calling the related decoder
functions should be done by the rc core, not the protocol handlers.

Properly handle lirc considering that no protocol bit is set for lirc.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit d80ca8bd71)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
2a217e3ca0 UPSTREAM: [media] media: rc: load decoder modules on-demand
Remove code for unconditional decoder module loading (except lirc).

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit acc1c3c688)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
fa3660beea UPSTREAM: [media] media: rc: constify struct proto_names
Declare struct proto_names and its member name as const.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 53df877717)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
99eb8f9a52 UPSTREAM: [media] media: rc: preparation for on-demand decoder module loading
Prepare on-demand decoder module loading by adding a module_name member
to struct proto_names and introducing the related load function.

After this patch of the series the decoder modules are still loaded
unconditionally.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 9f0bf366d7)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
e61f8a23c5 UPSTREAM: [media] media: rc: fix decoder module unloading
Currently, if a decoder module is unloadad, the respective protocol
is still shown as enabled (if it was enabled before).
Fix this by resetting the respective protocol bits if a decoder
module is unloaded.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 93cffffc18)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:58 +08:00
Heiner Kallweit
fa51e1c06b UPSTREAM: [media] media: rc-core: simplify logging in rc_register_device
Simplify the logging.

I had some doubts about using the elvis operator as it's GNU extension.
However GNU extensions are explicitely allowed and this operator is
used at several places in the kernel code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 4dc0e908a5)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:57 +08:00
Heiner Kallweit
cf55750f84 UPSTREAM: [media] media: rc: ir-sharp-decoder: add support for Denon variant of the protocol
Denon also uses the Sharp protocol, however with different check bits.

It would have been also possible to add this as a separate protocol
but this may not be worth the effort.

Successfully tested with a Denon RC-1002 remote control.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 1b0621af50)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:57 +08:00
Russell King
b0702d7766 UPSTREAM: [media] rc: allow rc modules to be loaded if rc-main is not a module
rc-main mistakenly uses #ifdef MODULE to determine whether it should
load the rc keymap modules.  This symbol is only defined if rc-main
is being built as a module itself, and bears no relation to whether
the rc keymaps are modules.

Fix this to use CONFIG_MODULES instead.

Fixes: 631493ecac ("[media] rc-core: merge rc-map.c into rc-main.c")

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit 2ff56fadd9)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:57 +08:00
Alec Leamas
ad507b0da5 UPSTREAM: [media] bz#75751: Move internal header file lirc.h to uapi/
The file include/media/lirc.h describes a public interface and
should thus be a public header. See kernel bug
https://bugzilla.kernel.org/show_bug.cgi?id=75751 which has
a manpage describing the interface + an acknowledgment that this
info belongs to uapi.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
(cherry picked from commit b7be755733)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:57 +08:00
Kees Cook
a256ba02d9 UPSTREAM: timer: Prepare to change timer callback argument type
Modern kernel callback systems pass the structure associated with a
given callback to the callback function. The timer callback remains one
of the legacy cases where an arbitrary unsigned long argument continues
to be passed as the callback argument. This has several problems:

- This bloats the timer_list structure with a normally redundant
  .data field.

- No type checking is being performed, forcing callbacks to do
  explicit type casts of the unsigned long argument into the object
  that was passed, rather than using container_of(), as done in most
  of the other callback infrastructure.

- Neighboring buffer overflows can overwrite both the .function and
  the .data field, providing attackers with a way to elevate from a buffer
  overflow into a simplistic ROP-like mechanism that allows calling
  arbitrary functions with a controlled first argument.

- For future Control Flow Integrity work, this creates a unique function
  prototype for timer callbacks, instead of allowing them to continue to
  be clustered with other void functions that take a single unsigned long
  argument.

This adds a new timer initialization API, which will ultimately replace
the existing setup_timer(), setup_{deferrable,pinned,etc}_timer() family,
named timer_setup() (to mirror hrtimer_setup(), making instances of its
use much easier to grep for).

In order to support the migration of existing timers into the new
callback arguments, timer_setup() casts its arguments to the existing
legacy types, and explicitly passes the timer pointer as the legacy
data argument. Once all setup_*timer() callers have been replaced with
timer_setup(), the casts can be removed, and the data argument can be
dropped with the timer expiration code changed to just pass the timer
to the callback directly.

Since the regular pattern of using container_of() during local variable
declaration repeats the need for the variable type declaration
to be included, this adds a helper modeled after other from_*()
helpers that wrap container_of(), named from_timer(). This helper uses
typeof(*variable), removing the type redundancy and minimizing the need
for line wraps in forthcoming conversions from "unsigned data long" to
"struct timer_list *" in the timer callbacks:

-void callback(unsigned long data)
+void callback(struct timer_list *t)
{
-   struct some_data_structure *local = (struct some_data_structure *)data;
+   struct some_data_structure *local = from_timer(local, t, timer);

Finally, in order to support the handful of timer users that perform
open-coded assignments of the .function (and .data) fields, provide
cast macros (TIMER_FUNC_TYPE and TIMER_DATA_TYPE) that can be used
temporarily. Once conversion has been completed, these can be globally
trivially removed.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20170928133817.GA113410@beast

(cherry picked from commit 686fef928b)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:57 +08:00
Logan Gunthorpe
2622ecd555 UPSTREAM: chardev: add helper function to register char devs with a struct device
Credit for this patch goes is shared with Dan Williams [1]. I've
taken things one step further to make the helper function more
useful and clean up calling code.

There's a common pattern in the kernel whereby a struct cdev is placed
in a structure along side a struct device which manages the life-cycle
of both. In the naive approach, the reference counting is broken and
the struct device can free everything before the chardev code
is entirely released.

Many developers have solved this problem by linking the internal kobjs
in this fashion:

cdev.kobj.parent = &parent_dev.kobj;

The cdev code explicitly gets and puts a reference to it's kobj parent.
So this seems like it was intended to be used this way. Dmitrty Torokhov
first put this in place in 2012 with this commit:

2f0157f char_dev: pin parent kobject

and the first instance of the fix was then done in the input subsystem
in the following commit:

4a215aa Input: fix use-after-free introduced with dynamic minor changes

Subsequently over the years, however, this issue seems to have tripped
up multiple developers independently. For example, see these commits:

0d5b7da iio: Prevent race between IIO chardev opening and IIO device
(by Lars-Peter Clausen in 2013)

ba0ef85 tpm: Fix initialization of the cdev
(by Jason Gunthorpe in 2015)

5b28dde [media] media: fix use-after-free in cdev_put() when app exits
after driver unbind
(by Shauh Khan in 2016)

This technique is similarly done in at least 15 places within the kernel
and probably should have been done so in another, at least, 5 places.
The kobj line also looks very suspect in that one would not expect
drivers to have to mess with kobject internals in this way.
Even highly experienced kernel developers can be surprised by this
code, as seen in [2].

To help alleviate this situation, and hopefully prevent future
wasted effort on this problem, this patch introduces a helper function
to register a char device along with its parent struct device.
This creates a more regular API for tying a char device to its parent
without the developer having to set members in the underlying kobject.

This patch introduce cdev_device_add and cdev_device_del which
replaces a common pattern including setting the kobj parent, calling
cdev_add and then calling device_add. It also introduces cdev_set_parent
for the few cases that set the kobject parent without using device_add.

[1] https://lkml.org/lkml/2017/2/13/700
[2] https://lkml.org/lkml/2017/2/10/370

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 233ed09d7f)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
2018-12-10 20:35:57 +08:00
William Wu
747277acfe usb: host: ehci-platform: Add basic runtime PM support
Like the runtime PM support patch of ohci-platform, we
add the same basic runtime PM for ehci-platform.

Change-Id: I84cbb15dd393e6af69b4cf6887f1628e2cba4999
Signed-off-by: William Wu <william.wu@rock-chips.com>
2018-12-10 20:09:34 +08:00
Tony Lindgren
cf15e865dd BACKPORT: usb: host: ohci-platform: Add basic runtime PM support
This is needed in preparation of adding support for omap3 and
later OHCI. The runtime PM will only do something on platforms
that implement it.

Change-Id: I497d03902648e7c4010a2de24d4cb8490887ee85
Cc: devicetree@vger.kernel.org
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Acked-by: Roger Quadros <rogerq@ti.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 0aa0b93e7a)
2018-12-10 20:09:07 +08:00
David Wu
54e977ad63 arm64: dts: rockchip: use extcon for usb2/usb3 on rk1808-evb
Change-Id: If71f47251a598e106843d83c885a658f71931d74
Signed-off-by: David Wu <david.wu@rock-chips.com>
2018-12-10 20:07:57 +08:00
David.Wu
cd59e670a8 arm64: dts: rockchip: Change the dr_mode from peripheral to otg for rk1808
Use the driver to auto switch the host/peripheral mode for rk1808,
so the dr_mode must be otg.

Change-Id: I9b05e06bacd141d5fbd00a9751f2a12a4e4385c8
Signed-off-by: David.Wu <david.wu@rock-chips.com>
2018-12-10 20:07:57 +08:00
David.Wu
833c56149e usb: dwc3: Change the dwc3 driver to dwc3-rockchip for rk1808 and rk3399pro-npu
Use the dwc3-rockchip driver to auto switch the host/peripheral dr_mode.

Change-Id: I497570fad4caaffc9da08086f2758653afb729db
Signed-off-by: David.Wu <david.wu@rock-chips.com>
2018-12-10 20:07:57 +08:00
David.Wu
98b799609e arm64: dts: rockchip: Add usbdrd3's compatible "rockchip,rk3399-dwc3" for rk3399pro-npu
We will use the dwc3-rockchip driver for rk3399pro-npu, this patch
is prepared for it.

Change-Id: I9c97002adbe9bd2fea01d8e209183f5211b3796c
Signed-off-by: David.Wu <david.wu@rock-chips.com>
2018-12-10 20:07:57 +08:00
David Wu
74aa9c38f5 arm64: dts: rockchip: Add usbdrd3's compatible "rockchip,rk3399-dwc3" for rk1808
We will use the dwc3-rockchip driver for rk1808, this patch is prepared
for it.

Change-Id: I7ca8baefd26ea6c67140b757c47e14625cfed609
Signed-off-by: David Wu <david.wu@rock-chips.com>
2018-12-10 20:07:57 +08:00
David.Wu
80fb508ae6 arm64: configs: Enable CONFIG_USB and CONFIG_USB_DWC3_GADGET for rk3399pro_npu
The driver of dwc3-rockchip depends on CONFIG_USB and
CONFIG_USB_DWC3_GADGE. To use the driver, need to enable
them.

Change-Id: Iddfbf1ac2b413aa33f5803ffcfc165ec3555937f
Signed-off-by: David Wu <david.wu@rock-chips.com>
2018-12-10 20:07:27 +08:00
Wang Panzhenzhuan
45e40867e0 arm64: dts: rockchip: rk3399-tve1030g: distinguish isp relate nodes for Android 9.0 & 8.1
rk3399-tve1030g*:
    isp0/1 for CameraHal1 in Android8.1 or lower version
    rkisp1_0/1 & mipi_dphy_rx0/tx1rx1 for CameraHal3 in Android9.0

Change-Id: I9198eccb0d76ad5e51ff6a2a5021e5acefbf0f49
Signed-off-by: Wang Panzhenzhuan <randy.wang@rock-chips.com>
2018-12-10 18:23:49 +08:00
Zhangbin Tong
4e264676aa ARM: dts: add new dts file for rk3229 evb android avb
Change-Id: I1e76b87ffe691ab5171edc9215a13e1dd21cbf76
Signed-off-by: Zhangbin Tong <zebulun.tong@rock-chips.com>
2018-12-10 14:04:49 +08:00
Zhangbin Tong
53d0ac7346 arm: dts: rk3229-android: separate android fireware
Split DT source files to separate out android fireware specific DT
bindings.

Change-Id: I31361570a630057e50507593c6da693cf1200a12
Signed-off-by: Zhangbin Tong <zebulun.tong@rock-chips.com>
2018-12-10 14:04:18 +08:00
Weixin Zhou
0d6bd51f37 arm64: dts: rockchip: rk3399pro-evb: set vcc5v0_usb always on
Fix the device reconnect error after exit deepsleep.

Change-Id: I277875ad64b84d5b9fbf49d528ae75d571a04ff4
Signed-off-by: Weixin Zhou <zwx@rock-chips.com>
2018-12-07 17:49:21 +08:00
Joseph Chen
393f834ac6 power: rk816-battery: ac/usb implement "input_current_limit" sysfs node
store 0 to disable charger input current supply, otherwise
enable charger input current supply

Change-Id: Iabf61d3c8e6469cb5d6466677e06b73c6af37bcb
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-12-07 14:53:16 +08:00
Elaine Zhang
be86533d88 regulator: rk809 & rk817: fix up the is_enable return error
mark rk8xx_is_enabled_wmsk_regmap as is_enable callback func for siwtch ops.

Change-Id: Ice90f92438a73f77c61aadd1c43441626c24e075
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2018-12-07 14:51:34 +08:00
Weixin Zhou
98c0b83b3b arm64: dts: rockchip: rk3399pro-evb: fix mpu6500 orientation
Change-Id: I38b1490de055ec42307c59c9ed9317e577fe4bd5
Signed-off-by: Weixin Zhou <zwx@rock-chips.com>
2018-12-07 14:49:31 +08:00
Wyon Bi
4c56e6306b drm/rockchip: rk618: remove unused files
Change-Id: I76e3e24d8aa391b5491e05474357bfec139d3827
Signed-off-by: Wyon Bi <bivvy.bi@rock-chips.com>
2018-12-07 11:05:03 +08:00
Zain Wang
e47d6954e3 arm64: dts: rockchip: rk3328-evb: enable rockchip_suspend
Change-Id: I1348d18031557ca6f45826ee6ddf3b6b224a5075
Signed-off-by: Zain Wang <wzz@rock-chips.com>
2018-12-06 16:54:34 +08:00
William Wu
3099e13bdb usb: gadget: f_uvc: support uvc and adb use independently
If we use usb gadget as uvc and adb composite function,
the adb will be disconnected if the uvc camera apk is
closed. I can reproduce this issue by the following steps
on rk3399/rk3288 platforms.

1. Set usb gadget as uvc and adb composite function,
   and open uvc camera apk on rk3399/rk3288 platforms.
2. Connect usb to PC, and use adb shell;
3. Close the uvc camera apk;

And then, the adb will also be disconnected. It's because
that when close the uvc camera apk, the userspace calls
v4l2_release -> uvc_v4l2_release -> uvc_function_disconnect
-> usb_gadget_deactivate -> usb_gadget_disconnect ->
pullup(gadget, 0), this cause usb controller disconnect the
usb connection.

This patch adds a uvc_enabled flag to indicate that usb
is connected, don't call pullup(gadget, 0) to disconnet
usb if we only close uvc camera apk but not plug out usb
cable.

Change-Id: I0cc5ce8a24e8e06e0dc9215dfd1b92ef702e4311
Signed-off-by: William Wu <william.wu@rock-chips.com>
2018-12-06 16:36:47 +08:00
Zhengjun Xing
f025f3ea83 UPSTREAM: xhci: Fix kernel oops in trace_xhci_free_virt_device
commit 44a182b9d1 ("xhci: Fix use-after-free in xhci_free_virt_device")
set dev->udev pointer to NULL in xhci_free_dev(), it will cause kernel
panic in trace_xhci_free_virt_device. This patch reimplement the trace
function trace_xhci_free_virt_device, remove dev->udev dereference and
added more useful parameters to show in the trace function,it also makes
sure dev->udev is not NULL before calling trace_xhci_free_virt_device.
This issue happened when xhci-hcd trace is enabled and USB devices hot
plug test. Original use-after-free patch went to stable so this needs so
be applied there as well.

[ 1092.022457] usb 2-4: USB disconnect, device number 6
[ 1092.092772] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
[ 1092.101694] PGD 0 P4D 0
[ 1092.104601] Oops: 0000 [#1] SMP
[ 1092.207734] Workqueue: usb_hub_wq hub_event
[ 1092.212507] RIP: 0010:trace_event_raw_event_xhci_log_virt_dev+0x6c/0xf0
[ 1092.220050] RSP: 0018:ffff8c252e883d28 EFLAGS: 00010086
[ 1092.226024] RAX: ffff8c24af86fa84 RBX: 0000000000000003 RCX: ffff8c25255c2a01
[ 1092.234130] RDX: 0000000000000000 RSI: 00000000aef55009 RDI: ffff8c252e883d28
[ 1092.242242] RBP: ffff8c252550e2c0 R08: ffff8c24af86fa84 R09: 0000000000000a70
[ 1092.250364] R10: 0000000000000a70 R11: 0000000000000000 R12: ffff8c251f21a000
[ 1092.258468] R13: 000000000000000c R14: ffff8c251f21a000 R15: ffff8c251f432f60
[ 1092.266572] FS:  0000000000000000(0000) GS:ffff8c252e880000(0000) knlGS:0000000000000000
[ 1092.275757] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 1092.282281] CR2: 0000000000000000 CR3: 0000000154209001 CR4: 00000000003606e0
[ 1092.290384] Call Trace:
[ 1092.293156]  <IRQ>
[ 1092.295439]  xhci_free_virt_device.part.34+0x182/0x1a0
[ 1092.301288]  handle_cmd_completion+0x7ac/0xfa0
[ 1092.306336]  ? trace_event_raw_event_xhci_log_trb+0x6e/0xa0
[ 1092.312661]  xhci_irq+0x3e8/0x1f60
[ 1092.316524]  __handle_irq_event_percpu+0x75/0x180
[ 1092.321876]  handle_irq_event_percpu+0x20/0x50
[ 1092.326922]  handle_irq_event+0x36/0x60
[ 1092.331273]  handle_edge_irq+0x6d/0x180
[ 1092.335644]  handle_irq+0x16/0x20
[ 1092.339417]  do_IRQ+0x41/0xc0
[ 1092.342782]  common_interrupt+0xf/0xf
[ 1092.346955]  </IRQ>

Fixes: 44a182b9d1 ("xhci: Fix use-after-free in xhci_free_virt_device")
Change-Id: I233aed0fdbe490d6d01a908dc0242f19781339f1
Cc: <stable@vger.kernel.org>
Signed-off-by: Zhengjun Xing <zhengjun.xing@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit d850c16583)
2018-12-06 10:17:00 +08:00
Mathias Nyman
50ed1d0da9 UPSTREAM: xhci: Fix USB3 NULL pointer dereference at logical disconnect.
Hub driver will try to disable a USB3 device twice at logical disconnect,
racing with xhci_free_dev() callback from the first port disable.

This can be triggered with "udisksctl power-off --block-device <disk>"
or by writing "1" to the "remove" sysfs file for a USB3 device
in 4.17-rc4.

USB3 devices don't have a similar disabled link state as USB2 devices,
and use a U3 suspended link state instead. In this state the port
is still enabled and connected.

hub_port_connect() first disconnects the device, then later it notices
that device is still enabled (due to U3 states) it will try to disable
the port again (set to U3).

The xhci_free_dev() called during device disable is async, so checking
for existing xhci->devs[i] when setting link state to U3 the second time
was successful, even if device was being freed.

The regression was caused by, and whole thing revealed by,
Commit 44a182b9d1 ("xhci: Fix use-after-free in xhci_free_virt_device")
which sets xhci->devs[i]->udev to NULL before xhci_virt_dev() returned.
and causes a NULL pointer dereference the second time we try to set U3.

Fix this by checking xhci->devs[i]->udev exists before setting link state.

The original patch went to stable so this fix needs to be applied there as
well.

Fixes: 44a182b9d1 ("xhci: Fix use-after-free in xhci_free_virt_device")
Change-Id: I568357fcb3ab320b628f6998ba1e571d40ecaa06
Cc: <stable@vger.kernel.org>
Reported-by: Jordan Glover <Golden_Miller83@protonmail.ch>
Tested-by: Jordan Glover <Golden_Miller83@protonmail.ch>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 2278446e2b)
2018-12-06 10:17:00 +08:00
Zhengjun Xing
c51d966e8e UPSTREAM: xhci: Fix NULL pointer in xhci debugfs
Commit dde634057d ("xhci: Fix use-after-free in xhci debugfs") causes a
null pointer dereference while fixing xhci-debugfs usage of ring pointers
that were freed during hibernate.

The fix passed addresses to ring pointers instead, but forgot to do this
change for the xhci_ring_trb_show function.

The address of the ring pointer passed to xhci-debugfs was of a temporary
ring pointer "new_ring" instead of the actual ring "ring" pointer. The
temporary new_ring pointer will be set to NULL later causing the NULL
pointer dereference.

This issue was seen when reading xhci related files in debugfs:

cat /sys/kernel/debug/usb/xhci/*/devices/*/ep*/trbs

[  184.604861] BUG: unable to handle kernel NULL pointer dereference at (null)
[  184.613776] IP: xhci_ring_trb_show+0x3a/0x890
[  184.618733] PGD 264193067 P4D 264193067 PUD 263238067 PMD 0
[  184.625184] Oops: 0000 [#1] SMP
[  184.726410] RIP: 0010:xhci_ring_trb_show+0x3a/0x890
[  184.731944] RSP: 0018:ffffba8243c0fd90 EFLAGS: 00010246
[  184.737880] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00000000000295d6
[  184.746020] RDX: 00000000000295d5 RSI: 0000000000000001 RDI: ffff971a6418d400
[  184.754121] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
[  184.762222] R10: ffff971a64c98a80 R11: ffff971a62a00e40 R12: ffff971a62a85500
[  184.770325] R13: 0000000000020000 R14: ffff971a6418d400 R15: ffff971a6418d400
[  184.778448] FS:  00007fe725a79700(0000) GS:ffff971a6ec00000(0000) knlGS:0000000000000000
[  184.787644] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  184.794168] CR2: 0000000000000000 CR3: 000000025f365005 CR4: 00000000003606f0
[  184.802318] Call Trace:
[  184.805094]  ? seq_read+0x281/0x3b0
[  184.809068]  seq_read+0xeb/0x3b0
[  184.812735]  full_proxy_read+0x4d/0x70
[  184.817007]  __vfs_read+0x23/0x120
[  184.820870]  vfs_read+0x91/0x130
[  184.824538]  SyS_read+0x42/0x90
[  184.828106]  entry_SYSCALL_64_fastpath+0x1a/0x7d

Change-Id: Icd54424a559e7a028e270edfa0e28a0f9dd645f9
Fixes: dde634057d ("xhci: Fix use-after-free in xhci debugfs")
Cc: <stable@vger.kernel.org> # v4.15
Signed-off-by: Zhengjun Xing <zhengjun.xing@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
2018-12-06 10:17:00 +08:00
Alexander Kappner
fa6b063e20 UPSTREAM: xhci: Fix use-after-free in xhci debugfs
Trying to read from debugfs after the system has resumed from
hibernate causes a use-after-free and thus a protection fault.

Steps to reproduce:
Hibernate system, resume from hibernate, then run
$ cat /sys/kernel/debug/usb/xhci/*/command-ring/enqueue

[ 3902.765086] general protection fault: 0000 [#1] PREEMPT SMP
...
[ 3902.765136] RIP: 0010:xhci_trb_virt_to_dma.part.50+0x5/0x30
...
[ 3902.765178] Call Trace:
[ 3902.765188]  xhci_ring_enqueue_show+0x1e/0x40
[ 3902.765197]  seq_read+0xdb/0x3a0
[ 3902.765204]  ? __handle_mm_fault+0x5fb/0x1210
[ 3902.765211]  full_proxy_read+0x4a/0x70
[ 3902.765219]  __vfs_read+0x23/0x120
[ 3902.765228]  vfs_read+0x8e/0x130
[ 3902.765235]  SyS_read+0x42/0x90
[ 3902.765242]  do_syscall_64+0x6b/0x290
[ 3902.765251]  entry_SYSCALL64_slow_path+0x25/0x25

The issue is caused by the xhci ring structures being reallocated
when the system is resumed, but pointers to the old structures
being retained in the debugfs files "private" field:

The proposed patch fixes this issue by storing a pointer to the xhci_ring
field in the xhci device structure in debugfs rather than directly
storing a pointer to the xhci_ring.

Change-Id: Ic60c7b4c7599209b89775e03b5cc4f9d9cdba6ac
Fixes: 02b6fdc2a1 ("usb: xhci: Add debugfs interface for xHCI driver")
Signed-off-by: Alexander Kappner <agk@godking.net>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
2018-12-06 10:17:00 +08:00
Mathias Nyman
87802b3d7a UPSTREAM: xhci: Fix xhci debugfs NULL pointer dereference in resume from hibernate
Free the virt_device and its debugfs_private member together.

When resuming from hibernate the .free_dev callback unconditionally
freed the debugfs_private member, but could leave virt_device intact.

This triggered a NULL pointer dereference after resume when usbmuxd
sent a USBDEVFS_SETCONFIGURATION ioctl to a device, trying to add a
endpoint debugfs entry to a already freed debugfs_private pointer.

Change-Id: Ib0ed39ee0f82f3f5c3af5c46949a6a5f6dfe190d
Fixes: 02b6fdc2a1 ("usb: xhci: Add debugfs interface for xHCI driver")
Reported-by: Alexander Kappner <agk@godking.net>
Tested-by: Alexander Kappner <agk@godking.net>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
2018-12-06 10:17:00 +08:00
Algea Cao
5f96ef7e0f drm/rockchip: Add hdmi shutdown interface
When system shutdown, shutdown interface will be called.
Hdmi should be disabled when system shutdown.

Change-Id: I09ec1d7d3801bf8a8277c91072fa09bd1b430809
Signed-off-by: Algea Cao <algea.cao@rock-chips.com>
2018-12-06 09:30:59 +08:00
Algea Cao
9b93bb6b3c drm/rockchip: tve: Add tve shutdown interface
When system shutdown, shutdown interface will be called.
TVE should be disabled when system shutdown.

Change-Id: If9dd29605cc0bd67aa8e9c494a98f89e625e4c50
Signed-off-by: Algea Cao <algea.cao@rock-chips.com>
2018-12-05 18:17:16 +08:00
Sugar Zhang
9a0b8a7eb2 clk: rockchip: px30: Export clk id for sclk_i2s0_tx/rx mux
Change-Id: I697d20fb0c69f9dcd76aaf2d18d666db2241360d
Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
2018-12-05 18:16:28 +08:00
Sugar Zhang
abba102d04 ASoC: rockchip: pdm: Correct PDM_CTRL0 reg value
This patch fix the wrong reg value for rk322x/rk322xh,
cuz there is no STORE JUSTIFIED MODE on it.

on rk322x/rk322xh, the same bit means PDM_MODE/RESERVED,
if the bit is set to RESERVED, the controller will not work.

Change-Id: I9bfc055e792d73a66f51c78c7c2ff5c4cba620ae
Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
2018-12-05 18:16:28 +08:00
Sugar Zhang
e0fa2af584 ASoC: rockchip: pdm: Mark RXFIFO_DATA as volatile and precious
This patch marks RXFIFO_DATA as precious to avoid being read
outside a call from the driver, such as regmap debugfs

Change-Id: Id94a3d6f4ea382fc09547241dabc6ab84ca74139
Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
2018-12-05 18:16:28 +08:00
Sugar Zhang
a5d947fe00 ASoC: rockchip: spdifrx: Mark SPDIFRX_SMPDR as volatile and precious
This patch marks SPDIFRX_SMPDR as precious to avoid being read
outside a call from the driver, such as regmap debugfs.

Change-Id: Icc5398e0e192b86e191770b9ebd1251f97e6a048
Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
2018-12-05 18:16:28 +08:00
Sugar Zhang
81901bd3af ASoC: rockchip: spdif: Mark SPDIF_SMPDR as volatile
This patch marks SPDIF_SMPDR as volatile to make it resaonable,
which also requires marking it as readable, even though it isn't.

Change-Id: Ia59136a4d7a9a3984d4f4b2518f835ead7419aec
Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
2018-12-05 18:16:28 +08:00