From patchwork Mon Oct 3 00:46:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9359889 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 8EEEC60459 for ; Mon, 3 Oct 2016 00:51:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A017928A45 for ; Mon, 3 Oct 2016 00:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9448E28A59; Mon, 3 Oct 2016 00:51:02 +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 1F7CC28A45 for ; Mon, 3 Oct 2016 00:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752314AbcJCAsN (ORCPT ); Sun, 2 Oct 2016 20:48:13 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34758 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752286AbcJCAqp (ORCPT ); Sun, 2 Oct 2016 20:46:45 -0400 Received: by mail-pa0-f54.google.com with SMTP id rz1so771255pab.1 for ; Sun, 02 Oct 2016 17:46:44 -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=9AZuy1MjZVTjRY6HW/CMBagZU3oTKXFylV1ozcq8iAg=; b=MABS8qtao+NGScnLb/UkvpLzlxt71uc+TM9l9HaoYRsm7qfNmIrAMr6jRH/DnIVlEk WJ2jhAjz25IbNzkG6yUIg2eqpbBEfUYfmV3urOgs7vehvcNhvYmsJlTILVfjdYnYD+jH QCBu1qbnvGk9xqyaJ8x7/AsD7jmxeiM3fetUU= 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=9AZuy1MjZVTjRY6HW/CMBagZU3oTKXFylV1ozcq8iAg=; b=B2wxGLddMUPNNXqLOc3aPtXEmumLIKMfVHa/NweRXJCgIe7oTye0OTpuZtAinleVLI B+Rgr0JQjHLdU9Au671Z0hQFAVWPKhjqJfYsXbsXxqDx/ZdpAvyOKRqxMPE0Z4nH8BiY 4KRn+OKdClCgsjUHtnxBW9dNuokXYMQCTAoCgNQCI2fWiG+ehkw4KqL5MrZoTLBP9xIz dk+2pca9Cn5eyp8pcuarIBF84nbLJQbmapvrZvalmfpxVZaHJ0L6UZdG1scnHcej9/Sv 8d0k1raYnegFjBU3oud9idNq+yJxkGXzQ0OvW7G6mTV9PJIrSvjxWuySecYAAUguKHfY mB7Q== X-Gm-Message-State: AA6/9RlqcIQ4ZCZeXdTB7moReUWcHoRLwvEhO11vpVE/V9hs7X+LzXd6bXZRz9rMGuitVnNF X-Received: by 10.67.5.33 with SMTP id cj1mr32810365pad.120.1475455604446; Sun, 02 Oct 2016 17:46:44 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Oct 2016 17:46:43 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Suman Anna Subject: [PATCH 2/2] remoteproc: Refactor rproc module locking Date: Sun, 2 Oct 2016 17:46:39 -0700 Message-Id: <1475455600-31689-2-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1475455600-31689-1-git-send-email-bjorn.andersson@linaro.org> References: <1475455600-31689-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 Lock the implementation as we hand out references to client drivers rather than when they try to boot the remote processor. This allows auto-booting remote processors to be shut down by unloading their module, in addition to first unbinding them. Signed-off-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ede3af14b9d0..c6bfb3496684 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1035,13 +1035,6 @@ static int __rproc_boot(struct rproc *rproc, bool wait) return ret; } - /* prevent underlying implementation from being removed */ - if (!try_module_get(dev->parent->driver->owner)) { - dev_err(dev, "%s: can't get owner\n", __func__); - ret = -EINVAL; - goto unlock_mutex; - } - /* skip the boot process if rproc is already powered up */ if (atomic_inc_return(&rproc->power) > 1) { ret = 0; @@ -1066,10 +1059,8 @@ static int __rproc_boot(struct rproc *rproc, bool wait) release_firmware(firmware_p); downref_rproc: - if (ret) { - module_put(dev->parent->driver->owner); + if (ret) atomic_dec(&rproc->power); - } unlock_mutex: mutex_unlock(&rproc->lock); return ret; @@ -1158,8 +1149,6 @@ void rproc_shutdown(struct rproc *rproc) out: mutex_unlock(&rproc->lock); - if (!ret) - module_put(dev->parent->driver->owner); } EXPORT_SYMBOL(rproc_shutdown); @@ -1188,6 +1177,12 @@ struct rproc *rproc_get_by_phandle(phandle phandle) mutex_lock(&rproc_list_mutex); list_for_each_entry(r, &rproc_list, node) { if (r->dev.parent && r->dev.parent->of_node == np) { + /* prevent underlying implementation from being removed */ + if (!try_module_get(r->dev.parent->driver->owner)) { + dev_err(&r->dev, "can't get owner\n"); + break; + } + rproc = r; get_device(&rproc->dev); break; @@ -1411,6 +1406,7 @@ EXPORT_SYMBOL(rproc_free); */ void rproc_put(struct rproc *rproc) { + module_put(rproc->dev.parent->driver->owner); put_device(&rproc->dev); } EXPORT_SYMBOL(rproc_put);