From patchwork Mon Nov 8 14:19:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 12608491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA788C433F5 for ; Mon, 8 Nov 2021 14:19:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80A7D610C8 for ; Mon, 8 Nov 2021 14:19:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240314AbhKHOWe (ORCPT ); Mon, 8 Nov 2021 09:22:34 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:55380 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237741AbhKHOWe (ORCPT ); Mon, 8 Nov 2021 09:22:34 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1A8DV3vc021016; Mon, 8 Nov 2021 15:19:47 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=a41vJFItKJ5IiBl4p4P3S/FPtTvymrgfs42LyirnKtY=; b=6MJjKlvDGqUnvsADI3pp1wU8fSaBgvUCksZw6XnpkphtaxEMnEaQBH2xMSKFeuBFuegP gjw/PqCfsXW5gE+vxVSua+9ry/0otK/5ScSSU0UlEBt+i4hRxHpO3uhIuB+NhOP7Gbl6 cw652CFgH5VpDXUFPedp/fs/MNQtKQ6wr5TuhLDg7MmPyLyis9jCouWd6rhCvNWjv4CA lMO5hePZVB360ZNlFOcmJVzQYHPViSSLEAFyitTeOuBwFecNeFbRRHC1Kc+SO8pb5ab6 zGyOQEeVuH81RcrQW4Nhkrne4dJKsJF7SZDlkRWob6bWZbnmFMw8GhRXUggIThWnmL0K uQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3c74uk8b9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Nov 2021 15:19:47 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6A81F10002A; Mon, 8 Nov 2021 15:19:47 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6443521E665; Mon, 8 Nov 2021 15:19:47 +0100 (CET) Received: from localhost (10.75.127.51) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 8 Nov 2021 15:19:47 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , , Subject: [PATCH v7 07/12] rpmsg: char: Refactor rpmsg_chrdev_eptdev_create function Date: Mon, 8 Nov 2021 15:19:32 +0100 Message-ID: <20211108141937.13016-8-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211108141937.13016-1-arnaud.pouliquen@foss.st.com> References: <20211108141937.13016-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-08_05,2021-11-08_01,2020-04-07_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org 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 --- 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 29c4d2c3aea9..3daf62df69a0 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -325,20 +325,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); @@ -354,6 +352,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; @@ -390,6 +398,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)