From 0a939ff218972d517cbca942543e1e45b0d3df76 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 13 Mar 2015 07:21:06 -0600 Subject: [PATCH] Pipes: Fix zero-lenth writes. From Jussi Kivilinna --- drivers/pipes/pipe_common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 026c11ab501..b4cdfc2e297 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -384,6 +384,11 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len) DEBUGASSERT(dev); + if (len == 0) + { + return 0; + } + /* Make sure that we have exclusive access to the device structure */ if (sem_wait(&dev->d_bfsem) < 0) @@ -469,6 +474,11 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t DEBUGASSERT(dev); pipe_dumpbuffer("To PIPE:", (uint8_t*)buffer, len); + if (len == 0) + { + return 0; + } + /* At present, this method cannot be called from interrupt handlers. That is * because it calls sem_wait (via pipecommon_semtake below) and sem_wait cannot * be called from interrupt level. This actually happens fairly commonly