From e6a025abdd2fcd60962d8f6a1f52048e52e35c78 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 13 May 2019 16:59:08 -0700 Subject: serdev: Do not call .receive_buf() callback recursively 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 Tested-by: Cory Tusar Signed-off-by: Sascha Hauer --- common/serdev.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'common') diff --git a/common/serdev.c b/common/serdev.c index 4a6dbefe61..3e0da0846e 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) -- cgit v1.2.3