From 6ccb97491069c7189c6a999efcdd2d9ee7d70b42 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 2 Oct 2017 08:10:12 -0600 Subject: [PATCH] net/route: Fix an error in cache list management. --- net/route/net_cacheroute.c | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/net/route/net_cacheroute.c b/net/route/net_cacheroute.c index 73dce42382c..6dcd17bdbe7 100644 --- a/net/route/net_cacheroute.c +++ b/net/route/net_cacheroute.c @@ -577,24 +577,24 @@ int net_addcache_ipv4(FAR struct net_route_ipv4_s *route) * list, then do nothing. It is already the most recently used. */ - if (prev == NULL) - { - net_unlock_ipv4_cache(); - return OK; - } + if (prev == NULL) + { + net_unlock_ipv4_cache(); + return OK; + } - /* Otherwise, remove the cache entry from the list */ + /* Otherwise, remove the cache entry from the middle or end of + * the list. + */ - if (g_ipv4_cache.tail == cache) - { - g_ipv4_cache.tail = prev; - } - else - { - prev->flink = cache->flink; - } + prev->flink = cache->flink; + if (g_ipv4_cache.tail == cache) + { + g_ipv4_cache.tail = prev; + } - cache->flink = NULL; + cache->flink = NULL; + break; } } @@ -657,24 +657,24 @@ int net_addcache_ipv6(FAR struct net_route_ipv6_s *route) * list, then do nothing. It is already the most recently used. */ - if (prev == NULL) - { - net_unlock_ipv6_cache(); - return OK; - } + if (prev == NULL) + { + net_unlock_ipv6_cache(); + return OK; + } - /* Otherwise, remove the cache entry from the list */ + /* Otherwise, remove the cache entry from the middle or end of + * the list. + */ - if (g_ipv6_cache.tail == cache) - { - g_ipv6_cache.tail = prev; - } - else - { - prev->flink = cache->flink; - } + prev->flink = cache->flink; + if (g_ipv6_cache.tail == cache) + { + g_ipv6_cache.tail = prev; + } - cache->flink = NULL; + cache->flink = NULL; + break; } }