Commit 5746b3b8 authored by Olof Johansson's avatar Olof Johansson

Merge tag 'tee-dev-cleanup-for-v5.10' of...

Merge tag 'tee-dev-cleanup-for-v5.10' of git://git.linaro.org:/people/jens.wiklander/linux-tee into arm/drivers

Simplify tee_device_register() and friends

Uses cdev_device_add() instead of the cdev_add() device_add()
combination.

Initializes dev->groups instead of direct calls to sysfs_create_group()
and friends.

* tag 'tee-dev-cleanup-for-v5.10' of git://git.linaro.org:/people/jens.wiklander/linux-tee:
  tee: avoid explicit sysfs_create/delete_group by initialising dev->groups
  tee: replace cdev_add + device_add with cdev_device_add

Link: https://lore.kernel.org/r/20200918144130.GB1219771@jadeSigned-off-by: default avatarOlof Johansson <olof@lixom.net>
parents 802b26b3 8c05f50f
......@@ -930,7 +930,6 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
cdev_init(&teedev->cdev, &tee_fops);
teedev->cdev.owner = teedesc->owner;
teedev->cdev.kobj.parent = &teedev->dev.kobj;
dev_set_drvdata(&teedev->dev, driver_data);
device_initialize(&teedev->dev);
......@@ -976,9 +975,7 @@ static struct attribute *tee_dev_attrs[] = {
NULL
};
static const struct attribute_group tee_dev_group = {
.attrs = tee_dev_attrs,
};
ATTRIBUTE_GROUPS(tee_dev);
/**
* tee_device_register() - Registers a TEE device
......@@ -998,39 +995,19 @@ int tee_device_register(struct tee_device *teedev)
return -EINVAL;
}
rc = cdev_add(&teedev->cdev, teedev->dev.devt, 1);
if (rc) {
dev_err(&teedev->dev,
"unable to cdev_add() %s, major %d, minor %d, err=%d\n",
teedev->name, MAJOR(teedev->dev.devt),
MINOR(teedev->dev.devt), rc);
return rc;
}
teedev->dev.groups = tee_dev_groups;
rc = device_add(&teedev->dev);
rc = cdev_device_add(&teedev->cdev, &teedev->dev);
if (rc) {
dev_err(&teedev->dev,
"unable to device_add() %s, major %d, minor %d, err=%d\n",
"unable to cdev_device_add() %s, major %d, minor %d, err=%d\n",
teedev->name, MAJOR(teedev->dev.devt),
MINOR(teedev->dev.devt), rc);
goto err_device_add;
}
rc = sysfs_create_group(&teedev->dev.kobj, &tee_dev_group);
if (rc) {
dev_err(&teedev->dev,
"failed to create sysfs attributes, err=%d\n", rc);
goto err_sysfs_create_group;
return rc;
}
teedev->flags |= TEE_DEVICE_FLAG_REGISTERED;
return 0;
err_sysfs_create_group:
device_del(&teedev->dev);
err_device_add:
cdev_del(&teedev->cdev);
return rc;
}
EXPORT_SYMBOL_GPL(tee_device_register);
......@@ -1073,11 +1050,8 @@ void tee_device_unregister(struct tee_device *teedev)
if (!teedev)
return;
if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED) {
sysfs_remove_group(&teedev->dev.kobj, &tee_dev_group);
cdev_del(&teedev->cdev);
device_del(&teedev->dev);
}
if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED)
cdev_device_del(&teedev->cdev, &teedev->dev);
tee_device_put(teedev);
wait_for_completion(&teedev->c_no_users);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment