mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] serdev: Do not call .receive_buf() callback recursively
@ 2019-05-13 23:59 Andrey Smirnov
  2019-05-14  1:49 ` Cory Tusar
  2019-05-15  8:10 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Andrey Smirnov @ 2019-05-13 23:59 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Code implementing .receive_buf() callback can potentially call
serdev_device_write(), which will call serdev_device_poller(). We need
to make sure that such a call is a no-op in order to prevent
corrupting shared data buffer as well as breaking .receive_buf
callback that most likely does not expect that to happen.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 common/serdev.c  | 6 ++++++
 include/serdev.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/common/serdev.c b/common/serdev.c
index 4a6dbefe6..3e0da0846 100644
--- a/common/serdev.c
+++ b/common/serdev.c
@@ -9,6 +9,10 @@ static void serdev_device_poller(void *context)
 	unsigned char *buf = serdev->buf;
 	int ret, len;
 
+	if (serdev->locked)
+		return;
+
+	serdev->locked = true;
 	/*
 	 * Since this callback is a part of poller infrastructure we
 	 * want to use _non_interruptible version of the function
@@ -37,6 +41,8 @@ static void serdev_device_poller(void *context)
 	} else {
 		poller_async_cancel(&serdev->poller);
 	}
+
+	serdev->locked = false;
 }
 
 static int serdev_device_set_polling_interval(struct param_d *param, void *serdev)
diff --git a/include/serdev.h b/include/serdev.h
index f5d34f527..29030538e 100644
--- a/include/serdev.h
+++ b/include/serdev.h
@@ -14,6 +14,7 @@
  * @poller		Async poller used to poll this serdev
  * @polling_interval:	Async poller periodicity
  * @polling_window:	Duration of a single busy loop poll
+ * @locked:		Lock to prevent recursive polling
  * @receive_buf:	Function called with data received from device;
  *			returns number of bytes accepted;
  */
@@ -24,6 +25,7 @@ struct serdev_device {
 	struct poller_async poller;
 	uint64_t polling_interval;
 	uint64_t polling_window;
+	bool locked;
 
 	int (*receive_buf)(struct serdev_device *, const unsigned char *,
 			   size_t);
-- 
2.21.0


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

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

* Re: [PATCH] serdev: Do not call .receive_buf() callback recursively
  2019-05-13 23:59 [PATCH] serdev: Do not call .receive_buf() callback recursively Andrey Smirnov
@ 2019-05-14  1:49 ` Cory Tusar
  2019-05-15  8:10 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Cory Tusar @ 2019-05-14  1:49 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

On Mon, May 13, 2019 at 04:59:08PM -0700, Andrey Smirnov wrote:
> Code implementing .receive_buf() callback can potentially call
> serdev_device_write(), which will call serdev_device_poller(). We need
> to make sure that such a call is a no-op in order to prevent
> corrupting shared data buffer as well as breaking .receive_buf
> callback that most likely does not expect that to happen.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>

Tested-by: Cory Tusar <cory.tusar@zii.aero>


--
Cory Tusar
Senior Software Engineer
Zodiac Inflight Innovations
2929 E Imperial Hwy, Suite 170
Brea, CA 92821
(714) 203-0519

www.safran-aerosystems.com

________________________________

This email and any files transmitted with it are confidential & proprietary to Zodiac Inflight Innovations. This information is intended solely for the use of the individual or entity to which it is addressed. Access or transmittal of the information contained in this e-mail, in full or in part, to any other organization or persons is not authorized.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] serdev: Do not call .receive_buf() callback recursively
  2019-05-13 23:59 [PATCH] serdev: Do not call .receive_buf() callback recursively Andrey Smirnov
  2019-05-14  1:49 ` Cory Tusar
@ 2019-05-15  8:10 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2019-05-15  8:10 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Mon, May 13, 2019 at 04:59:08PM -0700, Andrey Smirnov wrote:
> Code implementing .receive_buf() callback can potentially call
> serdev_device_write(), which will call serdev_device_poller(). We need
> to make sure that such a call is a no-op in order to prevent
> corrupting shared data buffer as well as breaking .receive_buf
> callback that most likely does not expect that to happen.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  common/serdev.c  | 6 ++++++
>  include/serdev.h | 2 ++
>  2 files changed, 8 insertions(+)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2019-05-15  8:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 23:59 [PATCH] serdev: Do not call .receive_buf() callback recursively Andrey Smirnov
2019-05-14  1:49 ` Cory Tusar
2019-05-15  8:10 ` Sascha Hauer

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