diff options
author | Stefan Agner <stefan.agner@toradex.com> | 2016-11-25 18:20:51 -0800 |
---|---|---|
committer | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2018-12-24 01:27:28 +0100 |
commit | a5afdb17e86e742b4e976d0859f30f48b0eb369d (patch) | |
tree | fda1af691d1e78a1b9261fd7c03c98049cef4117 /drivers/rpmsg | |
parent | 5f5013d1a655d4325fe2a4ee57204c830dbe8e67 (diff) |
rpmsg: imx: do not push data when no reader is available
Pushing data while there is no reader seems to lock/crash the TTY
layer in some way. Especially when a reader gets attached again,
the kernel crashes with
Unable to handle kernel paging request at virtual address 00002248
Also use tty_insert_flip_string which handels the copying and TTY
buffer resizing if necessary.
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
(cherry picked from commit 5aba75e2c61d4044bed21730b7c471822860fac1)
Diffstat (limited to 'drivers/rpmsg')
-rw-r--r-- | drivers/rpmsg/imx_rpmsg_tty.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/rpmsg/imx_rpmsg_tty.c b/drivers/rpmsg/imx_rpmsg_tty.c index db200e03af3a..ab71195ddb83 100644 --- a/drivers/rpmsg/imx_rpmsg_tty.c +++ b/drivers/rpmsg/imx_rpmsg_tty.c @@ -40,9 +40,16 @@ struct rpmsgtty_port { static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) { - int space; - unsigned char *cbuf; + int copied; struct rpmsgtty_port *cport = dev_get_drvdata(&rpdev->dev); + struct tty_struct *tty = dev_get_drvdata(&rpdev->dev); + + /* no one left to give data to, so sleep */ + if (tty == NULL) { + dev_dbg(&rpdev->dev, "waiting for readers, discard len %d\n", + len); + return; + } /* flush the recv-ed none-zero data to tty node */ if (len == 0) @@ -50,18 +57,14 @@ static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len); - print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1, - data, len, true); + print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, + data, len, true); spin_lock_bh(&cport->rx_lock); - space = tty_prepare_flip_string(&cport->port, &cbuf, len); - if (space <= 0) { - dev_err(&rpdev->dev, "No memory for tty_prepare_flip_string\n"); - spin_unlock_bh(&cport->rx_lock); - return -ENOMEM; - } + copied = tty_insert_flip_string(&cport->port, data, len); + if (copied != len) + dev_err_ratelimited(&rpdev->dev, "RX copy to tty layer failed\n"); - memcpy(cbuf, data, len); tty_flip_buffer_push(&cport->port); spin_unlock_bh(&cport->rx_lock); |