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: 77203 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp1407118qgf; Sun, 2 Oct 2016 17:49:05 -0700 (PDT) X-Received: by 10.98.95.197 with SMTP id t188mr33260412pfb.134.1475455745364; Sun, 02 Oct 2016 17:49:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si33788906pfl.295.2016.10.02.17.48.51; Sun, 02 Oct 2016 17:49:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752480AbcJCAs3 (ORCPT + 27 others); Sun, 2 Oct 2016 20:48:29 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:33646 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752288AbcJCAqp (ORCPT ); Sun, 2 Oct 2016 20:46:45 -0400 Received: by mail-pa0-f47.google.com with SMTP id cd13so52165612pac.0 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=lHusald8Eh9aEiHK6RDRNidC/ubOm1l3b2x6JKx57g9EOY9V/OOo2Vhfggh7/t8nzd t9REHv7q0FzurW6z+uvckkuqcOMrh6fZ2WHk3cEE2Jyeo4EcFFdj0lAMvqx3eoDnajGJ nHcumDuFXQLI8fv03/ozWa11ZP8t9BeJzTVp76M4DVSHNrclFd9ia+IpUMPE+kjsOcAy YXa2a8z3YA4FUdnVzcHcFbd6yuAvYqGRlO/DZ4CGQ9EQNh4NjtMSHy/e0lQBjmjJjTHN yTrRZWWYEzqe7h0aEfo9r0CsbCvI4sHeQJigydmd3MhdiCqLOhZWvOwPJ5pMdOlOZR5h jm9g== X-Gm-Message-State: AA6/9Rl6do6LX7WfZLmFn0IwyIOxEVkoSY9BYbgBwRECNt1AKOtb8zSG29kpe32agkLWwwGq 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.5.0 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);