Skip to content

Commit 3a25286

Browse files
zhhyu7xiaoxiang781216
authored andcommitted
usbdev/cdcncm: fix notify overwrite issue
we need to wait until the previous notify message is done to send a new notify message Signed-off-by: zhanghongyu <[email protected]>
1 parent 9f9075c commit 3a25286

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

drivers/usbdev/cdcncm.c

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ static void cdcncm_disconnect(FAR struct usbdevclass_driver_s *driver,
417417

418418
static void cdcncm_ep0incomplete(FAR struct usbdev_ep_s *ep,
419419
FAR struct usbdev_req_s *req);
420+
static void cdcncm_intcomplete(FAR struct usbdev_ep_s *ep,
421+
FAR struct usbdev_req_s *req);
420422
static void cdcncm_rdcomplete(FAR struct usbdev_ep_s *ep,
421423
FAR struct usbdev_req_s *req);
422424
static void cdcncm_wrcomplete(FAR struct usbdev_ep_s *ep,
@@ -1424,6 +1426,39 @@ static void cdcncm_ep0incomplete(FAR struct usbdev_ep_s *ep,
14241426
}
14251427
}
14261428

1429+
/****************************************************************************
1430+
* Name: cdcncm_intcomplete
1431+
*
1432+
* Description:
1433+
* Handle completion of interrupt write request. This function probably
1434+
* executes in the context of an interrupt handler.
1435+
*
1436+
****************************************************************************/
1437+
1438+
static void cdcncm_intcomplete(FAR struct usbdev_ep_s *ep,
1439+
FAR struct usbdev_req_s *req)
1440+
{
1441+
FAR struct cdcncm_driver_s *self = (FAR struct cdcncm_driver_s *)ep->priv;
1442+
1443+
if (req->result || req->xfrd != req->len)
1444+
{
1445+
uerr("result: %hd, xfrd: %hu\n", req->result, req->xfrd);
1446+
}
1447+
1448+
if (self->notify != NCM_NOTIFY_NONE)
1449+
{
1450+
cdcncm_notify_worker(self);
1451+
}
1452+
else if (!self->isncm)
1453+
{
1454+
/* After the NIC information is synchronized, subsequent
1455+
* notifications are all related to the mbim control.
1456+
*/
1457+
1458+
self->notify = NCM_NOTIFY_RESPONSE_AVAILABLE;
1459+
}
1460+
}
1461+
14271462
/****************************************************************************
14281463
* Name: cdcncm_rdcomplete
14291464
*
@@ -1715,25 +1750,16 @@ static void cdcncm_notify_worker(FAR void *arg)
17151750
FAR struct cdcncm_driver_s *self = arg;
17161751
int ret;
17171752

1718-
while (self->notify != NCM_NOTIFY_NONE)
1753+
ret = cdcncm_notify(self);
1754+
if (ret > 0)
17191755
{
1720-
ret = cdcncm_notify(self);
1721-
if (ret > 0)
1722-
{
1723-
FAR struct usbdev_req_s *notifyreq = self->notifyreq;
1756+
FAR struct usbdev_req_s *notifyreq = self->notifyreq;
17241757

1725-
notifyreq->len = ret;
1726-
notifyreq->flags = USBDEV_REQFLAGS_NULLPKT;
1758+
notifyreq->len = ret;
1759+
notifyreq->flags = USBDEV_REQFLAGS_NULLPKT;
17271760

1728-
EP_SUBMIT(self->epint, notifyreq);
1729-
}
1761+
EP_SUBMIT(self->epint, notifyreq);
17301762
}
1731-
1732-
/* After the NIC information is synchronized, subsequent notifications
1733-
* are all related to the mbim control
1734-
*/
1735-
1736-
self->notify = NCM_NOTIFY_RESPONSE_AVAILABLE;
17371763
}
17381764

17391765
/****************************************************************************
@@ -2399,7 +2425,7 @@ static int cdcncm_bind(FAR struct usbdevclass_driver_s *driver,
23992425
goto error;
24002426
}
24012427

2402-
self->notifyreq->callback = cdcncm_wrcomplete;
2428+
self->notifyreq->callback = cdcncm_intcomplete;
24032429

24042430
/* Pre-allocate read requests. The buffer size is NTB_DEFAULT_IN_SIZE. */
24052431

0 commit comments

Comments
 (0)