diff options
author | Stefan Agner <stefan.agner@toradex.com> | 2016-11-25 18:20:51 -0800 |
---|---|---|
committer | Philippe Schenker <philippe.schenker@toradex.com> | 2019-05-24 11:34:14 +0200 |
commit | 4f220c4dc53a4780f30fae7ccb69b652180484ca (patch) | |
tree | 218d2b36f81bb2635b1e6d1eb130843aa261f990 /drivers/rpmsg/imx_rpmsg_tty.c | |
parent | 3303db8896a1d050ba7858ac680a328c875fe238 (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/imx_rpmsg_tty.c')
-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 8228c0da287a..fd1750a00677 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); |