From patchwork Wed Jan 26 13:52:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 536875 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD482C63697 for ; Wed, 26 Jan 2022 13:54:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241703AbiAZNy3 (ORCPT ); Wed, 26 Jan 2022 08:54:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241661AbiAZNy2 (ORCPT ); Wed, 26 Jan 2022 08:54:28 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AF6C061747 for ; Wed, 26 Jan 2022 05:54:27 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id l25so25892095wrb.13 for ; Wed, 26 Jan 2022 05:54:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+o1EYrbz9tbcgwTH7lcJ3cHrRAzNh8NMyrOZAAp4l10=; b=tRXAd/j13i+dXARq2MRwK3EMKZk8klntInyjmxhB3XtbOgW99xqG2GgwS46dQPdl4Z eNGy2x71L6xH7BpuvQxL0Ka4NXQxzpxfpyIPklYHhZtxndDj+CBHOD74t7PMQzYz+pv+ KqHzqxQF6bPunY1srpJbB+s7prfkMFI6dxYRNkuJnZws56xZd3VWPoTssALXR/CeqvvQ xY7bVY+FBFIJxmnDNNUPgKwmh8myUfF2cFM+XvbZeYAVQ25WLH2n0NNB0umFzFGp0smc YU13GZfjCgUeqUHUTDDPpzwVpbQLqgrtu279W82TwxQeghw+UCUDcqaAq8f6QtkmDHd/ lyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+o1EYrbz9tbcgwTH7lcJ3cHrRAzNh8NMyrOZAAp4l10=; b=GVbODxDLq1IrsZ0A3jFW+A2sFOhyJ/O+4lijEEm04FyZyimchLpUm9ekOYoZMCrNnM XJBpBDvecLJJoBFf5JcrDRQUx8M/78/yPrH6eVK7UbSZbG3LHXblzVNt0Z/Vcz0ITLRV KJPYIOB5HdURcKg3/f0CoQ5tgmsIyQCW2TDYNzproT6bo59xW1MBCJgmaBdtXh7xnXw7 lHKNwq0ODiXMb1Stacinal87y8HOVfzN4g+6rp1P4Z/UItIf4U0QPPVWB0ICmCtw3kvA g7+wQho69D7UhW82GgM36yiMx4UtCXCIDjVJVkrs+dIjSrDudyYiXRmIaijT8hjTlhuy z/Zg== X-Gm-Message-State: AOAM531oo3zYuSNf7pFe0rYn5MFqll2+tD6gQIR1Oe+IMD++VqSW5cDY i8hQhMRhzLMkTqOTlrfw8E0QKfPJIzK3LA== X-Google-Smtp-Source: ABdhPJyT8lccT5fDH9Ddgssxd9Vk5ZVxmpZnc5ZYpXa+2hWrGwHZgsZl3MCFPr4864YSx4GA57T4fw== X-Received: by 2002:a5d:6682:: with SMTP id l2mr22930974wru.409.1643205266280; Wed, 26 Jan 2022 05:54:26 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:25 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v3 01/12] misc: fastrpc: separate fastrpc device from channel context Date: Wed, 26 Jan 2022 13:52:53 +0000 Message-Id: <20220126135304.16340-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Currently fastrpc misc device instance is within channel context struct with a kref. So we have 2 structs with refcount, both of them managing the same channel context structure. Separate fastrpc device from channel context and by adding a dedicated fastrpc_device structure, this should clean the structures a bit and also help when adding secure device node support. Signed-off-by: Srinivas Kandagatla Reported-by: kernel test robot Reported-by: Dan Carpenter --- drivers/misc/fastrpc.c | 48 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 4ccbf43e6bfa..00cf0dbb6084 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -78,7 +78,7 @@ #define USER_PD (1) #define SENSORS_PD (2) -#define miscdev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, miscdev) +#define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscdev) static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", "sdsp", "cdsp"}; @@ -212,8 +212,13 @@ struct fastrpc_channel_ctx { spinlock_t lock; struct idr ctx_idr; struct list_head users; - struct miscdevice miscdev; struct kref refcount; + struct fastrpc_device *fdevice; +}; + +struct fastrpc_device { + struct fastrpc_channel_ctx *cctx; + struct miscdevice miscdev; }; struct fastrpc_user { @@ -1220,10 +1225,14 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) static int fastrpc_device_open(struct inode *inode, struct file *filp) { - struct fastrpc_channel_ctx *cctx = miscdev_to_cctx(filp->private_data); + struct fastrpc_channel_ctx *cctx = NULL; + struct fastrpc_device *fdevice = NULL; struct fastrpc_user *fl = NULL; unsigned long flags; + fdevice = miscdev_to_fdevice(filp->private_data); + cctx = fdevice->cctx; + fl = kzalloc(sizeof(*fl), GFP_KERNEL); if (!fl) return -ENOMEM; @@ -1608,6 +1617,29 @@ static struct platform_driver fastrpc_cb_driver = { }, }; +static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctx *cctx, + const char *domain) +{ + struct fastrpc_device *fdev; + int err; + + fdev = devm_kzalloc(dev, sizeof(*fdev), GFP_KERNEL); + if (!fdev) + return -ENOMEM; + + fdev->cctx = cctx; + fdev->miscdev.minor = MISC_DYNAMIC_MINOR; + fdev->miscdev.fops = &fastrpc_fops; + fdev->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "fastrpc-%s", domain); + err = misc_register(&fdev->miscdev); + if (err) + kfree(fdev); + else + cctx->fdevice = fdev; + + return err; +} + static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) { struct device *rdev = &rpdev->dev; @@ -1637,11 +1669,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) if (!data) return -ENOMEM; - data->miscdev.minor = MISC_DYNAMIC_MINOR; - data->miscdev.name = devm_kasprintf(rdev, GFP_KERNEL, "fastrpc-%s", - domains[domain_id]); - data->miscdev.fops = &fastrpc_fops; - err = misc_register(&data->miscdev); + err = fastrpc_device_register(rdev, data, domains[domain_id]); if (err) { kfree(data); return err; @@ -1681,7 +1709,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) fastrpc_notify_users(user); spin_unlock_irqrestore(&cctx->lock, flags); - misc_deregister(&cctx->miscdev); + if (cctx->fdevice) + misc_deregister(&cctx->fdevice->miscdev); + of_platform_depopulate(&rpdev->dev); cctx->rpdev = NULL;