Skip to content

Commit f9d690b

Browse files
satya priyagregkh
satya priya
authored andcommitted
tty: serial: qcom_geni_serial: Allocate port->rx_fifo buffer in probe
To fix the RX cancel command failure, rx_fifo buffer needs to be flushed in stop_rx() by calling handle_rx().In handle_rx() the data in rx_fifo buffer is read and then dropped, not sent to upper layers. If set_termios is called before startup, by this time memory is not allocated to port->rx_fifo buffer, which leads to a NULL pointer dereference. To avoid this NULL pointer dereference allocate memory to port->rx_fifo in probe itself. Signed-off-by: satya priya <skakit@codeaurora.org> Reported-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/1583477228-32231-2-git-send-email-skakit@codeaurora.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9a8da60 commit f9d690b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

drivers/tty/serial/qcom_geni_serial.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct qcom_geni_serial_port {
120120
unsigned int baud;
121121
unsigned int tx_bytes_pw;
122122
unsigned int rx_bytes_pw;
123-
u32 *rx_fifo;
123+
void *rx_fifo;
124124
u32 loopback;
125125
bool brk;
126126

@@ -514,7 +514,6 @@ static int handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
514514

515515
static int handle_rx_uart(struct uart_port *uport, u32 bytes, bool drop)
516516
{
517-
unsigned char *buf;
518517
struct tty_port *tport;
519518
struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
520519
u32 num_bytes_pw = port->tx_fifo_width / BITS_PER_BYTE;
@@ -526,8 +525,7 @@ static int handle_rx_uart(struct uart_port *uport, u32 bytes, bool drop)
526525
if (drop)
527526
return 0;
528527

529-
buf = (unsigned char *)port->rx_fifo;
530-
ret = tty_insert_flip_string(tport, buf, bytes);
528+
ret = tty_insert_flip_string(tport, port->rx_fifo, bytes);
531529
if (ret != bytes) {
532530
dev_err(uport->dev, "%s:Unable to push data ret %d_bytes %d\n",
533531
__func__, ret, bytes);
@@ -892,12 +890,6 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport)
892890
false, false, true);
893891
geni_se_init(&port->se, UART_RX_WM, port->rx_fifo_depth - 2);
894892
geni_se_select_mode(&port->se, GENI_SE_FIFO);
895-
if (!uart_console(uport)) {
896-
port->rx_fifo = devm_kcalloc(uport->dev,
897-
port->rx_fifo_depth, sizeof(u32), GFP_KERNEL);
898-
if (!port->rx_fifo)
899-
return -ENOMEM;
900-
}
901893
port->setup = true;
902894

903895
return 0;
@@ -1308,6 +1300,13 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
13081300
port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
13091301
port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
13101302

1303+
if (!console) {
1304+
port->rx_fifo = devm_kcalloc(uport->dev,
1305+
port->rx_fifo_depth, sizeof(u32), GFP_KERNEL);
1306+
if (!port->rx_fifo)
1307+
return -ENOMEM;
1308+
}
1309+
13111310
port->name = devm_kasprintf(uport->dev, GFP_KERNEL,
13121311
"qcom_geni_serial_%s%d",
13131312
uart_console(uport) ? "console" : "uart", uport->line);

0 commit comments

Comments
 (0)