patch "usb: typec: tcpm: fix logbuffer index is wrong if _tcpm_log is" added to usb-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
usb: typec: tcpm: fix logbuffer index is wrong if _tcpm_log is
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
Quoted 1 line
From
d5a4f93511b7000183c0d528739b824752139f79Mon Sep 17 00:00:00 2001
From: Peter Chen <[email protected]>
Date: Tue, 12 Jun 2018 09:53:01 +0800
Subject: usb: typec: tcpm: fix logbuffer index is wrong if _tcpm_log is
re-entered
The port->logbuffer_head may be wrong if the two processes enters _tcpm_log at the mostly same time. The 2nd process enters _tcpm_log before the 1st process update the index, then the 2nd process will not allocate logbuffer, when the 2nd process tries to use log buffer, the index has already updated by the 1st process, so it will get NULL pointer for updated logbuffer, the error message like below:
tcpci 0-0050: Log buffer index 6 is NULL
--- drivers/usb/typec/tcpm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/typec/tcpm.c +4 -3
@@ -418,17 +418,18 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)u64 ts_nsec =local_clock ();unsigned long rem_nsec; +mutex_lock (&port->logbuffer_lock);if (!port->logbuffer[port->logbuffer_head]) { port->logbuffer[port->logbuffer_head] =kzalloc (LOG_BUFFER_ENTRY_SIZE ,GFP_KERNEL ); -if (!port->logbuffer[port->logbuffer_head]) +if (!port->logbuffer[port->logbuffer_head]) { +mutex_unlock (&port->logbuffer_lock);return ; + } }vsnprintf (tmpbuffer,sizeof (tmpbuffer), fmt, args); -mutex_lock (&port->logbuffer_lock); -if (tcpm_log_full (port)) { port->logbuffer_head =max (port->logbuffer_head -1 ,0 );strcpy (tmpbuffer,"overflow" );
Signature · 1 line
2.18.0