git: 6c9b92e741f0 - stable/13 - sctp: improve consistency

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Thu, 11 Jan 2024 12:19:22 UTC
The branch stable/13 has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=6c9b92e741f0f878deff8ad3553239155c517a7a

commit 6c9b92e741f0f878deff8ad3553239155c517a7a
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2023-07-28 12:36:11 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2024-01-11 12:18:37 +0000

    sctp: improve consistency
    
    This is simplifying a patch to address PR 260116.
    
    PR:             260116
    
    (cherry picked from commit b279e84a47ddb59e55b5a3cec31c51cd41bf0dc3)
---
 sys/netinet/sctputil.c | 8 ++------
 sys/netinet/sctputil.h | 6 +-----
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index d9cfe12861d7..e34cadd27bc8 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -5040,11 +5040,7 @@ sctp_free_bufspace(struct sctp_tcb *stcb, struct sctp_association *asoc,
 	if ((stcb->sctp_socket != NULL) &&
 	    (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) ||
 	    ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE)))) {
-		if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) {
-			atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size);
-		} else {
-			stcb->sctp_socket->so_snd.sb_cc = 0;
-		}
+		SCTP_SAVE_ATOMIC_DECREMENT(&stcb->sctp_socket->so_snd.sb_cc, tp1->book_size);
 	}
 }
 
@@ -6121,7 +6117,7 @@ get_more_data:
 					if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
 						sctp_sblog(&so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBFREE, (int)cp_len);
 					}
-					atomic_subtract_int(&so->so_rcv.sb_cc, (int)cp_len);
+					SCTP_SAVE_ATOMIC_DECREMENT(&so->so_rcv.sb_cc, (int)cp_len);
 					if ((control->do_not_ref_stcb == 0) &&
 					    stcb) {
 						atomic_subtract_int(&stcb->asoc.sb_cc, (int)cp_len);
diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h
index 1f450a264939..9026fd09a0be 100644
--- a/sys/netinet/sctputil.h
+++ b/sys/netinet/sctputil.h
@@ -251,11 +251,7 @@ do { \
 		} \
 		if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
 		    (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
-			if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \
-				atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \
-			} else { \
-				stcb->sctp_socket->so_snd.sb_cc = 0; \
-			} \
+			SCTP_SAVE_ATOMIC_DECREMENT(&stcb->sctp_socket->so_snd.sb_cc, sp->length); \
 		} \
 	} \
 } while (0)