From patchwork Mon Oct 3 00:46:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9359873 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 5850660459 for ; Mon, 3 Oct 2016 00:48:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6819628A45 for ; Mon, 3 Oct 2016 00:48:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BE8528A59; Mon, 3 Oct 2016 00:48:56 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B62B928A45 for ; Mon, 3 Oct 2016 00:48:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bqrPR-0006SP-Vd; Mon, 03 Oct 2016 00:47:09 +0000 Received: from mail-pf0-x22d.google.com ([2607:f8b0:400e:c00::22d]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bqrPM-0006Ra-2k for linux-arm-kernel@lists.infradead.org; Mon, 03 Oct 2016 00:47:05 +0000 Received: by mail-pf0-x22d.google.com with SMTP id 190so10900441pfv.0 for ; Sun, 02 Oct 2016 17:46:43 -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; bh=1Q/XR1a1QANrZMNhT5ED7/vKEXbf/ML7srQLbwQfF50=; b=Pnhl12BV9VR9xb2B+xDt/+3lwH/0SzVo/S1/amLnxsAYa4dj75Ew2MWXsqwIoPKF8P 4QrDecHihFrs4nANb4NE8BNRqugLadMra03Q1qDIzQgx/48GL7zHiLba3o8F8ZHxWT/J xz+eLJ3ntR25jOlWRObwe4uS6/nPDFSSJsJPU= 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; bh=1Q/XR1a1QANrZMNhT5ED7/vKEXbf/ML7srQLbwQfF50=; b=L7MuM4xyhiEcs+KUav2wxD+YVXRA9rYz0oN5OkFxG5QtE22g/TAHjyGt6vXqWMxKyC 4SmpFSwIegfCvqovEls25Ms5M3udxsU/VVeY0G/FunnOkMCydkEWmirf2PMj32AhJKkN VS5HSvwzeruWnc4asSVT3yF2166A/jAE0BBNX2U62Kdi7HN5u/uygodVrOAoVmnMw5wc iwDEhH7M3Vx8ERweLwMWdP5J1/hW4MBS+NdBFd65tfE1Gb4dirhTsvAn2vxx/YETSLxO 1RoM7Riq9wAFy51QAv3zrxiwMcaPhK519KNnDAJaFh7nylCmFh/Vwv0sX1nH75l1mf1F IZtg== X-Gm-Message-State: AA6/9RmR9T7m8PJjgx4kLeok4Hf0Isyywu7TpC0OlPDazlkirCqye28lDiO6A3wJO2+di4Kf X-Received: by 10.98.56.147 with SMTP id f141mr12229152pfa.83.1475455602786; Sun, 02 Oct 2016 17:46:42 -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 b88sm42386713pfe.66.2016.10.02.17.46.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Oct 2016 17:46:41 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Patrice Chotard Subject: [PATCH 1/2] remoteproc: Split driver and consumer dereferencing Date: Sun, 2 Oct 2016 17:46:38 -0700 Message-Id: <1475455600-31689-1-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161002_174704_242403_B54D53A5 X-CRM114-Status: GOOD ( 16.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, Jonathan Corbet , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In order to be able to lock a rproc driver implementations only when used by a client, we must differ between the dereference operation of a client and the implementation itself. This patch brings no functional change. Signed-off-by: Bjorn Andersson --- Documentation/remoteproc.txt | 6 +++--- drivers/remoteproc/da8xx_remoteproc.c | 4 ++-- drivers/remoteproc/omap_remoteproc.c | 4 ++-- drivers/remoteproc/qcom_q6v5_pil.c | 4 ++-- drivers/remoteproc/qcom_wcnss.c | 4 ++-- drivers/remoteproc/remoteproc_core.c | 21 ++++++++++++++++++--- drivers/remoteproc/st_remoteproc.c | 4 ++-- drivers/remoteproc/ste_modem_rproc.c | 4 ++-- drivers/remoteproc/wkup_m3_rproc.c | 4 ++-- include/linux/remoteproc.h | 1 + 10 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Documentation/remoteproc.txt b/Documentation/remoteproc.txt index ef0219fa4bb4..f07597482351 100644 --- a/Documentation/remoteproc.txt +++ b/Documentation/remoteproc.txt @@ -101,9 +101,9 @@ int dummy_rproc_example(struct rproc *my_rproc) On success, the new rproc is returned, and on failure, NULL. Note: _never_ directly deallocate @rproc, even if it was not registered - yet. Instead, when you need to unroll rproc_alloc(), use rproc_put(). + yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). - void rproc_put(struct rproc *rproc) + void rproc_free(struct rproc *rproc) - Free an rproc handle that was allocated by rproc_alloc. This function essentially unrolls rproc_alloc(), by decrementing the rproc's refcount. It doesn't directly free rproc; that would happen @@ -131,7 +131,7 @@ int dummy_rproc_example(struct rproc *my_rproc) has completed successfully. After rproc_del() returns, @rproc is still valid, and its - last refcount should be decremented by calling rproc_put(). + last refcount should be decremented by calling rproc_free(). Returns 0 on success and -EINVAL if @rproc isn't valid. diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c index 12823d078e1e..1afac8f31be0 100644 --- a/drivers/remoteproc/da8xx_remoteproc.c +++ b/drivers/remoteproc/da8xx_remoteproc.c @@ -261,7 +261,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) return 0; free_rproc: - rproc_put(rproc); + rproc_free(rproc); return ret; } @@ -290,7 +290,7 @@ static int da8xx_rproc_remove(struct platform_device *pdev) disable_irq(drproc->irq); rproc_del(rproc); - rproc_put(rproc); + rproc_free(rproc); return 0; } diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c index 01e234cb9157..fa63bf2eb885 100644 --- a/drivers/remoteproc/omap_remoteproc.c +++ b/drivers/remoteproc/omap_remoteproc.c @@ -215,7 +215,7 @@ static int omap_rproc_probe(struct platform_device *pdev) return 0; free_rproc: - rproc_put(rproc); + rproc_free(rproc); return ret; } @@ -224,7 +224,7 @@ static int omap_rproc_remove(struct platform_device *pdev) struct rproc *rproc = platform_get_drvdata(pdev); rproc_del(rproc); - rproc_put(rproc); + rproc_free(rproc); return 0; } diff --git a/drivers/remoteproc/qcom_q6v5_pil.c b/drivers/remoteproc/qcom_q6v5_pil.c index 05b04573e87d..2e0caaaa766a 100644 --- a/drivers/remoteproc/qcom_q6v5_pil.c +++ b/drivers/remoteproc/qcom_q6v5_pil.c @@ -875,7 +875,7 @@ static int q6v5_probe(struct platform_device *pdev) return 0; free_rproc: - rproc_put(rproc); + rproc_free(rproc); return ret; } @@ -885,7 +885,7 @@ static int q6v5_remove(struct platform_device *pdev) struct q6v5 *qproc = platform_get_drvdata(pdev); rproc_del(qproc->rproc); - rproc_put(qproc->rproc); + rproc_free(qproc->rproc); return 0; } diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c index 1917de7db91c..f5cedeaafba1 100644 --- a/drivers/remoteproc/qcom_wcnss.c +++ b/drivers/remoteproc/qcom_wcnss.c @@ -585,7 +585,7 @@ static int wcnss_probe(struct platform_device *pdev) return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); free_rproc: - rproc_put(rproc); + rproc_free(rproc); return ret; } @@ -598,7 +598,7 @@ static int wcnss_remove(struct platform_device *pdev) qcom_smem_state_put(wcnss->state); rproc_del(wcnss->rproc); - rproc_put(wcnss->rproc); + rproc_free(wcnss->rproc); return 0; } diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3da566b0d437..ede3af14b9d0 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1307,7 +1307,7 @@ static struct device_type rproc_type = { * On success the new rproc is returned, and on failure, NULL. * * Note: _never_ directly deallocate @rproc, even if it was not registered - * yet. Instead, when you need to unroll rproc_alloc(), use rproc_put(). + * yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). */ struct rproc *rproc_alloc(struct device *dev, const char *name, const struct rproc_ops *ops, @@ -1386,7 +1386,22 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, EXPORT_SYMBOL(rproc_alloc); /** - * rproc_put() - unroll rproc_alloc() + * rproc_free() - unroll rproc_alloc() + * @rproc: the remote processor handle + * + * This function decrements the rproc dev refcount. + * + * If no one holds any reference to rproc anymore, then its refcount would + * now drop to zero, and it would be freed. + */ +void rproc_free(struct rproc *rproc) +{ + put_device(&rproc->dev); +} +EXPORT_SYMBOL(rproc_free); + +/** + * rproc_put() - release rproc reference * @rproc: the remote processor handle * * This function decrements the rproc dev refcount. @@ -1411,7 +1426,7 @@ EXPORT_SYMBOL(rproc_put); * * After rproc_del() returns, @rproc isn't freed yet, because * of the outstanding reference created by rproc_alloc. To decrement that - * one last refcount, one still needs to call rproc_put(). + * one last refcount, one still needs to call rproc_free(). * * Returns 0 on success and -EINVAL if @rproc isn't valid. */ diff --git a/drivers/remoteproc/st_remoteproc.c b/drivers/remoteproc/st_remoteproc.c index 6f056caa8a56..ae8963fcc8c8 100644 --- a/drivers/remoteproc/st_remoteproc.c +++ b/drivers/remoteproc/st_remoteproc.c @@ -262,7 +262,7 @@ static int st_rproc_probe(struct platform_device *pdev) return 0; free_rproc: - rproc_put(rproc); + rproc_free(rproc); return ret; } @@ -277,7 +277,7 @@ static int st_rproc_remove(struct platform_device *pdev) of_reserved_mem_device_release(&pdev->dev); - rproc_put(rproc); + rproc_free(rproc); return 0; } diff --git a/drivers/remoteproc/ste_modem_rproc.c b/drivers/remoteproc/ste_modem_rproc.c index 53dc17bdd54e..03d69a9a3c5b 100644 --- a/drivers/remoteproc/ste_modem_rproc.c +++ b/drivers/remoteproc/ste_modem_rproc.c @@ -257,7 +257,7 @@ static int sproc_drv_remove(struct platform_device *pdev) rproc_del(sproc->rproc); dma_free_coherent(sproc->rproc->dev.parent, SPROC_FW_SIZE, sproc->fw_addr, sproc->fw_dma_addr); - rproc_put(sproc->rproc); + rproc_free(sproc->rproc); mdev->drv_data = NULL; @@ -325,7 +325,7 @@ static int sproc_probe(struct platform_device *pdev) free_rproc: /* Reset device data upon error */ mdev->drv_data = NULL; - rproc_put(rproc); + rproc_free(rproc); return err; } diff --git a/drivers/remoteproc/wkup_m3_rproc.c b/drivers/remoteproc/wkup_m3_rproc.c index 3811cb522af3..18175d0331fd 100644 --- a/drivers/remoteproc/wkup_m3_rproc.c +++ b/drivers/remoteproc/wkup_m3_rproc.c @@ -208,7 +208,7 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev) return 0; err_put_rproc: - rproc_put(rproc); + rproc_free(rproc); err: pm_runtime_put_noidle(dev); pm_runtime_disable(dev); @@ -220,7 +220,7 @@ static int wkup_m3_rproc_remove(struct platform_device *pdev) struct rproc *rproc = platform_get_drvdata(pdev); rproc_del(rproc); - rproc_put(rproc); + rproc_free(rproc); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index c321eab5054e..930023b7c825 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -493,6 +493,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, void rproc_put(struct rproc *rproc); int rproc_add(struct rproc *rproc); int rproc_del(struct rproc *rproc); +void rproc_free(struct rproc *rproc); int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc);