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, ...@@ -930,7 +930,6 @@ struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
cdev_init(&teedev->cdev, &tee_fops); cdev_init(&teedev->cdev, &tee_fops);
teedev->cdev.owner = teedesc->owner; teedev->cdev.owner = teedesc->owner;
teedev->cdev.kobj.parent = &teedev->dev.kobj;
dev_set_drvdata(&teedev->dev, driver_data); dev_set_drvdata(&teedev->dev, driver_data);
device_initialize(&teedev->dev); device_initialize(&teedev->dev);
...@@ -976,9 +975,7 @@ static struct attribute *tee_dev_attrs[] = { ...@@ -976,9 +975,7 @@ static struct attribute *tee_dev_attrs[] = {
NULL NULL
}; };
static const struct attribute_group tee_dev_group = { ATTRIBUTE_GROUPS(tee_dev);
.attrs = tee_dev_attrs,
};
/** /**
* tee_device_register() - Registers a TEE device * tee_device_register() - Registers a TEE device
...@@ -998,39 +995,19 @@ int tee_device_register(struct tee_device *teedev) ...@@ -998,39 +995,19 @@ int tee_device_register(struct tee_device *teedev)
return -EINVAL; return -EINVAL;
} }
rc = cdev_add(&teedev->cdev, teedev->dev.devt, 1); teedev->dev.groups = tee_dev_groups;
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;
}
rc = device_add(&teedev->dev); rc = cdev_device_add(&teedev->cdev, &teedev->dev);
if (rc) { if (rc) {
dev_err(&teedev->dev, 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), teedev->name, MAJOR(teedev->dev.devt),
MINOR(teedev->dev.devt), rc); MINOR(teedev->dev.devt), rc);
goto err_device_add; return rc;
}
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;
} }
teedev->flags |= TEE_DEVICE_FLAG_REGISTERED; teedev->flags |= TEE_DEVICE_FLAG_REGISTERED;
return 0; 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); EXPORT_SYMBOL_GPL(tee_device_register);
...@@ -1073,11 +1050,8 @@ void tee_device_unregister(struct tee_device *teedev) ...@@ -1073,11 +1050,8 @@ void tee_device_unregister(struct tee_device *teedev)
if (!teedev) if (!teedev)
return; return;
if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED) { if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED)
sysfs_remove_group(&teedev->dev.kobj, &tee_dev_group); cdev_device_del(&teedev->cdev, &teedev->dev);
cdev_del(&teedev->cdev);
device_del(&teedev->dev);
}
tee_device_put(teedev); tee_device_put(teedev);
wait_for_completion(&teedev->c_no_users); 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