summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-05-19 20:54:30 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-05-20 10:41:53 +0200
commitc51dfe31e7725628ba52060024a7eb7083620557 (patch)
tree57a2af1e9d61627db0974b4bc6ad2dfcec320327
parent325608a96cec194d04b379ded8afdce41d525658 (diff)
downloadbarebox-c51dfe31e7725628ba52060024a7eb7083620557.tar.gz
barebox-c51dfe31e7725628ba52060024a7eb7083620557.tar.xz
ratp: Test if console exists before using it
Consoles can be unregistered, this happens for example when barebox implements the barebox serial USB gadget. Before using the console we have to explicitly test if the pointer is still valid each time. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/ratp/ratp.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c
index ca751a30eb..def1ceb020 100644
--- a/common/ratp/ratp.c
+++ b/common/ratp/ratp.c
@@ -97,11 +97,24 @@ static int init_ratp_command_list(void)
late_initcall(init_ratp_command_list);
+static bool console_exists(struct console_device *cdev)
+{
+ struct console_device *cs;
+
+ list_for_each_entry(cs, &console_list, list)
+ if (cs == cdev)
+ return true;
+ return false;
+}
+
static int console_recv(struct ratp *r, uint8_t *data)
{
struct ratp_ctx *ctx = container_of(r, struct ratp_ctx, ratp);
struct console_device *cdev = ctx->cdev;
+ if (!console_exists(cdev))
+ return -ENODEV;
+
if (ctx->have_synch) {
ctx->have_synch = 0;
*data = 0x01;
@@ -123,6 +136,9 @@ static int console_send(struct ratp *r, void *pkt, int len)
const uint8_t *buf = pkt;
int i;
+ if (!console_exists(cdev))
+ return -ENODEV;
+
for (i = 0; i < len; i++)
cdev->putc(cdev, buf[i]);