[PATCH v1 1/1] serial: core: make static analyzer happy about locks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Static analyzer can not see balanced locking if the lock is acquired and
released conditionally. Add __acquire() and __release() markings in the right
locations so that sparse isn't tripped up on the conditional locking.

drivers/tty/serial/serial_core.c:131:17: warning: context imbalance in 'uart_stop' - unexpected unlock
include/linux/spinlock.h:362:9: warning: context imbalance in 'uart_start' - unexpected unlock
include/linux/spinlock.h:362:9: warning: context imbalance in 'uart_put_char' - unexpected unlock
include/linux/spinlock.h:362:9: warning: context imbalance in 'uart_write' - unexpected unlock
include/linux/spinlock.h:362:9: warning: context imbalance in 'uart_write_room' - unexpected unlock
include/linux/spinlock.h:362:9: warning: context imbalance in 'uart_chars_in_buffer' - unexpected unlock
include/linux/spinlock.h:362:9: warning: context imbalance in 'uart_flush_buffer' - unexpected unlock

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
 drivers/tty/serial/serial_core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index f2303f3..ff90c8e 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -82,6 +82,8 @@ static inline void uart_port_deref(struct uart_port *uport)
 		struct uart_port *__uport = uart_port_ref(state);	\
 		if (__uport)						\
 			spin_lock_irqsave(&__uport->lock, flags);	\
+		else							\
+			__acquire(&__uport->lock);			\
 		__uport;						\
 	})
 
@@ -90,6 +92,8 @@ static inline void uart_port_deref(struct uart_port *uport)
 		struct uart_port *__uport = uport;			\
 		if (__uport)						\
 			spin_unlock_irqrestore(&__uport->lock, flags);	\
+		else							\
+			__release(&__uport->lock);			\
 		uart_port_deref(__uport);				\
 	})
 
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux