1. 10 10月, 2019 1 次提交
  2. 04 10月, 2019 1 次提交
  3. 20 8月, 2019 1 次提交
  4. 18 6月, 2019 1 次提交
    • S
      tty: serial_core: Set port active bit in uart_port_activate · 13b18d35
      Serge Semin 提交于
      A bug was introduced by commit b3b57646 ("tty: serial_core: convert
      uart_open to use tty_port_open"). It caused a constant warning printed
      into the system log regarding the tty and port counter mismatch:
      
      [   21.644197] ttyS ttySx: tty_port_close_start: tty->count = 1 port count = 2
      
      in case if session hangup was detected so the warning is printed starting
      from the second open-close iteration.
      
      Particularly the problem was discovered in situation when there is a
      serial tty device without hardware back-end being setup. It is considered
      by the tty-serial subsystems as a hardware problem with session hang up.
      In this case uart_startup() will return a positive value with TTY_IO_ERROR
      flag set in corresponding tty_struct instance. The same value will get
      passed to be returned from the activate() callback and then being returned
      from tty_port_open(). But since in this case tty_port_block_til_ready()
      isn't called the TTY_PORT_ACTIVE flag isn't set (while the method had been
      called before tty_port_open conversion was introduced and the rest of the
      subsystem code expected the bit being set in this case), which prevents the
      uart_hangup() method to perform any cleanups including the tty port
      counter setting to zero. So the next attempt to open/close the tty device
      will discover the counters mismatch.
      
      In order to fix the problem we need to manually set the TTY_PORT_ACTIVE
      flag in case if uart_startup() returned a positive value. In this case
      the hang up procedure will perform a full set of cleanup actions including
      the port ref-counter resetting.
      
      Fixes: b3b57646 "tty: serial_core: convert uart_open to use tty_port_open"
      Signed-off-by: NSerge Semin <fancer.lancer@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13b18d35
  5. 25 4月, 2019 2 次提交
    • S
      tty: serial_core: fix error code returned by uart_register_driver() · 050dfc09
      Sergey Organov 提交于
      uart_register_driver() returned -ENOMEM on any error, even when
      tty_register_driver() call returned another one, such as -EBUSY.
      Signed-off-by: NSergey Organov <sorganov@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      050dfc09
    • J
      TTY: serial_core, add ->install · 4cdd17ba
      Jiri Slaby 提交于
      We need to compute the uart state only on the first open. This is
      usually what is done in the ->install hook. serial_core used to do this
      in ->open on every open. So move it to ->install.
      
      As a side effect, it ensures the state is set properly in the window
      after tty_init_dev is called, but before uart_open. This fixes a bunch
      of races between tty_open and flush_to_ldisc we were dealing with
      recently.
      
      One of such bugs was attempted to fix in commit fedb5760 (serial:
      fix race between flush_to_ldisc and tty_open), but it only took care of
      a couple of functions (uart_start and uart_unthrottle).  I was able to
      reproduce the crash on a SLE system, but in uart_write_room which is
      also called from flush_to_ldisc via process_echoes. I was *unable* to
      reproduce the bug locally. It is due to having this patch in my queue
      since 2012!
      
       general protection fault: 0000 [#1] SMP KASAN PTI
       CPU: 1 PID: 5 Comm: kworker/u4:0 Tainted: G             L 4.12.14-396-default #1 SLE15-SP1 (unreleased)
       Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c89-prebuilt.qemu.org 04/01/2014
       Workqueue: events_unbound flush_to_ldisc
       task: ffff8800427d8040 task.stack: ffff8800427f0000
       RIP: 0010:uart_write_room+0xc4/0x590
       RSP: 0018:ffff8800427f7088 EFLAGS: 00010202
       RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
       RDX: 000000000000002f RSI: 00000000000000ee RDI: ffff88003888bd90
       RBP: ffffffffb9545850 R08: 0000000000000001 R09: 0000000000000400
       R10: ffff8800427d825c R11: 000000000000006e R12: 1ffff100084fee12
       R13: ffffc900004c5000 R14: ffff88003888bb28 R15: 0000000000000178
       FS:  0000000000000000(0000) GS:ffff880043300000(0000) knlGS:0000000000000000
       CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
       CR2: 0000561da0794148 CR3: 000000000ebf4000 CR4: 00000000000006e0
       Call Trace:
        tty_write_room+0x6d/0xc0
        __process_echoes+0x55/0x870
        n_tty_receive_buf_common+0x105e/0x26d0
        tty_ldisc_receive_buf+0xb7/0x1c0
        tty_port_default_receive_buf+0x107/0x180
        flush_to_ldisc+0x35d/0x5c0
      ...
      
      0 in rbx means tty->driver_data is NULL in uart_write_room. 0x178 is
      tried to be dereferenced (0x178 >> 3 is 0x2f in rdx) at
      uart_write_room+0xc4. 0x178 is exactly (struct uart_state *)NULL->refcount
      used in uart_port_lock from uart_write_room.
      
      So revert the upstream commit here as my local patch should fix the
      whole family.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: Li RongQing <lirongqing@baidu.com>
      Cc: Wang Li <wangli39@baidu.com>
      Cc: Zhang Yu <zhangyu31@baidu.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4cdd17ba
  6. 16 4月, 2019 1 次提交
  7. 19 2月, 2019 1 次提交
  8. 01 2月, 2019 1 次提交
    • G
      serial: fix race between flush_to_ldisc and tty_open · fedb5760
      Greg Kroah-Hartman 提交于
      There still is a race window after the commit b027e229
      ("tty: fix data race between tty_init_dev and flush of buf"),
      and we encountered this crash issue if receive_buf call comes
      before tty initialization completes in tty_open and
      tty->driver_data may be NULL.
      
      CPU0                                    CPU1
      ----                                    ----
                                        tty_open
                                         tty_init_dev
                                           tty_ldisc_unlock
                                             schedule
      flush_to_ldisc
       receive_buf
        tty_port_default_receive_buf
         tty_ldisc_receive_buf
          n_tty_receive_buf_common
            __receive_buf
             uart_flush_chars
              uart_start
              /*tty->driver_data is NULL*/
                                         tty->ops->open
                                         /*init tty->driver_data*/
      
      it can be fixed by extending ldisc semaphore lock in tty_init_dev
      to driver_data initialized completely after tty->ops->open(), but
      this will lead to get lock on one function and unlock in some other
      function, and hard to maintain, so fix this race only by checking
      tty->driver_data when receiving, and return if tty->driver_data
      is NULL, and n_tty_receive_buf_common maybe calls uart_unthrottle,
      so add the same check.
      
      Because the tty layer knows nothing about the driver associated with the
      device, the tty layer can not do anything here, it is up to the tty
      driver itself to check for this type of race.  Fix up the serial driver
      to correctly check to see if it is finished binding with the device when
      being called, and if not, abort the tty calls.
      
      [Description and problem report and testing from Li RongQing, I rewrote
      the patch to be in the serial layer, not in the tty core - gregkh]
      Reported-by: NLi RongQing <lirongqing@baidu.com>
      Tested-by: NLi RongQing <lirongqing@baidu.com>
      Signed-off-by: NWang Li <wangli39@baidu.com>
      Signed-off-by: NZhang Yu <zhangyu31@baidu.com>
      Signed-off-by: NLi RongQing <lirongqing@baidu.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fedb5760
  9. 18 1月, 2019 1 次提交
    • S
      uart: Fix crash in uart_write and uart_put_char · aff9cf59
      Samir Virmani 提交于
      We were experiencing a crash similar to the one reported as part of
      commit:a5ba1d95 ("uart: fix race between uart_put_char() and
      uart_shutdown()") in our testbed as well. We continue to observe the same
      crash after integrating the commit a5ba1d95 ("uart: fix race between
      uart_put_char() and uart_shutdown()")
      
      On reviewing the change, the port lock should be taken prior to checking for
      if (!circ->buf) in fn. __uart_put_char and other fns. that update the buffer
      uart_state->xmit.
      
      Traceback:
      
      [11/27/2018 06:24:32.4870] Unable to handle kernel NULL pointer dereference
                                 at virtual address 0000003b
      
      [11/27/2018 06:24:32.4950] PC is at memcpy+0x48/0x180
      [11/27/2018 06:24:32.4950] LR is at uart_write+0x74/0x120
      [11/27/2018 06:24:32.4950] pc : [<ffffffc0002e6808>]
                                 lr : [<ffffffc0003747cc>] pstate: 000001c5
      [11/27/2018 06:24:32.4950] sp : ffffffc076433d30
      [11/27/2018 06:24:32.4950] x29: ffffffc076433d30 x28: 0000000000000140
      [11/27/2018 06:24:32.4950] x27: ffffffc0009b9d5e x26: ffffffc07ce36580
      [11/27/2018 06:24:32.4950] x25: 0000000000000000 x24: 0000000000000140
      [11/27/2018 06:24:32.4950] x23: ffffffc000891200 x22: ffffffc01fc34000
      [11/27/2018 06:24:32.4950] x21: 0000000000000fff x20: 0000000000000076
      [11/27/2018 06:24:32.4950] x19: 0000000000000076 x18: 0000000000000000
      [11/27/2018 06:24:32.4950] x17: 000000000047cf08 x16: ffffffc000099e68
      [11/27/2018 06:24:32.4950] x15: 0000000000000018 x14: 776d726966205948
      [11/27/2018 06:24:32.4950] x13: 50203a6c6974755f x12: 74647075205d3333
      [11/27/2018 06:24:32.4950] x11: 3a35323a36203831 x10: 30322f37322f3131
      [11/27/2018 06:24:32.4950] x9 : 5b205d303638342e x8 : 746164206f742070
      [11/27/2018 06:24:32.4950] x7 : 7520736920657261 x6 : 000000000000003b
      [11/27/2018 06:24:32.4950] x5 : 000000000000817a x4 : 0000000000000008
      [11/27/2018 06:24:32.4950] x3 : 2f37322f31312a5b x2 : 000000000000006e
      [11/27/2018 06:24:32.4950] x1 : ffffffc0009b9cf0 x0 : 000000000000003b
      
      [11/27/2018 06:24:32.4950] CPU2: stopping
      [11/27/2018 06:24:32.4950] CPU: 2 PID: 0 Comm: swapper/2 Tainted: P      D    O    4.1.51 #3
      [11/27/2018 06:24:32.4950] Hardware name: Broadcom-v8A (DT)
      [11/27/2018 06:24:32.4950] Call trace:
      [11/27/2018 06:24:32.4950] [<ffffffc0000883b8>] dump_backtrace+0x0/0x150
      [11/27/2018 06:24:32.4950] [<ffffffc00008851c>] show_stack+0x14/0x20
      [11/27/2018 06:24:32.4950] [<ffffffc0005ee810>] dump_stack+0x90/0xb0
      [11/27/2018 06:24:32.4950] [<ffffffc00008e844>] handle_IPI+0x18c/0x1a0
      [11/27/2018 06:24:32.4950] [<ffffffc000080c68>] gic_handle_irq+0x88/0x90
      
      Fixes: a5ba1d95 ("uart: fix race between uart_put_char() and uart_shutdown()")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NSamir Virmani <samir@embedur.com>
      Acked-by: NTycho Andersen <tycho@tycho.ws>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aff9cf59
  10. 17 12月, 2018 1 次提交
    • S
      tty/serial: do not free trasnmit buffer page under port lock · d7240214
      Sergey Senozhatsky 提交于
      LKP has hit yet another circular locking dependency between uart
      console drivers and debugobjects [1]:
      
           CPU0                                    CPU1
      
                                                  rhltable_init()
                                                   __init_work()
                                                    debug_object_init
           uart_shutdown()                          /* db->lock */
            /* uart_port->lock */                    debug_print_object()
             free_page()                              printk()
                                                       call_console_drivers()
              debug_check_no_obj_freed()                /* uart_port->lock */
               /* db->lock */
                debug_print_object()
      
      So there are two dependency chains:
      	uart_port->lock -> db->lock
      And
      	db->lock -> uart_port->lock
      
      This particular circular locking dependency can be addressed in several
      ways:
      
      a) One way would be to move debug_print_object() out of db->lock scope
         and, thus, break the db->lock -> uart_port->lock chain.
      b) Another one would be to free() transmit buffer page out of db->lock
         in UART code; which is what this patch does.
      
      It makes sense to apply a) and b) independently: there are too many things
      going on behind free(), none of which depend on uart_port->lock.
      
      The patch fixes transmit buffer page free() in uart_shutdown() and,
      additionally, in uart_port_startup() (as was suggested by Dmitry Safonov).
      
      [1] https://lore.kernel.org/lkml/20181211091154.GL23332@shao2-debian/T/#uSigned-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Reviewed-by: NPetr Mladek <pmladek@suse.com>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Dmitry Safonov <dima@arista.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d7240214
  11. 13 10月, 2018 2 次提交
  12. 05 10月, 2018 1 次提交
  13. 03 10月, 2018 2 次提交
  14. 13 7月, 2018 1 次提交
    • T
      uart: fix race between uart_put_char() and uart_shutdown() · a5ba1d95
      Tycho Andersen 提交于
      We have reports of the following crash:
      
          PID: 7 TASK: ffff88085c6d61c0 CPU: 1 COMMAND: "kworker/u25:0"
          #0 [ffff88085c6db710] machine_kexec at ffffffff81046239
          #1 [ffff88085c6db760] crash_kexec at ffffffff810fc248
          #2 [ffff88085c6db830] oops_end at ffffffff81008ae7
          #3 [ffff88085c6db860] no_context at ffffffff81050b8f
          #4 [ffff88085c6db8b0] __bad_area_nosemaphore at ffffffff81050d75
          #5 [ffff88085c6db900] bad_area_nosemaphore at ffffffff81050e83
          #6 [ffff88085c6db910] __do_page_fault at ffffffff8105132e
          #7 [ffff88085c6db9b0] do_page_fault at ffffffff8105152c
          #8 [ffff88085c6db9c0] page_fault at ffffffff81a3f122
          [exception RIP: uart_put_char+149]
          RIP: ffffffff814b67b5 RSP: ffff88085c6dba78 RFLAGS: 00010006
          RAX: 0000000000000292 RBX: ffffffff827c5120 RCX: 0000000000000081
          RDX: 0000000000000000 RSI: 000000000000005f RDI: ffffffff827c5120
          RBP: ffff88085c6dba98 R8: 000000000000012c R9: ffffffff822ea320
          R10: ffff88085fe4db04 R11: 0000000000000001 R12: ffff881059f9c000
          R13: 0000000000000001 R14: 000000000000005f R15: 0000000000000fba
          ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
          #9 [ffff88085c6dbaa0] tty_put_char at ffffffff81497544
          #10 [ffff88085c6dbac0] do_output_char at ffffffff8149c91c
          #11 [ffff88085c6dbae0] __process_echoes at ffffffff8149cb8b
          #12 [ffff88085c6dbb30] commit_echoes at ffffffff8149cdc2
          #13 [ffff88085c6dbb60] n_tty_receive_buf_fast at ffffffff8149e49b
          #14 [ffff88085c6dbbc0] __receive_buf at ffffffff8149ef5a
          #15 [ffff88085c6dbc20] n_tty_receive_buf_common at ffffffff8149f016
          #16 [ffff88085c6dbca0] n_tty_receive_buf2 at ffffffff8149f194
          #17 [ffff88085c6dbcb0] flush_to_ldisc at ffffffff814a238a
          #18 [ffff88085c6dbd50] process_one_work at ffffffff81090be2
          #19 [ffff88085c6dbe20] worker_thread at ffffffff81091b4d
          #20 [ffff88085c6dbeb0] kthread at ffffffff81096384
          #21 [ffff88085c6dbf50] ret_from_fork at ffffffff81a3d69f​
      
      after slogging through some dissasembly:
      
      ffffffff814b6720 <uart_put_char>:
      ffffffff814b6720:	55                   	push   %rbp
      ffffffff814b6721:	48 89 e5             	mov    %rsp,%rbp
      ffffffff814b6724:	48 83 ec 20          	sub    $0x20,%rsp
      ffffffff814b6728:	48 89 1c 24          	mov    %rbx,(%rsp)
      ffffffff814b672c:	4c 89 64 24 08       	mov    %r12,0x8(%rsp)
      ffffffff814b6731:	4c 89 6c 24 10       	mov    %r13,0x10(%rsp)
      ffffffff814b6736:	4c 89 74 24 18       	mov    %r14,0x18(%rsp)
      ffffffff814b673b:	e8 b0 8e 58 00       	callq  ffffffff81a3f5f0 <mcount>
      ffffffff814b6740:	4c 8b a7 88 02 00 00 	mov    0x288(%rdi),%r12
      ffffffff814b6747:	45 31 ed             	xor    %r13d,%r13d
      ffffffff814b674a:	41 89 f6             	mov    %esi,%r14d
      ffffffff814b674d:	49 83 bc 24 70 01 00 	cmpq   $0x0,0x170(%r12)
      ffffffff814b6754:	00 00
      ffffffff814b6756:	49 8b 9c 24 80 01 00 	mov    0x180(%r12),%rbx
      ffffffff814b675d:	00
      ffffffff814b675e:	74 2f                	je     ffffffff814b678f <uart_put_char+0x6f>
      ffffffff814b6760:	48 89 df             	mov    %rbx,%rdi
      ffffffff814b6763:	e8 a8 67 58 00       	callq  ffffffff81a3cf10 <_raw_spin_lock_irqsave>
      ffffffff814b6768:	41 8b 8c 24 78 01 00 	mov    0x178(%r12),%ecx
      ffffffff814b676f:	00
      ffffffff814b6770:	89 ca                	mov    %ecx,%edx
      ffffffff814b6772:	f7 d2                	not    %edx
      ffffffff814b6774:	41 03 94 24 7c 01 00 	add    0x17c(%r12),%edx
      ffffffff814b677b:	00
      ffffffff814b677c:	81 e2 ff 0f 00 00    	and    $0xfff,%edx
      ffffffff814b6782:	75 23                	jne    ffffffff814b67a7 <uart_put_char+0x87>
      ffffffff814b6784:	48 89 c6             	mov    %rax,%rsi
      ffffffff814b6787:	48 89 df             	mov    %rbx,%rdi
      ffffffff814b678a:	e8 e1 64 58 00       	callq  ffffffff81a3cc70 <_raw_spin_unlock_irqrestore>
      ffffffff814b678f:	44 89 e8             	mov    %r13d,%eax
      ffffffff814b6792:	48 8b 1c 24          	mov    (%rsp),%rbx
      ffffffff814b6796:	4c 8b 64 24 08       	mov    0x8(%rsp),%r12
      ffffffff814b679b:	4c 8b 6c 24 10       	mov    0x10(%rsp),%r13
      ffffffff814b67a0:	4c 8b 74 24 18       	mov    0x18(%rsp),%r14
      ffffffff814b67a5:	c9                   	leaveq
      ffffffff814b67a6:	c3                   	retq
      ffffffff814b67a7:	49 8b 94 24 70 01 00 	mov    0x170(%r12),%rdx
      ffffffff814b67ae:	00
      ffffffff814b67af:	48 63 c9             	movslq %ecx,%rcx
      ffffffff814b67b2:	41 b5 01             	mov    $0x1,%r13b
      ffffffff814b67b5:	44 88 34 0a          	mov    %r14b,(%rdx,%rcx,1)
      ffffffff814b67b9:	41 8b 94 24 78 01 00 	mov    0x178(%r12),%edx
      ffffffff814b67c0:	00
      ffffffff814b67c1:	83 c2 01             	add    $0x1,%edx
      ffffffff814b67c4:	81 e2 ff 0f 00 00    	and    $0xfff,%edx
      ffffffff814b67ca:	41 89 94 24 78 01 00 	mov    %edx,0x178(%r12)
      ffffffff814b67d1:	00
      ffffffff814b67d2:	eb b0                	jmp    ffffffff814b6784 <uart_put_char+0x64>
      ffffffff814b67d4:	66 66 66 2e 0f 1f 84 	data32 data32 nopw %cs:0x0(%rax,%rax,1)
      ffffffff814b67db:	00 00 00 00 00
      
      for our build, this is crashing at:
      
          circ->buf[circ->head] = c;
      
      Looking in uart_port_startup(), it seems that circ->buf (state->xmit.buf)
      protected by the "per-port mutex", which based on uart_port_check() is
      state->port.mutex. Indeed, the lock acquired in uart_put_char() is
      uport->lock, i.e. not the same lock.
      
      Anyway, since the lock is not acquired, if uart_shutdown() is called, the
      last chunk of that function may release state->xmit.buf before its assigned
      to null, and cause the race above.
      
      To fix it, let's lock uport->lock when allocating/deallocating
      state->xmit.buf in addition to the per-port mutex.
      
      v2: switch to locking uport->lock on allocation/deallocation instead of
          locking the per-port mutex in uart_put_char. Note that since
          uport->lock is a spin lock, we have to switch the allocation to
          GFP_ATOMIC.
      v3: move the allocation outside the lock, so we can switch back to
          GFP_KERNEL
      Signed-off-by: NTycho Andersen <tycho@tycho.ws>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a5ba1d95
  15. 13 6月, 2018 1 次提交
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6396bb22
  16. 16 5月, 2018 1 次提交
  17. 23 4月, 2018 1 次提交
  18. 23 3月, 2018 1 次提交
  19. 28 2月, 2018 1 次提交
  20. 22 1月, 2018 1 次提交
    • S
      serial: core: mark port as initialized after successful IRQ change · 44117a1d
      Sebastian Andrzej Siewior 提交于
      setserial changes the IRQ via uart_set_info(). It invokes
      uart_shutdown() which free the current used IRQ and clear
      TTY_PORT_INITIALIZED. It will then update the IRQ number and invoke
      uart_startup() before returning to the caller leaving
      TTY_PORT_INITIALIZED cleared.
      
      The next open will crash with
      |  list_add double add: new=ffffffff839fcc98, prev=ffffffff839fcc98, next=ffffffff839fcc98.
      since the close from the IOCTL won't free the IRQ (and clean the list)
      due to the TTY_PORT_INITIALIZED check in uart_shutdown().
      
      There is same pattern in uart_do_autoconfig() and I *think* it also
      needs to set TTY_PORT_INITIALIZED there.
      Is there a reason why uart_startup() does not set the flag by itself
      after the IRQ has been acquired (since it is cleared in uart_shutdown)?
      Signed-off-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      44117a1d
  21. 09 1月, 2018 1 次提交
  22. 28 11月, 2017 2 次提交
    • L
      serial: core: Support common rs485 binding for RTS polarity · f1e5b618
      Lukas Wunner 提交于
      When a driver invokes the uart_get_rs485_mode() helper, set the RTS
      polarity to active high by default unless the newly introduced
      "rs485-rts-active-low" property was specified.
      
      imx contains a line to set the default RTS polarity to active high,
      it is now superfluous and hence deleted.
      
      omap-serial historically defaults to active low and supports an
      "rs485-rts-active-high" property to inverse the polarity.
      Retain that behavior for compatibility.
      
      Cc: Mark Jackson <mpfj@newflow.co.uk>
      Cc: Michał Oleszczyk <oleszczyk.m@gmail.com>
      Cc: Rafael Gago Castano <rgc@hms.se>
      Cc: Sascha Hauer <s.hauer@pengutronix.de>
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Acked-by: NUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f1e5b618
    • L
      serial: Make retrieval of rs485 properties platform-agnostic · 743f93f8
      Lukas Wunner 提交于
      Commit ef838a81 ("serial: Add common rs485 device tree parsing
      function") consolidated retrieval of rs485 OF properties in a common
      helper function but did not #ifdef it to CONFIG_OF.  The function is
      therefore included on ACPI platforms as well even though it's not used.
      
      On the other hand ACPI platforms with rs485 do exist (e.g. Siemens
      IOT2040) and they may leverage _DSD to store rs485 properties.  Likewise,
      UART platform devices instantiated from an MFD should be able to specify
      rs485 properties.  In fact, the tty subsystem maintainer had asked for
      a "generic" function during review of commit ef838a81:
      https://marc.info/?l=linux-serial&m=150143441725194&w=4
      
      Thus, instead of constraining the helper to OF platforms, make it
      platform-agnostic by converting it to device_property_*() functions
      and renaming it accordingly.
      
      In imx.c, move the invocation of uart_get_rs485_mode() from
      serial_imx_probe_dt() to serial_imx_probe() so that it also gets called
      for non-OF devices.
      
      In omap-serial.c, move its invocation further up within
      serial_omap_probe_rs485() so that the RTS polarity can be overridden
      with the driver-specific "rs485-rts-active-high" property once we
      introduce a generic "rs485-rts-active-low" property.
      
      Cc: Jan Kiszka <jan.kiszka@siemens.com>
      Cc: Richard Genoud <richard.genoud@gmail.com>
      Cc: Sascha Hauer <s.hauer@pengutronix.de>
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Acked-by: NUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      743f93f8
  23. 08 11月, 2017 2 次提交
    • G
      tty: serial: Remove redundant license text · 4793f2eb
      Greg Kroah-Hartman 提交于
      Now that the SPDX tag is in all tty files, that identifies the license
      in a specific and legally-defined manner.  So the extra GPL text wording
      can be removed as it is no longer needed at all.
      
      This is done on a quest to remove the 700+ different ways that files in
      the kernel describe the GPL license text.  And there's unneeded stuff
      like the address (sometimes incorrect) for the FSF which is never
      needed.
      
      No copyright headers or other non-license-description text was removed.
      
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Eric Anholt <eric@anholt.net>
      Cc: Stefan Wahren <stefan.wahren@i2se.com>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Ray Jui <rjui@broadcom.com>
      Cc: Scott Branden <sbranden@broadcom.com>
      Cc: bcm-kernel-feedback-list@broadcom.com
      Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Joachim Eastwood <manabian@gmail.com>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Tobias Klauser <tklauser@distanz.ch>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Vineet Gupta <vgupta@synopsys.com>
      Cc: Richard Genoud <richard.genoud@gmail.com>
      Cc: Alexander Shiyan <shc_work@mail.ru>
      Cc: Baruch Siach <baruch@tkos.co.il>
      Cc: Pat Gefre <pfg@sgi.com>
      Cc: "Guilherme G. Piccoli" <gpiccoli@linux.vnet.ibm.com>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: Vladimir Zapolskiy <vz@mleia.com>
      Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
      Cc: Carlo Caione <carlo@caione.org>
      Cc: Kevin Hilman <khilman@baylibre.com>
      Cc: Liviu Dudau <liviu.dudau@arm.com>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: Andy Gross <andy.gross@linaro.org>
      Cc: David Brown <david.brown@linaro.org>
      Cc: "Andreas Färber" <afaerber@suse.de>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Kevin Cernekee <cernekee@gmail.com>
      Cc: Laxman Dewangan <ldewangan@nvidia.com>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: Jonathan Hunter <jonathanh@nvidia.com>
      Cc: Barry Song <baohua@kernel.org>
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Alexandre Torgue <alexandre.torgue@st.com>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: Peter Korsgaard <jacmet@sunsite.dk>
      Cc: Timur Tabi <timur@tabi.org>
      Cc: Tony Prisk <linux@prisktech.co.nz>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: "Sören Brinkmann" <soren.brinkmann@xilinx.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4793f2eb
    • G
      tty: add SPDX identifiers to all remaining files in drivers/tty/ · e3b3d0f5
      Greg Kroah-Hartman 提交于
      It's good to have SPDX identifiers in all files to make it easier to
      audit the kernel tree for correct licenses.
      
      Update the drivers/tty files files with the correct SPDX license
      identifier based on the license text in the file itself.  The SPDX
      identifier is a legally binding shorthand, which can be used instead of
      the full boiler plate text.
      
      This work is based on a script and data from Thomas Gleixner, Philippe
      Ombredanne, and Kate Stewart.
      
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: David Sterba <dsterba@suse.com>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Eric Anholt <eric@anholt.net>
      Cc: Stefan Wahren <stefan.wahren@i2se.com>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Ray Jui <rjui@broadcom.com>
      Cc: Scott Branden <sbranden@broadcom.com>
      Cc: bcm-kernel-feedback-list@broadcom.com
      Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Joachim Eastwood <manabian@gmail.com>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Tobias Klauser <tklauser@distanz.ch>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Vineet Gupta <vgupta@synopsys.com>
      Cc: Richard Genoud <richard.genoud@gmail.com>
      Cc: Alexander Shiyan <shc_work@mail.ru>
      Cc: Baruch Siach <baruch@tkos.co.il>
      Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
      Cc: "Uwe Kleine-König" <kernel@pengutronix.de>
      Cc: Pat Gefre <pfg@sgi.com>
      Cc: "Guilherme G. Piccoli" <gpiccoli@linux.vnet.ibm.com>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: Vladimir Zapolskiy <vz@mleia.com>
      Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
      Cc: Carlo Caione <carlo@caione.org>
      Cc: Kevin Hilman <khilman@baylibre.com>
      Cc: Liviu Dudau <liviu.dudau@arm.com>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: Andy Gross <andy.gross@linaro.org>
      Cc: David Brown <david.brown@linaro.org>
      Cc: "Andreas Färber" <afaerber@suse.de>
      Cc: Kevin Cernekee <cernekee@gmail.com>
      Cc: Laxman Dewangan <ldewangan@nvidia.com>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: Jonathan Hunter <jonathanh@nvidia.com>
      Cc: Barry Song <baohua@kernel.org>
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Alexandre Torgue <alexandre.torgue@st.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Peter Korsgaard <jacmet@sunsite.dk>
      Cc: Timur Tabi <timur@tabi.org>
      Cc: Tony Prisk <linux@prisktech.co.nz>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: "Sören Brinkmann" <soren.brinkmann@xilinx.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e3b3d0f5
  24. 04 11月, 2017 1 次提交
  25. 19 9月, 2017 1 次提交
  26. 29 8月, 2017 2 次提交
  27. 30 7月, 2017 1 次提交
    • A
      serial: core: enforce type for upf_t when copying · a17e74c5
      Andy Shevchenko 提交于
      upf_t is a bitwise defined type and any assignment from different, but
      compatible, types makes static analyzer unhappy.
      
      drivers/tty/serial/serial_core.c:793:29: warning: incorrect type in assignment (different base types)
      drivers/tty/serial/serial_core.c:793:29:    expected int [signed] flags
      drivers/tty/serial/serial_core.c:793:29:    got restricted upf_t [usertype] flags
      drivers/tty/serial/serial_core.c:867:19: warning: incorrect type in assignment (different base types)
      drivers/tty/serial/serial_core.c:867:19:    expected restricted upf_t [usertype] new_flags
      drivers/tty/serial/serial_core.c:867:19:    got int [signed] flags
      
      Enforce corresponding types when upf_t being assigned.
      
      Note, we need __force attribute due to the scope of variable. It's being
      used in user space with plain old type while kernel uses bitwise one.
      Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a17e74c5
  28. 13 6月, 2017 1 次提交
  29. 18 5月, 2017 2 次提交
  30. 09 4月, 2017 1 次提交
  31. 31 3月, 2017 1 次提交
  32. 17 3月, 2017 1 次提交
    • J
      tty: serial_core, remove state checks in uart_poll* · 22077b09
      Jiri Slaby 提交于
      Coverity complains about uart_state checks in polling functions. And it
      is indeed correct. We do something like this:
      	struct uart_state *state = drv->state + line;
      	if (!state)
      		return;
      
      Adding 'line' to drv->state would move the potential NULL pointer to
      something near NULL and the check is useless. Even if we checked pure
      drv->state, nothing guarantees it is not freed and NULLed after the
      check. So if the only user of this interface (kgdboc) needs to assure
      something, this is neither the correct thing, nor place to do so.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: linux-serial@vger.kernel.org
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: kgdb-bugreport@lists.sourceforge.net
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      22077b09
  33. 02 3月, 2017 1 次提交