@@ -112,6 +112,7 @@ struct ffa_drv_info {
112
112
};
113
113
114
114
static struct ffa_drv_info * drv_info ;
115
+ static void ffa_partitions_cleanup (void );
115
116
116
117
/*
117
118
* 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)
1195
1196
kfree (pbuf );
1196
1197
}
1197
1198
1198
- static void ffa_setup_partitions (void )
1199
+ static int ffa_setup_partitions (void )
1199
1200
{
1200
1201
int count , idx , ret ;
1201
1202
uuid_t uuid ;
@@ -1206,7 +1207,7 @@ static void ffa_setup_partitions(void)
1206
1207
count = ffa_partition_probe (& uuid_null , & pbuf );
1207
1208
if (count <= 0 ) {
1208
1209
pr_info ("%s: No partitions found, error %d\n" , __func__ , count );
1209
- return ;
1210
+ return - EINVAL ;
1210
1211
}
1211
1212
1212
1213
xa_init (& drv_info -> partition_info );
@@ -1250,16 +1251,26 @@ static void ffa_setup_partitions(void)
1250
1251
1251
1252
/* Allocate for the host */
1252
1253
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
+
1255
1262
rwlock_init (& info -> rw_lock );
1256
1263
ret = xa_insert (& drv_info -> partition_info , drv_info -> vm_id ,
1257
1264
info , GFP_KERNEL );
1258
1265
if (ret ) {
1259
1266
pr_err ("%s: failed to save Host partition ID 0x%x - ret:%d. Abort.\n" ,
1260
1267
__func__ , drv_info -> vm_id , ret );
1261
1268
kfree (info );
1269
+ /* Already registered devices are freed on bus_exit */
1270
+ ffa_partitions_cleanup ();
1262
1271
}
1272
+
1273
+ return ret ;
1263
1274
}
1264
1275
1265
1276
static void ffa_partitions_cleanup (void )
@@ -1520,14 +1531,21 @@ static int __init ffa_init(void)
1520
1531
1521
1532
ffa_notifications_setup ();
1522
1533
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
+ }
1524
1539
1525
1540
ret = ffa_sched_recv_cb_update (drv_info -> vm_id , ffa_self_notif_handle ,
1526
1541
drv_info , true);
1527
1542
if (ret )
1528
1543
pr_info ("Failed to register driver sched callback %d\n" , ret );
1529
1544
1530
1545
return 0 ;
1546
+
1547
+ cleanup_notifs :
1548
+ ffa_notifications_cleanup ();
1531
1549
free_pages :
1532
1550
if (drv_info -> tx_buffer )
1533
1551
free_pages_exact (drv_info -> tx_buffer , RXTX_BUFFER_SIZE );
0 commit comments