Skip to content

Commit cc9da7d

Browse files
arnopoandersson
authored andcommitted
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
1 parent 472f84e commit cc9da7d

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,18 @@ static void rpmsg_eptdev_release_device(struct device *dev)
330330
kfree(eptdev);
331331
}
332332

333-
int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
334-
struct rpmsg_channel_info chinfo)
333+
static struct rpmsg_eptdev *rpmsg_chrdev_eptdev_alloc(struct rpmsg_device *rpdev,
334+
struct device *parent)
335335
{
336336
struct rpmsg_eptdev *eptdev;
337337
struct device *dev;
338-
int ret;
339338

340339
eptdev = kzalloc(sizeof(*eptdev), GFP_KERNEL);
341340
if (!eptdev)
342-
return -ENOMEM;
341+
return ERR_PTR(-ENOMEM);
343342

344343
dev = &eptdev->dev;
345344
eptdev->rpdev = rpdev;
346-
eptdev->chinfo = chinfo;
347345

348346
mutex_init(&eptdev->ept_lock);
349347
spin_lock_init(&eptdev->queue_lock);
@@ -359,6 +357,16 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
359357
cdev_init(&eptdev->cdev, &rpmsg_eptdev_fops);
360358
eptdev->cdev.owner = THIS_MODULE;
361359

360+
return eptdev;
361+
}
362+
363+
static int rpmsg_chrdev_eptdev_add(struct rpmsg_eptdev *eptdev, struct rpmsg_channel_info chinfo)
364+
{
365+
struct device *dev = &eptdev->dev;
366+
int ret;
367+
368+
eptdev->chinfo = chinfo;
369+
362370
ret = ida_simple_get(&rpmsg_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL);
363371
if (ret < 0)
364372
goto free_eptdev;
@@ -389,6 +397,21 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
389397

390398
return ret;
391399
}
400+
401+
int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
402+
struct rpmsg_channel_info chinfo)
403+
{
404+
struct rpmsg_eptdev *eptdev;
405+
int ret;
406+
407+
eptdev = rpmsg_chrdev_eptdev_alloc(rpdev, parent);
408+
if (IS_ERR(eptdev))
409+
return PTR_ERR(eptdev);
410+
411+
ret = rpmsg_chrdev_eptdev_add(eptdev, chinfo);
412+
413+
return ret;
414+
}
392415
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
393416

394417
static int rpmsg_chrdev_init(void)

0 commit comments

Comments
 (0)