Commit d5a4f935 authored by Peter Chen's avatar Peter Chen Committed by Greg Kroah-Hartman

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

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Jun Li <jun.li@nxp.com>
Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: stable <stable@vger.kernel.org>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9578bcd0
...@@ -418,17 +418,18 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) ...@@ -418,17 +418,18 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
u64 ts_nsec = local_clock(); u64 ts_nsec = local_clock();
unsigned long rem_nsec; unsigned long rem_nsec;
mutex_lock(&port->logbuffer_lock);
if (!port->logbuffer[port->logbuffer_head]) { if (!port->logbuffer[port->logbuffer_head]) {
port->logbuffer[port->logbuffer_head] = port->logbuffer[port->logbuffer_head] =
kzalloc(LOG_BUFFER_ENTRY_SIZE, GFP_KERNEL); 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; return;
}
} }
vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args); vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
mutex_lock(&port->logbuffer_lock);
if (tcpm_log_full(port)) { if (tcpm_log_full(port)) {
port->logbuffer_head = max(port->logbuffer_head - 1, 0); port->logbuffer_head = max(port->logbuffer_head - 1, 0);
strcpy(tmpbuffer, "overflow"); strcpy(tmpbuffer, "overflow");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment