mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 19:08:57 +09:00
UPSTREAM: rpmsg: char: Refactor rpmsg_chrdev_eptdev_create function
Introduce the rpmsg_chrdev_eptdev_alloc and rpmsg_chrdev_eptdev_add
internal function to split the allocation part from the device add.
This patch prepares the introduction of a rpmsg channel device for the
char device. An default endpoint will be created,
referenced in the rpmsg_eptdev structure before adding the devices.
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/20220124102524.295783-9-arnaud.pouliquen@foss.st.com
Bug: 228237154
(cherry picked from commit cc9da7de4a)
Change-Id: Ibbcf48ecac9ee12d9daedcf563d8c3afe341a198
Signed-off-by: Jindong Yue <jindong.yue@nxp.com>
This commit is contained in:
committed by
Jindong Yue
parent
d08b81c362
commit
3ebe5afe93
@@ -327,20 +327,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);
|
||||
@@ -356,6 +354,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;
|
||||
@@ -386,6 +394,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)
|
||||
|
||||
Reference in New Issue
Block a user