All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: <linux-remoteproc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<julien.massot@iot.bzh>, <arnaud.pouliquen@foss.st.com>
Subject: [PATCH v9 08/11] rpmsg: char: Refactor rpmsg_chrdev_eptdev_create function
Date: Mon, 24 Jan 2022 11:25:21 +0100	[thread overview]
Message-ID: <20220124102524.295783-9-arnaud.pouliquen@foss.st.com> (raw)
In-Reply-To: <20220124102524.295783-1-arnaud.pouliquen@foss.st.com>

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>
---
 drivers/rpmsg/rpmsg_char.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index fcd583472d5a..e7bc7dcdba63 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -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 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
 
 	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)
-- 
2.25.1


  parent reply	other threads:[~2022-01-24 10:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 10:25 [PATCH v9 00/11] Restructure the rpmsg_char driver and introduce rpmsg_ctrl driver Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 01/11] rpmsg: char: Export eptdev create and destroy functions Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 02/11] rpmsg: Create the rpmsg class in core instead of in rpmsg char Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 03/11] rpmsg: Move the rpmsg control device from rpmsg_char to rpmsg_ctrl Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 04/11] arm: configs: Configs that had RPMSG_CHAR now get RPMSG_CTRL Arnaud Pouliquen
2022-01-24 10:25   ` Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 05/11] RISC-V: " Arnaud Pouliquen
2022-01-24 10:25   ` Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 06/11] arm64: defconfig: Config that had RPMSG_CHAR now gets RPMSG_CTRL Arnaud Pouliquen
2022-01-24 10:25   ` Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 07/11] rpmsg: Update rpmsg_chrdev_register_device function Arnaud Pouliquen
2022-01-24 10:25 ` Arnaud Pouliquen [this message]
2022-01-24 10:25 ` [PATCH v9 09/11] rpmsg: char: Add possibility to use default endpoint of the rpmsg device Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 10/11] rpmsg: char: Introduce the "rpmsg-raw" channel Arnaud Pouliquen
2022-01-24 10:25 ` [PATCH v9 11/11] rpmsg: ctrl: Introduce new RPMSG_CREATE/RELEASE_DEV_IOCTL controls Arnaud Pouliquen
2022-02-23 21:28 ` [PATCH v9 00/11] Restructure the rpmsg_char driver and introduce rpmsg_ctrl driver Philipp Rossak
2022-02-24  8:29   ` Arnaud POULIQUEN
2022-02-25 21:45     ` Philipp Rossak
2022-02-28  9:02       ` Arnaud POULIQUEN
2022-03-24 17:36 ` Arnaud POULIQUEN
2022-03-25 15:59   ` Mathieu Poirier
2022-03-25 17:05     ` Arnaud POULIQUEN
2022-03-25 17:27       ` Mathieu Poirier
2022-03-25 17:52         ` Arnaud POULIQUEN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220124102524.295783-9-arnaud.pouliquen@foss.st.com \
    --to=arnaud.pouliquen@foss.st.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=julien.massot@iot.bzh \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mathieu.poirier@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.