]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usbip: Use min to simplify stub_send_ret_submit
authorThorsten Blum <thorsten.blum@linux.dev>
Fri, 17 Oct 2025 09:19:23 +0000 (11:19 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Oct 2025 08:58:31 +0000 (10:58 +0200)
Use min() to improve stub_send_ret_submit(). Change the local variable
'size' from 'int' to 'unsigned int' to prevent a signedness error and to
match the resulting type.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20251017091923.1694-2-thorsten.blum@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/usbip/stub_tx.c

index 7eb2e074012a4c59f10a5f64a12d0a3ed18a3e97..55919c3762ba1d858aaa6fac38ef88ad999e6fbd 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/kthread.h>
+#include <linux/minmax.h>
 #include <linux/socket.h>
 #include <linux/scatterlist.h>
 
@@ -239,17 +240,13 @@ static int stub_send_ret_submit(struct stub_device *sdev)
                    urb->actual_length > 0) {
                        if (urb->num_sgs) {
                                unsigned int copy = urb->actual_length;
-                               int size;
+                               unsigned int size;
 
                                for_each_sg(urb->sg, sg, urb->num_sgs, i) {
                                        if (copy == 0)
                                                break;
 
-                                       if (copy < sg->length)
-                                               size = copy;
-                                       else
-                                               size = sg->length;
-
+                                       size = min(copy, sg->length);
                                        iov[iovnum].iov_base = sg_virt(sg);
                                        iov[iovnum].iov_len = size;