diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-08-18 14:07:52 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-08-18 14:07:52 +0000 |
commit | aad68a29984f20c2888f6897c2597d80df6bf8ee (patch) | |
tree | 2f1212b1ea86e4bedd984788699a03ad124840a8 /nuttx/drivers/can.c | |
parent | a2ed85e342d6705578a222f3a1e0bf9c0ae08e21 (diff) | |
download | px4-nuttx-aad68a29984f20c2888f6897c2597d80df6bf8ee.tar.gz px4-nuttx-aad68a29984f20c2888f6897c2597d80df6bf8ee.tar.bz2 px4-nuttx-aad68a29984f20c2888f6897c2597d80df6bf8ee.zip |
Fix a semphore overflow problem in the CAN driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3890 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/can.c')
-rw-r--r-- | nuttx/drivers/can.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/nuttx/drivers/can.c b/nuttx/drivers/can.c index accafce3c..fc70678a7 100644 --- a/nuttx/drivers/can.c +++ b/nuttx/drivers/can.c @@ -50,6 +50,7 @@ #include <string.h> #include <semaphore.h> #include <fcntl.h> +#include <assert.h> #include <errno.h> #include <debug.h> @@ -443,7 +444,11 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer, size_t do { + DEBUGASSERT(dev->cd_ntxwaiters < 255); + dev->cd_ntxwaiters++; ret = sem_wait(&fifo->cf_sem); + dev->cd_ntxwaiters--; + if (ret < 0 && errno != EINTR) { ret = -errno; @@ -750,9 +755,12 @@ int can_txdone(FAR struct can_dev_s *dev) /* Send the next message in the FIFO */ ret = can_xmit(dev); - if (ret == OK) + + /* Are there any threads waiting for space in the TX FIFO? */ + + if (ret == OK && dev->cd_ntxwaiters > 0) { - /* Inform any waiting threads that new xmit space is available */ + /* Yes.. Inform them that new xmit space is available */ ret = sem_post(&dev->cd_xmit.cf_sem); } |