Networking: Add a test to see a device pointer is still valid
This commit is contained in:
parent
2102892e7b
commit
f10fdf7ad4
@ -49,6 +49,7 @@
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -123,6 +124,16 @@ FAR struct devif_callback_s *
|
||||
|
||||
if (dev)
|
||||
{
|
||||
/* Verify that the device is valid */
|
||||
|
||||
if (!netdev_verify(dev))
|
||||
{
|
||||
/* No.. release the callback structure and fail */
|
||||
|
||||
devif_callback_free(NULL, NULL, list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->nxtdev = dev->d_devcb;
|
||||
dev->d_devcb = ret;
|
||||
}
|
||||
@ -181,10 +192,15 @@ void devif_callback_free(FAR struct net_driver_s *dev,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Remove the callback structure from the device notification list if
|
||||
* it is supposed to be in the device notification list AND if the
|
||||
* device pointer is still valid.
|
||||
*/
|
||||
|
||||
if (dev && netdev_verify(dev))
|
||||
{
|
||||
/* Find the callback structure in the device event list */
|
||||
|
||||
if (dev)
|
||||
{
|
||||
for (prev = NULL, curr = dev->d_devcb;
|
||||
curr && curr != cb;
|
||||
prev = curr, curr = curr->nxtdev);
|
||||
@ -205,10 +221,14 @@ void devif_callback_free(FAR struct net_driver_s *dev,
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the callback structure in the connection event list */
|
||||
/* Remove the callback structure from the data notification list if
|
||||
* it is supposed to be in the data notification list.
|
||||
*/
|
||||
|
||||
if (list)
|
||||
{
|
||||
/* Find the callback structure in the connection event list */
|
||||
|
||||
for (prev = NULL, curr = *list;
|
||||
curr && curr != cb;
|
||||
prev = curr, curr = curr->nxtconn);
|
||||
|
@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# net/netdev/Make.defs
|
||||
#
|
||||
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -38,7 +38,7 @@
|
||||
NETDEV_CSRCS += netdev_register.c netdev_ioctl.c netdev_txnotify.c
|
||||
NETDEV_CSRCS += netdev_findbyname.c netdev_findbyaddr.c netdev_count.c
|
||||
NETDEV_CSRCS += netdev_foreach.c netdev_unregister.c netdev_sem.c
|
||||
NETDEV_CSRCS += netdev_carrier.c netdev_default.c
|
||||
NETDEV_CSRCS += netdev_carrier.c netdev_default.c netdev_verify.c
|
||||
|
||||
ifeq ($(CONFIG_NET_RXAVAIL),y)
|
||||
NETDEV_CSRCS += netdev_rxnotify.c
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
@ -124,6 +125,19 @@ void netdev_semgive(void);
|
||||
void netdev_ifup(FAR struct net_driver_s *dev);
|
||||
void netdev_ifdown(FAR struct net_driver_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_verify
|
||||
*
|
||||
* Description:
|
||||
* Verify that the specified device still exists
|
||||
*
|
||||
* Assumptions:
|
||||
* The caller has locked the network.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool netdev_verify(FAR struct net_driver_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_findbyname
|
||||
*
|
||||
|
@ -89,9 +89,9 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct net_driver_s *netdev_findbyname(const char *ifname)
|
||||
FAR struct net_driver_s *netdev_findbyname(FAR const char *ifname)
|
||||
{
|
||||
struct net_driver_s *dev;
|
||||
FAR struct net_driver_s *dev;
|
||||
if (ifname)
|
||||
{
|
||||
netdev_semtake();
|
||||
|
Loading…
Reference in New Issue
Block a user