From 33f903178e7567f4ece8da31743a279e829235d8 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Mon, 24 Oct 2022 11:28:25 +0900 Subject: [PATCH] drivers/modem/alt1250: Fix poll function Notify only when there are available events. --- drivers/modem/alt1250/alt1250.c | 52 +++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/modem/alt1250/alt1250.c b/drivers/modem/alt1250/alt1250.c index 972fea97ff..ee093d47ea 100644 --- a/drivers/modem/alt1250/alt1250.c +++ b/drivers/modem/alt1250/alt1250.c @@ -279,6 +279,25 @@ static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev, nxmutex_unlock(&dev->evtmaplock); } +/**************************************************************************** + * Name: is_evtbitmap_avail + ****************************************************************************/ + +static int is_evtbitmap_avail(FAR struct alt1250_dev_s *dev) +{ + int ret; + + nxmutex_lock(&dev->evtmaplock); + + /* 0 means it is not available, otherwise it is available. */ + + ret = (0ULL != dev->evtbitmap); + + nxmutex_unlock(&dev->evtmaplock); + + return ret; +} + /**************************************************************************** * Name: add_evtbuff ****************************************************************************/ @@ -1195,6 +1214,7 @@ static int alt1250_poll(FAR struct file *filep, FAR struct pollfd *fds, { FAR struct inode *inode; FAR struct alt1250_dev_s *dev; + int ret = OK; /* Get our private data structure */ @@ -1204,12 +1224,40 @@ static int alt1250_poll(FAR struct file *filep, FAR struct pollfd *fds, dev = (FAR struct alt1250_dev_s *)inode->i_private; DEBUGASSERT(dev); + /* Are we setting up the poll? Or tearing it down? */ + if (setup) { - poll_notify(&fds, 1, POLLIN); + /* Ignore waits that do not include POLLIN */ + + if ((fds->events & POLLIN) == 0) + { + ret = -EDEADLK; + goto errout; + } + + nxmutex_lock(&dev->pfdlock); + + if (is_evtbitmap_avail(dev)) + { + poll_notify(&fds, 1, POLLIN); + } + else + { + dev->pfd = fds; + } + + nxmutex_unlock(&dev->pfdlock); + } + else + { + nxmutex_lock(&dev->pfdlock); + dev->pfd = NULL; + nxmutex_unlock(&dev->pfdlock); } - return OK; +errout: + return ret; } /****************************************************************************