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

Configure Feed

Select the types of activity you want to include in your feed.

usb: fhci: use kzalloc_flex for priv struct

Convert kzalloc_obj(s) to kzalloc_flex to save an allocation.

Add __counted_by to get extra runtime analysis. Move counting variable
assignment immediately after allocation as required by __counted_by.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260313003456.124270-1-rosenp@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rosen Penev and committed by
Greg Kroah-Hartman
03cd4fd6 341434a4

+5 -13
+3 -12
drivers/usb/host/fhci-hcd.c
··· 426 426 } 427 427 428 428 /* allocate the private part of the URB */ 429 - urb_priv = kzalloc_obj(*urb_priv, mem_flags); 429 + urb_priv = kzalloc_flex(*urb_priv, tds, size, mem_flags); 430 430 if (!urb_priv) 431 431 return -ENOMEM; 432 432 433 - /* allocate the private part of the URB */ 434 - urb_priv->tds = kzalloc_objs(*urb_priv->tds, size, mem_flags); 435 - if (!urb_priv->tds) { 436 - kfree(urb_priv); 437 - return -ENOMEM; 438 - } 433 + urb_priv->num_of_tds = size; 439 434 440 435 spin_lock_irqsave(&fhci->lock, flags); 441 436 ··· 439 444 goto err; 440 445 441 446 /* fill the private part of the URB */ 442 - urb_priv->num_of_tds = size; 443 - 444 447 urb->status = -EINPROGRESS; 445 448 urb->actual_length = 0; 446 449 urb->error_count = 0; ··· 446 453 447 454 fhci_queue_urb(fhci, urb); 448 455 err: 449 - if (ret) { 450 - kfree(urb_priv->tds); 456 + if (ret) 451 457 kfree(urb_priv); 452 - } 453 458 spin_unlock_irqrestore(&fhci->lock, flags); 454 459 return ret; 455 460 }
+2 -1
drivers/usb/host/fhci.h
··· 387 387 int tds_cnt; 388 388 int state; 389 389 390 - struct td **tds; 391 390 struct ed *ed; 392 391 struct timer_list time_out; 392 + 393 + struct td *tds[] __counted_by(num_of_tds); 393 394 }; 394 395 395 396 struct endpoint {