From 824261d3bc8467f6220061f43d22321f1ce50bc3 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 22 Aug 2013 15:12:00 +0800 Subject: [PATCH 1/2] dev/portal: add checks on oflag It does not make sense to open portal without a flag. One should open a portal with RT_DEVICE_OFLAG_RDWR in most cases. --- components/drivers/src/portal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/drivers/src/portal.c b/components/drivers/src/portal.c index 82d9d4e802..26977a8259 100644 --- a/components/drivers/src/portal.c +++ b/components/drivers/src/portal.c @@ -53,6 +53,9 @@ static rt_err_t _portal_open(rt_device_t dev, rt_uint16_t oflag) RT_ASSERT(dev); + if (!oflag) + return -RT_ERROR; + portal = (struct rt_portal_device*)dev; if (oflag & RT_DEVICE_OFLAG_RDONLY) From 246bdde8de4167065b4a52530a9c7be85c189dd8 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 22 Aug 2013 16:43:06 +0800 Subject: [PATCH 2/2] dev/portal: fix bug in portal callback forwarding When forwarding rx/tx callback from the underlaying device(pipe), the "dev" argument should be the portal. So the portal callback could think itself as called. --- components/drivers/src/portal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/drivers/src/portal.c b/components/drivers/src/portal.c index 26977a8259..779812e9ca 100644 --- a/components/drivers/src/portal.c +++ b/components/drivers/src/portal.c @@ -116,7 +116,8 @@ static rt_err_t _portal_rx_indicate(rt_device_t dev, rt_size_t size) pipe = (struct rt_pipe_device*)dev; if (pipe->read_portal->parent.rx_indicate) - return pipe->read_portal->parent.rx_indicate(dev, size); + return pipe->read_portal->parent.rx_indicate( + (rt_device_t)pipe->read_portal, size); return -RT_ENOSYS; } @@ -130,7 +131,8 @@ static rt_err_t _portal_tx_complete(rt_device_t dev, void *buf) pipe = (struct rt_pipe_device*)dev; if (pipe->write_portal->parent.tx_complete) - return pipe->write_portal->parent.tx_complete(dev, buf); + return pipe->write_portal->parent.tx_complete( + (rt_device_t)pipe->write_portal, buf); return -RT_ENOSYS; }