tee: correct max value for id allocation
The privileged dev id range is [TEE_NUM_DEVICES / 2, TEE_NUM_DEVICES). The non-privileged dev id range is [0, TEE_NUM_DEVICES / 2). So when finding a slot for them, need to use different max value. Signed-off-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
This commit is contained in:
parent
661e50bc85
commit
7dd003aec2
|
@ -693,7 +693,7 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
|
||||||
{
|
{
|
||||||
struct tee_device *teedev;
|
struct tee_device *teedev;
|
||||||
void *ret;
|
void *ret;
|
||||||
int rc;
|
int rc, max_id;
|
||||||
int offs = 0;
|
int offs = 0;
|
||||||
|
|
||||||
if (!teedesc || !teedesc->name || !teedesc->ops ||
|
if (!teedesc || !teedesc->name || !teedesc->ops ||
|
||||||
|
@ -707,16 +707,20 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teedesc->flags & TEE_DESC_PRIVILEGED)
|
max_id = TEE_NUM_DEVICES / 2;
|
||||||
|
|
||||||
|
if (teedesc->flags & TEE_DESC_PRIVILEGED) {
|
||||||
offs = TEE_NUM_DEVICES / 2;
|
offs = TEE_NUM_DEVICES / 2;
|
||||||
|
max_id = TEE_NUM_DEVICES;
|
||||||
|
}
|
||||||
|
|
||||||
spin_lock(&driver_lock);
|
spin_lock(&driver_lock);
|
||||||
teedev->id = find_next_zero_bit(dev_mask, TEE_NUM_DEVICES, offs);
|
teedev->id = find_next_zero_bit(dev_mask, max_id, offs);
|
||||||
if (teedev->id < TEE_NUM_DEVICES)
|
if (teedev->id < max_id)
|
||||||
set_bit(teedev->id, dev_mask);
|
set_bit(teedev->id, dev_mask);
|
||||||
spin_unlock(&driver_lock);
|
spin_unlock(&driver_lock);
|
||||||
|
|
||||||
if (teedev->id >= TEE_NUM_DEVICES) {
|
if (teedev->id >= max_id) {
|
||||||
ret = ERR_PTR(-ENOMEM);
|
ret = ERR_PTR(-ENOMEM);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue