Skip to content

Commit 965602e

Browse files
Srinivas-Kandagatlagregkh
authored andcommitted
misc: fastrpc: separate fastrpc device from channel context
Currently fastrpc misc device instance is within channel context struct with a kref. So we have 2 structs with refcount, both of them managing the same channel context structure. Separate fastrpc device from channel context and by adding a dedicated fastrpc_device structure, this should clean the structures a bit and also help when adding secure device node support. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20220214161002.6831-2-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 084973e commit 965602e

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#define USER_PD (1)
7979
#define SENSORS_PD (2)
8080

81-
#define miscdev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, miscdev)
81+
#define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscdev)
8282

8383
static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp",
8484
"sdsp", "cdsp"};
@@ -212,8 +212,13 @@ struct fastrpc_channel_ctx {
212212
spinlock_t lock;
213213
struct idr ctx_idr;
214214
struct list_head users;
215-
struct miscdevice miscdev;
216215
struct kref refcount;
216+
struct fastrpc_device *fdevice;
217+
};
218+
219+
struct fastrpc_device {
220+
struct fastrpc_channel_ctx *cctx;
221+
struct miscdevice miscdev;
217222
};
218223

219224
struct fastrpc_user {
@@ -1220,10 +1225,14 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
12201225

12211226
static int fastrpc_device_open(struct inode *inode, struct file *filp)
12221227
{
1223-
struct fastrpc_channel_ctx *cctx = miscdev_to_cctx(filp->private_data);
1228+
struct fastrpc_channel_ctx *cctx;
1229+
struct fastrpc_device *fdevice;
12241230
struct fastrpc_user *fl = NULL;
12251231
unsigned long flags;
12261232

1233+
fdevice = miscdev_to_fdevice(filp->private_data);
1234+
cctx = fdevice->cctx;
1235+
12271236
fl = kzalloc(sizeof(*fl), GFP_KERNEL);
12281237
if (!fl)
12291238
return -ENOMEM;
@@ -1615,6 +1624,27 @@ static struct platform_driver fastrpc_cb_driver = {
16151624
},
16161625
};
16171626

1627+
static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctx *cctx,
1628+
const char *domain)
1629+
{
1630+
struct fastrpc_device *fdev;
1631+
int err;
1632+
1633+
fdev = devm_kzalloc(dev, sizeof(*fdev), GFP_KERNEL);
1634+
if (!fdev)
1635+
return -ENOMEM;
1636+
1637+
fdev->cctx = cctx;
1638+
fdev->miscdev.minor = MISC_DYNAMIC_MINOR;
1639+
fdev->miscdev.fops = &fastrpc_fops;
1640+
fdev->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "fastrpc-%s", domain);
1641+
err = misc_register(&fdev->miscdev);
1642+
if (!err)
1643+
cctx->fdevice = fdev;
1644+
1645+
return err;
1646+
}
1647+
16181648
static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
16191649
{
16201650
struct device *rdev = &rpdev->dev;
@@ -1644,11 +1674,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
16441674
if (!data)
16451675
return -ENOMEM;
16461676

1647-
data->miscdev.minor = MISC_DYNAMIC_MINOR;
1648-
data->miscdev.name = devm_kasprintf(rdev, GFP_KERNEL, "fastrpc-%s",
1649-
domains[domain_id]);
1650-
data->miscdev.fops = &fastrpc_fops;
1651-
err = misc_register(&data->miscdev);
1677+
err = fastrpc_device_register(rdev, data, domains[domain_id]);
16521678
if (err) {
16531679
kfree(data);
16541680
return err;
@@ -1688,7 +1714,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
16881714
fastrpc_notify_users(user);
16891715
spin_unlock_irqrestore(&cctx->lock, flags);
16901716

1691-
misc_deregister(&cctx->miscdev);
1717+
if (cctx->fdevice)
1718+
misc_deregister(&cctx->fdevice->miscdev);
1719+
16921720
of_platform_depopulate(&rpdev->dev);
16931721

16941722
cctx->rpdev = NULL;

0 commit comments

Comments
 (0)