Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usbip: Use min to simplify stub_send_ret_submit

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>

authored by

Thorsten Blum and committed by
Greg Kroah-Hartman
8ad19469 071786e2

+3 -6
+3 -6
drivers/usb/usbip/stub_tx.c
··· 4 4 */ 5 5 6 6 #include <linux/kthread.h> 7 + #include <linux/minmax.h> 7 8 #include <linux/socket.h> 8 9 #include <linux/scatterlist.h> 9 10 ··· 240 239 urb->actual_length > 0) { 241 240 if (urb->num_sgs) { 242 241 unsigned int copy = urb->actual_length; 243 - int size; 242 + unsigned int size; 244 243 245 244 for_each_sg(urb->sg, sg, urb->num_sgs, i) { 246 245 if (copy == 0) 247 246 break; 248 247 249 - if (copy < sg->length) 250 - size = copy; 251 - else 252 - size = sg->length; 253 - 248 + size = min(copy, sg->length); 254 249 iov[iovnum].iov_base = sg_virt(sg); 255 250 iov[iovnum].iov_len = size; 256 251