summaryrefslogtreecommitdiffstats
path: root/drivers/rpmsg/rpmsg_char.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rpmsg/rpmsg_char.c')
-rw-r--r--drivers/rpmsg/rpmsg_char.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index 644b7d36707c..bf7311d64e42 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -330,20 +330,18 @@ static void rpmsg_eptdev_release_device(struct device *dev)
kfree(eptdev);
}
-int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
- struct rpmsg_channel_info chinfo)
+static struct rpmsg_eptdev *rpmsg_chrdev_eptdev_alloc(struct rpmsg_device *rpdev,
+ struct device *parent)
{
struct rpmsg_eptdev *eptdev;
struct device *dev;
- int ret;
eptdev = kzalloc(sizeof(*eptdev), GFP_KERNEL);
if (!eptdev)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
dev = &eptdev->dev;
eptdev->rpdev = rpdev;
- eptdev->chinfo = chinfo;
mutex_init(&eptdev->ept_lock);
spin_lock_init(&eptdev->queue_lock);
@@ -359,6 +357,16 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
cdev_init(&eptdev->cdev, &rpmsg_eptdev_fops);
eptdev->cdev.owner = THIS_MODULE;
+ return eptdev;
+}
+
+static int rpmsg_chrdev_eptdev_add(struct rpmsg_eptdev *eptdev, struct rpmsg_channel_info chinfo)
+{
+ struct device *dev = &eptdev->dev;
+ int ret;
+
+ eptdev->chinfo = chinfo;
+
ret = ida_simple_get(&rpmsg_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL);
if (ret < 0)
goto free_eptdev;
@@ -389,6 +397,21 @@ free_eptdev:
return ret;
}
+
+int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
+ struct rpmsg_channel_info chinfo)
+{
+ struct rpmsg_eptdev *eptdev;
+ int ret;
+
+ eptdev = rpmsg_chrdev_eptdev_alloc(rpdev, parent);
+ if (IS_ERR(eptdev))
+ return PTR_ERR(eptdev);
+
+ ret = rpmsg_chrdev_eptdev_add(eptdev, chinfo);
+
+ return ret;
+}
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
static int rpmsg_chrdev_init(void)