@@ -342,7 +342,6 @@ static void hsi_controller_release(struct device *dev)
342342{
343343 struct hsi_controller * hsi = to_hsi_controller (dev );
344344
345- kfree (hsi -> port );
346345 kfree (hsi );
347346}
348347
@@ -446,7 +445,7 @@ void hsi_put_controller(struct hsi_controller *hsi)
446445 return ;
447446
448447 for (i = 0 ; i < hsi -> num_ports ; i ++ )
449- if (hsi -> port && hsi -> port [i ])
448+ if (hsi -> port [i ])
450449 put_device (& hsi -> port [i ]-> device );
451450 put_device (& hsi -> device );
452451}
@@ -462,39 +461,33 @@ EXPORT_SYMBOL_GPL(hsi_put_controller);
462461struct hsi_controller * hsi_alloc_controller (unsigned int n_ports , gfp_t flags )
463462{
464463 struct hsi_controller * hsi ;
465- struct hsi_port * * port ;
466464 unsigned int i ;
467465
468466 if (!n_ports )
469467 return NULL ;
470468
471- hsi = kzalloc_obj (* hsi , flags );
469+ hsi = kzalloc_flex (* hsi , port , n_ports , flags );
472470 if (!hsi )
473471 return NULL ;
474- port = kzalloc_objs (* port , n_ports , flags );
475- if (!port ) {
476- kfree (hsi );
477- return NULL ;
478- }
472+
479473 hsi -> num_ports = n_ports ;
480- hsi -> port = port ;
481474 hsi -> device .release = hsi_controller_release ;
482475 device_initialize (& hsi -> device );
483476
484477 for (i = 0 ; i < n_ports ; i ++ ) {
485- port [i ] = kzalloc_obj (* * port , flags );
486- if (port [i ] == NULL )
478+ hsi -> port [i ] = kzalloc_obj (* * hsi -> port , flags );
479+ if (hsi -> port [i ] == NULL )
487480 goto out ;
488- port [i ]-> num = i ;
489- port [i ]-> async = hsi_dummy_msg ;
490- port [i ]-> setup = hsi_dummy_cl ;
491- port [i ]-> flush = hsi_dummy_cl ;
492- port [i ]-> start_tx = hsi_dummy_cl ;
493- port [i ]-> stop_tx = hsi_dummy_cl ;
494- port [i ]-> release = hsi_dummy_cl ;
495- mutex_init (& port [i ]-> lock );
496- BLOCKING_INIT_NOTIFIER_HEAD (& port [i ]-> n_head );
497- dev_set_name (& port [i ]-> device , "port%d" , i );
481+ hsi -> port [i ]-> num = i ;
482+ hsi -> port [i ]-> async = hsi_dummy_msg ;
483+ hsi -> port [i ]-> setup = hsi_dummy_cl ;
484+ hsi -> port [i ]-> flush = hsi_dummy_cl ;
485+ hsi -> port [i ]-> start_tx = hsi_dummy_cl ;
486+ hsi -> port [i ]-> stop_tx = hsi_dummy_cl ;
487+ hsi -> port [i ]-> release = hsi_dummy_cl ;
488+ mutex_init (& hsi -> port [i ]-> lock );
489+ BLOCKING_INIT_NOTIFIER_HEAD (& hsi -> port [i ]-> n_head );
490+ dev_set_name (& hsi -> port [i ]-> device , "port%d" , i );
498491 hsi -> port [i ]-> device .release = hsi_port_release ;
499492 device_initialize (& hsi -> port [i ]-> device );
500493 }
0 commit comments