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.

hsi: hsi_core: use kzalloc_flex

Simplifies allocations by using a flexible array member in this struct.

Add __counted_by to get extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260318191037.5661-1-rosenp@gmail.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Rosen Penev and committed by
Sebastian Reichel
e61af3ca 6de23f81

+16 -23
+15 -22
drivers/hsi/hsi_core.c
··· 342 342 { 343 343 struct hsi_controller *hsi = to_hsi_controller(dev); 344 344 345 - kfree(hsi->port); 346 345 kfree(hsi); 347 346 } 348 347 ··· 445 446 return; 446 447 447 448 for (i = 0; i < hsi->num_ports; i++) 448 - if (hsi->port && hsi->port[i]) 449 + if (hsi->port[i]) 449 450 put_device(&hsi->port[i]->device); 450 451 put_device(&hsi->device); 451 452 } ··· 461 462 struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags) 462 463 { 463 464 struct hsi_controller *hsi; 464 - struct hsi_port **port; 465 465 unsigned int i; 466 466 467 467 if (!n_ports) 468 468 return NULL; 469 469 470 - hsi = kzalloc_obj(*hsi, flags); 470 + hsi = kzalloc_flex(*hsi, port, n_ports, flags); 471 471 if (!hsi) 472 472 return NULL; 473 - port = kzalloc_objs(*port, n_ports, flags); 474 - if (!port) { 475 - kfree(hsi); 476 - return NULL; 477 - } 473 + 478 474 hsi->num_ports = n_ports; 479 - hsi->port = port; 480 475 hsi->device.release = hsi_controller_release; 481 476 device_initialize(&hsi->device); 482 477 483 478 for (i = 0; i < n_ports; i++) { 484 - port[i] = kzalloc_obj(**port, flags); 485 - if (port[i] == NULL) 479 + hsi->port[i] = kzalloc_obj(**hsi->port, flags); 480 + if (hsi->port[i] == NULL) 486 481 goto out; 487 - port[i]->num = i; 488 - port[i]->async = hsi_dummy_msg; 489 - port[i]->setup = hsi_dummy_cl; 490 - port[i]->flush = hsi_dummy_cl; 491 - port[i]->start_tx = hsi_dummy_cl; 492 - port[i]->stop_tx = hsi_dummy_cl; 493 - port[i]->release = hsi_dummy_cl; 494 - mutex_init(&port[i]->lock); 495 - BLOCKING_INIT_NOTIFIER_HEAD(&port[i]->n_head); 496 - dev_set_name(&port[i]->device, "port%d", i); 482 + hsi->port[i]->num = i; 483 + hsi->port[i]->async = hsi_dummy_msg; 484 + hsi->port[i]->setup = hsi_dummy_cl; 485 + hsi->port[i]->flush = hsi_dummy_cl; 486 + hsi->port[i]->start_tx = hsi_dummy_cl; 487 + hsi->port[i]->stop_tx = hsi_dummy_cl; 488 + hsi->port[i]->release = hsi_dummy_cl; 489 + mutex_init(&hsi->port[i]->lock); 490 + BLOCKING_INIT_NOTIFIER_HEAD(&hsi->port[i]->n_head); 491 + dev_set_name(&hsi->port[i]->device, "port%d", i); 497 492 hsi->port[i]->device.release = hsi_port_release; 498 493 device_initialize(&hsi->port[i]->device); 499 494 }
+1 -1
include/linux/hsi/hsi.h
··· 271 271 struct module *owner; 272 272 unsigned int id; 273 273 unsigned int num_ports; 274 - struct hsi_port **port; 274 + struct hsi_port *port[] __counted_by(num_ports); 275 275 }; 276 276 277 277 #define to_hsi_controller(dev) container_of(dev, struct hsi_controller, device)