Skip to content

Commit

Permalink
firmware: arm_ffa: Handle partitions setup failures
Browse files Browse the repository at this point in the history
Make ffa_setup_partitions() fail, cleanup and return an error when the Host
partition setup fails: in such a case ffa_init() itself will fail.

Signed-off-by: Cristian Marussi <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sudeep Holla <[email protected]>
  • Loading branch information
freefall75 authored and sudeep-holla committed Jan 22, 2024
1 parent ace760d commit 0c565d1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions drivers/firmware/arm_ffa/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct ffa_drv_info {
};

static struct ffa_drv_info *drv_info;
static void ffa_partitions_cleanup(void);

/*
* The driver must be able to support all the versions from the earliest
Expand Down Expand Up @@ -1195,7 +1196,7 @@ void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
kfree(pbuf);
}

static void ffa_setup_partitions(void)
static int ffa_setup_partitions(void)
{
int count, idx, ret;
uuid_t uuid;
Expand All @@ -1206,7 +1207,7 @@ static void ffa_setup_partitions(void)
count = ffa_partition_probe(&uuid_null, &pbuf);
if (count <= 0) {
pr_info("%s: No partitions found, error %d\n", __func__, count);
return;
return -EINVAL;
}

xa_init(&drv_info->partition_info);
Expand Down Expand Up @@ -1250,16 +1251,26 @@ static void ffa_setup_partitions(void)

/* Allocate for the host */
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return;
if (!info) {
pr_err("%s: failed to alloc Host partition ID 0x%x. Abort.\n",
__func__, drv_info->vm_id);
/* Already registered devices are freed on bus_exit */
ffa_partitions_cleanup();
return -ENOMEM;
}

rwlock_init(&info->rw_lock);
ret = xa_insert(&drv_info->partition_info, drv_info->vm_id,
info, GFP_KERNEL);
if (ret) {
pr_err("%s: failed to save Host partition ID 0x%x - ret:%d. Abort.\n",
__func__, drv_info->vm_id, ret);
kfree(info);
/* Already registered devices are freed on bus_exit */
ffa_partitions_cleanup();
}

return ret;
}

static void ffa_partitions_cleanup(void)
Expand Down Expand Up @@ -1520,14 +1531,21 @@ static int __init ffa_init(void)

ffa_notifications_setup();

ffa_setup_partitions();
ret = ffa_setup_partitions();
if (ret) {
pr_err("failed to setup partitions\n");
goto cleanup_notifs;
}

ret = ffa_sched_recv_cb_update(drv_info->vm_id, ffa_self_notif_handle,
drv_info, true);
if (ret)
pr_info("Failed to register driver sched callback %d\n", ret);

return 0;

cleanup_notifs:
ffa_notifications_cleanup();
free_pages:
if (drv_info->tx_buffer)
free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE);
Expand Down

0 comments on commit 0c565d1

Please sign in to comment.