[PATCH 2/2] ratp: Test if console exists before using it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 common/ratp/ratp.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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]);
 
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux