Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rpmsg: char: Export eptdev create and destroy functions

To prepare the split of the code related to the control (ctrldev)
and the endpoint (eptdev) devices in 2 separate files:

- Rename and export the functions in rpmsg_char.h.

- Suppress the dependency with the rpmsg_ctrldev struct in the
rpmsg_eptdev_create function.

Suggested-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/20220124102524.295783-2-arnaud.pouliquen@foss.st.com

authored by

Arnaud Pouliquen and committed by
Bjorn Andersson
69265bc1 cbf58250

+57 -7
+11 -7
drivers/rpmsg/rpmsg_char.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 + * Copyright (C) 2022, STMicroelectronics 3 4 * Copyright (c) 2016, Linaro Ltd. 4 5 * Copyright (c) 2012, Michal Simek <monstr@monstr.eu> 5 6 * Copyright (c) 2012, PetaLogix ··· 25 24 #include <linux/slab.h> 26 25 #include <linux/uaccess.h> 27 26 #include <uapi/linux/rpmsg.h> 27 + 28 + #include "rpmsg_char.h" 28 29 29 30 #define RPMSG_DEV_MAX (MINORMASK + 1) 30 31 ··· 82 79 wait_queue_head_t readq; 83 80 }; 84 81 85 - static int rpmsg_eptdev_destroy(struct device *dev, void *data) 82 + int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data) 86 83 { 87 84 struct rpmsg_eptdev *eptdev = dev_to_eptdev(dev); 88 85 ··· 101 98 102 99 return 0; 103 100 } 101 + EXPORT_SYMBOL(rpmsg_chrdev_eptdev_destroy); 104 102 105 103 static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len, 106 104 void *priv, u32 addr) ··· 288 284 if (cmd != RPMSG_DESTROY_EPT_IOCTL) 289 285 return -EINVAL; 290 286 291 - return rpmsg_eptdev_destroy(&eptdev->dev, NULL); 287 + return rpmsg_chrdev_eptdev_destroy(&eptdev->dev, NULL); 292 288 } 293 289 294 290 static const struct file_operations rpmsg_eptdev_fops = { ··· 346 342 kfree(eptdev); 347 343 } 348 344 349 - static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, 345 + int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent, 350 346 struct rpmsg_channel_info chinfo) 351 347 { 352 - struct rpmsg_device *rpdev = ctrldev->rpdev; 353 348 struct rpmsg_eptdev *eptdev; 354 349 struct device *dev; 355 350 int ret; ··· 368 365 369 366 device_initialize(dev); 370 367 dev->class = rpmsg_class; 371 - dev->parent = &ctrldev->dev; 368 + dev->parent = parent; 372 369 dev->groups = rpmsg_eptdev_groups; 373 370 dev_set_drvdata(dev, eptdev); 374 371 ··· 405 402 406 403 return ret; 407 404 } 405 + EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create); 408 406 409 407 static int rpmsg_ctrldev_open(struct inode *inode, struct file *filp) 410 408 { ··· 445 441 chinfo.src = eptinfo.src; 446 442 chinfo.dst = eptinfo.dst; 447 443 448 - return rpmsg_eptdev_create(ctrldev, chinfo); 444 + return rpmsg_chrdev_eptdev_create(ctrldev->rpdev, &ctrldev->dev, chinfo); 449 445 }; 450 446 451 447 static const struct file_operations rpmsg_ctrldev_fops = { ··· 524 520 int ret; 525 521 526 522 /* Destroy all endpoints */ 527 - ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_eptdev_destroy); 523 + ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_chrdev_eptdev_destroy); 528 524 if (ret) 529 525 dev_warn(&rpdev->dev, "failed to nuke endpoints: %d\n", ret); 530 526
+46
drivers/rpmsg/rpmsg_char.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (C) 2022, STMicroelectronics 4 + */ 5 + 6 + #ifndef __RPMSG_CHRDEV_H__ 7 + #define __RPMSG_CHRDEV_H__ 8 + 9 + #if IS_ENABLED(CONFIG_RPMSG_CHAR) 10 + /** 11 + * rpmsg_chrdev_eptdev_create() - register char device based on an endpoint 12 + * @rpdev: prepared rpdev to be used for creating endpoints 13 + * @parent: parent device 14 + * @chinfo: associated endpoint channel information. 15 + * 16 + * This function create a new rpmsg char endpoint device to instantiate a new 17 + * endpoint based on chinfo information. 18 + */ 19 + int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent, 20 + struct rpmsg_channel_info chinfo); 21 + 22 + /** 23 + * rpmsg_chrdev_eptdev_destroy() - destroy created char device endpoint. 24 + * @data: private data associated to the endpoint device 25 + * 26 + * This function destroys a rpmsg char endpoint device created by the RPMSG_DESTROY_EPT_IOCTL 27 + * control. 28 + */ 29 + int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data); 30 + 31 + #else /*IS_ENABLED(CONFIG_RPMSG_CHAR) */ 32 + 33 + static inline int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent, 34 + struct rpmsg_channel_info chinfo) 35 + { 36 + return -ENXIO; 37 + } 38 + 39 + static inline int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data) 40 + { 41 + return -ENXIO; 42 + } 43 + 44 + #endif /*IS_ENABLED(CONFIG_RPMSG_CHAR) */ 45 + 46 + #endif /*__RPMSG_CHRDEV_H__ */