Skip to content

Commit ace760d

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_ffa: Use xa_insert() and check for result
While adding new partitions descriptors to the XArray the outcome of the stores should be checked and, in particular, it has also to be ensured that an existing entry with the same index was not already present, since partitions IDs are expected to be unique. Use xa_insert() instead of xa_store() since it returns -EBUSY when the index is already in use and log an error when that happens. Signed-off-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sudeep Holla <[email protected]>
1 parent ad9d9a1 commit ace760d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/firmware/arm_ffa/driver.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid)
11971197

11981198
static void ffa_setup_partitions(void)
11991199
{
1200-
int count, idx;
1200+
int count, idx, ret;
12011201
uuid_t uuid;
12021202
struct ffa_device *ffa_dev;
12031203
struct ffa_dev_part_info *info;
@@ -1236,7 +1236,14 @@ static void ffa_setup_partitions(void)
12361236
continue;
12371237
}
12381238
rwlock_init(&info->rw_lock);
1239-
xa_store(&drv_info->partition_info, tpbuf->id, info, GFP_KERNEL);
1239+
ret = xa_insert(&drv_info->partition_info, tpbuf->id,
1240+
info, GFP_KERNEL);
1241+
if (ret) {
1242+
pr_err("%s: failed to save partition ID 0x%x - ret:%d\n",
1243+
__func__, tpbuf->id, ret);
1244+
ffa_device_unregister(ffa_dev);
1245+
kfree(info);
1246+
}
12401247
}
12411248

12421249
kfree(pbuf);
@@ -1246,7 +1253,13 @@ static void ffa_setup_partitions(void)
12461253
if (!info)
12471254
return;
12481255
rwlock_init(&info->rw_lock);
1249-
xa_store(&drv_info->partition_info, drv_info->vm_id, info, GFP_KERNEL);
1256+
ret = xa_insert(&drv_info->partition_info, drv_info->vm_id,
1257+
info, GFP_KERNEL);
1258+
if (ret) {
1259+
pr_err("%s: failed to save Host partition ID 0x%x - ret:%d. Abort.\n",
1260+
__func__, drv_info->vm_id, ret);
1261+
kfree(info);
1262+
}
12501263
}
12511264

12521265
static void ffa_partitions_cleanup(void)

0 commit comments

Comments
 (0)