From 04dc2fe4e1aca38f4ebe3d6d95422abd4085106e Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 5 Apr 2016 09:54:51 +0300 Subject: [PATCH] net: buf: Check we are not overflowing free buf count Make sure the number of free bufs will never go over the allocated limit. This is only used for debugging when printing the free buf count so this is not very serious issue. Change-Id: Icb5e34e969cbf07280c24966659addcf32829f7c Signed-off-by: Jukka Rissanen --- net/ip/ip_buf.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/ip/ip_buf.c b/net/ip/ip_buf.c index d97e453c042..5e6a1212d02 100644 --- a/net/ip/ip_buf.c +++ b/net/ip/ip_buf.c @@ -80,7 +80,11 @@ static inline void inc_free_rx_bufs(struct net_buf *buf) return; } - num_free_rx_bufs++; + if (num_free_rx_bufs > IP_BUF_RX_SIZE) { + num_free_rx_bufs = IP_BUF_RX_SIZE; + } else { + num_free_rx_bufs++; + } } static inline void dec_free_tx_bufs(struct net_buf *buf) @@ -102,7 +106,11 @@ static inline void inc_free_tx_bufs(struct net_buf *buf) return; } - num_free_tx_bufs++; + if (num_free_tx_bufs > IP_BUF_TX_SIZE) { + num_free_tx_bufs = IP_BUF_TX_SIZE; + } else { + num_free_tx_bufs++; + } } static inline int get_frees(enum ip_buf_type type)