diff options
author | Michael Brown <mcb30@ipxe.org> | 2010-11-08 02:51:18 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2010-11-08 03:15:28 +0000 |
commit | ea631f6fb8dbffe3081ecf29eafa62ecd38ec64f (patch) | |
tree | f27d347fc48c524e172a4bdeea80976a26b9904a /src/net/netdevice.c | |
parent | 295ba15bd670038e1f22d3c72151036337298a1c (diff) | |
download | ipxe-ea631f6fb8dbffe3081ecf29eafa62ecd38ec64f.tar.gz |
[list] Add list_first_entry()
There are several points in the iPXE codebase where
list_for_each_entry() is (ab)used to extract only the first entry from
a list. Add a macro list_first_entry() to make this code easier to
read.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/netdevice.c')
-rw-r--r-- | src/net/netdevice.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 894b7e79..3a01a58d 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -328,11 +328,12 @@ void netdev_poll ( struct net_device *netdev ) { struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev ) { struct io_buffer *iobuf; - list_for_each_entry ( iobuf, &netdev->rx_queue, list ) { - list_del ( &iobuf->list ); - return iobuf; - } - return NULL; + iobuf = list_first_entry ( &netdev->rx_queue, struct io_buffer, list ); + if ( ! iobuf ) + return NULL; + + list_del ( &iobuf->list ); + return iobuf; } /** @@ -592,12 +593,13 @@ struct net_device * find_netdev_by_location ( unsigned int bus_type, struct net_device * last_opened_netdev ( void ) { struct net_device *netdev; - list_for_each_entry ( netdev, &open_net_devices, open_list ) { - assert ( netdev_is_open ( netdev ) ); - return netdev; - } + netdev = list_first_entry ( &open_net_devices, struct net_device, + list ); + if ( ! netdev ) + return NULL; - return NULL; + assert ( netdev_is_open ( netdev ) ); + return netdev; } /** |