]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb: client: make use of smbdirect_connection_grant_recv_credits()
authorStefan Metzmacher <metze@samba.org>
Fri, 17 Oct 2025 13:37:32 +0000 (15:37 +0200)
committerSteve French <stfrench@microsoft.com>
Thu, 16 Apr 2026 02:58:22 +0000 (21:58 -0500)
This already calls atomic_add(new_credits, &sc->recv_io.credits.count),
so there's no need to do it in the caller anymore.

Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/smbdirect.c

index ffdb87d24b47f35fe712622d6b8ecace268d3e12..4cc5dc825ee4fe0eaeb3258d16ca92d932c7debd 100644 (file)
@@ -759,51 +759,6 @@ dma_mapping_failed:
        return rc;
 }
 
-/*
- * Extend the credits to remote peer
- * This implements [MS-SMBD] 3.1.5.9
- * The idea is that we should extend credits to remote peer as quickly as
- * it's allowed, to maintain data flow. We allocate as much receive
- * buffer as possible, and extend the receive credits to remote peer
- * return value: the new credtis being granted.
- */
-static int manage_credits_prior_sending(struct smbdirect_socket *sc)
-{
-       int missing;
-       int available;
-       int new_credits;
-
-       if (atomic_read(&sc->recv_io.credits.count) >= sc->recv_io.credits.target)
-               return 0;
-
-       missing = (int)sc->recv_io.credits.target - atomic_read(&sc->recv_io.credits.count);
-       available = atomic_xchg(&sc->recv_io.credits.available, 0);
-       new_credits = (u16)min3(U16_MAX, missing, available);
-       if (new_credits <= 0) {
-               /*
-                * If credits are available, but not granted
-                * we need to re-add them again.
-                */
-               if (available)
-                       atomic_add(available, &sc->recv_io.credits.available);
-               return 0;
-       }
-
-       if (new_credits < available) {
-               /*
-                * Readd the remaining available again.
-                */
-               available -= new_credits;
-               atomic_add(available, &sc->recv_io.credits.available);
-       }
-
-       /*
-        * Remember we granted the credits
-        */
-       atomic_add(new_credits, &sc->recv_io.credits.count);
-       return new_credits;
-}
-
 /*
  * Check if we need to send a KEEP_ALIVE message
  * The idle connection timer triggers a KEEP_ALIVE message when expires
@@ -1048,7 +1003,7 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
        int data_length;
        struct smbdirect_send_io *request;
        struct smbdirect_data_transfer *packet;
-       int new_credits = 0;
+       u16 new_credits = 0;
        struct smbdirect_send_batch _batch;
 
        if (!batch) {
@@ -1077,7 +1032,7 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
                goto err_wait_credit;
        }
 
-       new_credits = manage_credits_prior_sending(sc);
+       new_credits = smbdirect_connection_grant_recv_credits(sc);
        if (new_credits == 0 &&
            atomic_read(&sc->send_io.credits.count) == 0 &&
            atomic_read(&sc->recv_io.credits.count) == 0) {
@@ -1094,7 +1049,7 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
                        goto err_wait_credit;
                }
 
-               new_credits = manage_credits_prior_sending(sc);
+               new_credits = smbdirect_connection_grant_recv_credits(sc);
        }
 
        request = smbdirect_connection_alloc_send_io(sc);