mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] ratp: Free buffers
@ 2020-05-20  8:44 Sascha Hauer
  2020-05-20  8:44 ` [PATCH 2/2] ratp: Test if console exists before using it Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2020-05-20  8:44 UTC (permalink / raw)
  To: Barebox List

recvbuf and sendbuf are never freed, free them to avoid memory holes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/ratp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/ratp.c b/lib/ratp.c
index 8167c5bd4c..1901cc8ea8 100644
--- a/lib/ratp.c
+++ b/lib/ratp.c
@@ -1714,6 +1714,8 @@ void ratp_close(struct ratp *ratp)
 	list_for_each_entry_safe(msg, tmp, &ri->sendmsg, list)
 		ratp_msg_done(ri, msg, -ECONNRESET);
 
+	free(ri->recvbuf);
+	free(ri->sendbuf);
 	free(ri);
 	ratp->internal = NULL;
 
-- 
2.26.2


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] ratp: Test if console exists before using it
  2020-05-20  8:44 [PATCH 1/2] ratp: Free buffers Sascha Hauer
@ 2020-05-20  8:44 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-05-20  8:44 UTC (permalink / raw)
  To: Barebox List

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>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-20  8:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20  8:44 [PATCH 1/2] ratp: Free buffers Sascha Hauer
2020-05-20  8:44 ` [PATCH 2/2] ratp: Test if console exists before using it Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox