From 53aff3a78c70a0c9edb970cf7de7fd9d2403b299 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Tue, 7 Nov 2006 09:48:19 +0000 Subject: [PATCH] [NET] back: Fix wrap to zero in transmit credit scheduler. This could happen when credit_bytes == ~0UL (i.e., scheduling is 'disabled'). Signed-off-by: Kirk Allan --- linux-2.6-xen-sparse/drivers/xen/netback/netback.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index 5706322a8f..c4fb3e4383 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -814,7 +814,7 @@ void netif_deschedule_work(netif_t *netif) static void tx_add_credit(netif_t *netif) { - unsigned long max_burst; + unsigned long max_burst, max_credit; /* * Allow a burst big enough to transmit a jumbo packet of up to 128kB. @@ -824,9 +824,10 @@ static void tx_add_credit(netif_t *netif) max_burst = min(max_burst, 131072UL); max_burst = max(max_burst, netif->credit_bytes); - netif->remaining_credit = min(netif->remaining_credit + - netif->credit_bytes, - max_burst); + /* Take care that adding a new chunk of credit doesn't wrap to zero. */ + max_credit = max(netif->remaining_credit + netif->credit_bytes, ~0UL); + + netif->remaining_credit = min(max_credit, max_burst); } static void tx_credit_callback(unsigned long data) -- 2.30.2