summaryrefslogtreecommitdiffstats
path: root/common/serdev.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-05-13 16:59:08 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2019-05-15 10:09:41 +0200
commite6a025abdd2fcd60962d8f6a1f52048e52e35c78 (patch)
tree78adf618a7ed404cbe9e15f77396f2777f0f7a68 /common/serdev.c
parente0600e1fe20856cfbefb2d8f798076c7694a9e24 (diff)
downloadbarebox-e6a025abdd2fcd60962d8f6a1f52048e52e35c78.tar.gz
barebox-e6a025abdd2fcd60962d8f6a1f52048e52e35c78.tar.xz
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 <andrew.smirnov@gmail.com> Tested-by: Cory Tusar <cory.tusar@zii.aero> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/serdev.c')
-rw-r--r--common/serdev.c6
1 files changed, 6 insertions, 0 deletions
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)