From patchwork Thu Oct 20 02:40:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9385789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B9978608A7 for ; Thu, 20 Oct 2016 02:41:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB4F82993D for ; Thu, 20 Oct 2016 02:41:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A01F829954; Thu, 20 Oct 2016 02:41:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55FD729995 for ; Thu, 20 Oct 2016 02:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757463AbcJTCkZ (ORCPT ); Wed, 19 Oct 2016 22:40:25 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:33754 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757524AbcJTCkY (ORCPT ); Wed, 19 Oct 2016 22:40:24 -0400 Received: by mail-pf0-f169.google.com with SMTP id 128so26593468pfz.0 for ; Wed, 19 Oct 2016 19:40:23 -0700 (PDT) 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; bh=tCNBUvuhZgpNOQe5dBLDFOfYbdlaIaRsqFeO+Nnh3Qo=; b=eE0cXbVkFY9BM5iAmzePSfZazgdckxsWB8ngizeMXVG9x3bll9iQnU4rAzTV6iAJ9D szms/4vgvPW5Q0j6oDintIHspxKh9MYrSEVF3VGjoZJwLf+Yb3+jZZ9ULzpWKB/ILf0u u/kcKFnaSW2o2gKnMe86M2bC7CY8lm5nWF9j8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tCNBUvuhZgpNOQe5dBLDFOfYbdlaIaRsqFeO+Nnh3Qo=; b=huAL9tMl2EiTH7EDsbCs6M0AUYH2S23niNmVk+NOjXtwAdP2V1iS7IsCsutccM7ynn of7g52P96nt3rx79DAe69GhuOdGr3BRQUTxf+Skn5e4rRIPdEPANFSLruNZZpzWKpHEu eaQhSJLhr1l2llC41twVOlvxgANgsxQLeTmf7ZHw76OZAfqjWq+HQwlIy+m00qlc7IAF fztDawgpXSwsugC6NalPhZexjPdtBGd+ZQqzQt64pwaQ4pEPx4nW9xyabyUG5qye2BRi UQYSpVTiGtJqLKreSVdZcun/RzctSFDd7bhLLfbtkjz3dKLdZ29bD9VRwBblhgzacK0j FNLA== X-Gm-Message-State: AA6/9RlPTUMRbC04vbbgcnDah4/8jseTsgjahuVNhHpEh5Y0JFBSVAHow5dyfYqZaldgWLC7 X-Received: by 10.99.119.72 with SMTP id s69mr13998305pgc.11.1476931223351; Wed, 19 Oct 2016 19:40:23 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id s85sm66780616pfi.17.2016.10.19.19.40.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 19:40:22 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/11] remoteproc: Assign kref to rproc_vdev Date: Wed, 19 Oct 2016 19:40:06 -0700 Message-Id: <1476931212-1806-6-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1476931212-1806-1-git-send-email-bjorn.andersson@linaro.org> References: <1476931212-1806-1-git-send-email-bjorn.andersson@linaro.org> Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No functional change Signed-off-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 10 ++++++++++ drivers/remoteproc/remoteproc_internal.h | 1 + drivers/remoteproc/remoteproc_virtio.c | 10 ++++++---- include/linux/remoteproc.h | 3 +++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 4309996f4335..c978907498d0 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -356,6 +356,8 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, if (!rvdev) return -ENOMEM; + kref_init(&rvdev->refcount); + rvdev->rproc = rproc; /* parse the vrings */ @@ -384,6 +386,14 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, return ret; } +void rproc_vdev_release(struct kref *ref) +{ + struct rproc_vdev *rvdev = container_of(ref, struct rproc_vdev, refcount); + + list_del(&rvdev->node); + kfree(rvdev); +} + /** * rproc_handle_trace() - handle a shared trace buffer resource * @rproc: the remote processor diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 4cf93ca2816e..fe5a570b6c2b 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -49,6 +49,7 @@ struct rproc_fw_ops { void rproc_release(struct kref *kref); irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); int rproc_boot_nowait(struct rproc *rproc); +void rproc_vdev_release(struct kref *ref); /* from remoteproc_virtio.c */ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index 01870a16d6d2..0d1ad3ed149d 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -282,14 +282,13 @@ static const struct virtio_config_ops rproc_virtio_config_ops = { * Never call this function directly; it will be called by the driver * core when needed. */ -static void rproc_vdev_release(struct device *dev) +static void rproc_virtio_dev_release(struct device *dev) { struct virtio_device *vdev = dev_to_virtio(dev); struct rproc_vdev *rvdev = vdev_to_rvdev(vdev); struct rproc *rproc = vdev_to_rproc(vdev); - list_del(&rvdev->node); - kfree(rvdev); + kref_put(&rvdev->refcount, rproc_vdev_release); put_device(&rproc->dev); } @@ -313,7 +312,7 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) vdev->id.device = id, vdev->config = &rproc_virtio_config_ops, vdev->dev.parent = dev; - vdev->dev.release = rproc_vdev_release; + vdev->dev.release = rproc_virtio_dev_release; /* * We're indirectly making a non-temporary copy of the rproc pointer @@ -325,6 +324,9 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) */ get_device(&rproc->dev); + /* Reference the vdev and vring allocations */ + kref_get(&rvdev->refcount); + ret = register_virtio_device(vdev); if (ret) { put_device(&rproc->dev); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index a05f4569a2a0..dbcd967dd2e7 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -487,6 +487,7 @@ struct rproc_vring { /** * struct rproc_vdev - remoteproc state for a supported virtio device + * @refcount: reference counter for the vdev and vring allocations * @node: list node * @rproc: the rproc handle * @vdev: the virio device @@ -494,6 +495,8 @@ struct rproc_vring { * @rsc_offset: offset of the vdev's resource entry */ struct rproc_vdev { + struct kref refcount; + struct list_head node; struct rproc *rproc; struct virtio_device vdev;