@@ -112,6 +112,7 @@ struct ffa_drv_info {
112112};
113113
114114static struct ffa_drv_info * drv_info ;
115+ static void ffa_partitions_cleanup (void );
115116
116117/*
117118 * The driver must be able to support all the versions from the earliest
@@ -1195,7 +1196,7 @@ void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
11951196 kfree (pbuf );
11961197}
11971198
1198- static void ffa_setup_partitions (void )
1199+ static int ffa_setup_partitions (void )
11991200{
12001201 int count , idx , ret ;
12011202 uuid_t uuid ;
@@ -1206,7 +1207,7 @@ static void ffa_setup_partitions(void)
12061207 count = ffa_partition_probe (& uuid_null , & pbuf );
12071208 if (count <= 0 ) {
12081209 pr_info ("%s: No partitions found, error %d\n" , __func__ , count );
1209- return ;
1210+ return - EINVAL ;
12101211 }
12111212
12121213 xa_init (& drv_info -> partition_info );
@@ -1250,16 +1251,26 @@ static void ffa_setup_partitions(void)
12501251
12511252 /* Allocate for the host */
12521253 info = kzalloc (sizeof (* info ), GFP_KERNEL );
1253- if (!info )
1254- return ;
1254+ if (!info ) {
1255+ pr_err ("%s: failed to alloc Host partition ID 0x%x. Abort.\n" ,
1256+ __func__ , drv_info -> vm_id );
1257+ /* Already registered devices are freed on bus_exit */
1258+ ffa_partitions_cleanup ();
1259+ return - ENOMEM ;
1260+ }
1261+
12551262 rwlock_init (& info -> rw_lock );
12561263 ret = xa_insert (& drv_info -> partition_info , drv_info -> vm_id ,
12571264 info , GFP_KERNEL );
12581265 if (ret ) {
12591266 pr_err ("%s: failed to save Host partition ID 0x%x - ret:%d. Abort.\n" ,
12601267 __func__ , drv_info -> vm_id , ret );
12611268 kfree (info );
1269+ /* Already registered devices are freed on bus_exit */
1270+ ffa_partitions_cleanup ();
12621271 }
1272+
1273+ return ret ;
12631274}
12641275
12651276static void ffa_partitions_cleanup (void )
@@ -1520,14 +1531,21 @@ static int __init ffa_init(void)
15201531
15211532 ffa_notifications_setup ();
15221533
1523- ffa_setup_partitions ();
1534+ ret = ffa_setup_partitions ();
1535+ if (ret ) {
1536+ pr_err ("failed to setup partitions\n" );
1537+ goto cleanup_notifs ;
1538+ }
15241539
15251540 ret = ffa_sched_recv_cb_update (drv_info -> vm_id , ffa_self_notif_handle ,
15261541 drv_info , true);
15271542 if (ret )
15281543 pr_info ("Failed to register driver sched callback %d\n" , ret );
15291544
15301545 return 0 ;
1546+
1547+ cleanup_notifs :
1548+ ffa_notifications_cleanup ();
15311549free_pages :
15321550 if (drv_info -> tx_buffer )
15331551 free_pages_exact (drv_info -> tx_buffer , RXTX_BUFFER_SIZE );
0 commit comments