From patchwork Thu Feb 11 23:46:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12084451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C570C433DB for ; Thu, 11 Feb 2021 23:50:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8CD064E42 for ; Thu, 11 Feb 2021 23:50:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8CD064E42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iTgV6wP73oa+O6CoB1/3KLqnaQ4O0jwN/tDnSRVq6es=; b=XJykb+I2sxj/yKn5cAkYj7tSO U/5FJJQxWoHVWCcl/jMr4FlTLFrLFsLKCJPRaq5NQViB8Qfpci+iE8QntnipP+cmDMv1Z4/DXGTgK g7KnjgmW5NYo6JyWepMSvsvy3pJ48IRKZNITmmi2FF8w8r6Sg0S8ubUeTUVhw33P2vbXZXhCfvR8x n6CHI6HgroclmLDU5MxdEI5XNezSyKtsu8VYGQ4+eq3FxZhpVzPIk0vW57TisEu2GJZY/XvGL1FhR 0fXd3M0bqUMM5bBvVZhtvKPbChacqOjIR7LOHMKCdQC5Vz06biR8kqUdW7cZg8IPq9ePZBwjb2DCY wcULncwXQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lALhQ-0005Fw-Hv; Thu, 11 Feb 2021 23:48:40 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lALfY-0004MY-V1 for linux-arm-kernel@lists.infradead.org; Thu, 11 Feb 2021 23:46:53 +0000 Received: by mail-pg1-x535.google.com with SMTP id m2so5071771pgq.5 for ; Thu, 11 Feb 2021 15:46:44 -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=LDZKl3InJry2uc3BIzMNfTpvGwSU2yaFbHElAaRG5qQ=; b=QVkVXmDnViCOE4jMf8kqA4U6tgVMTUzDp7YWDf8qKVzsyuWdqJhID9SGoYxyf1TLZ3 IHn7iWfULllzfOiZU2OE5sTOID0KCZ2h6PKXRV+3DklKjnP4sHeZdYYKEkxTj/y3uvXh LhfbAerRSvBobO9kA/1bB/Z2FOz63FEGDPHD/ezqbvZ2CSdZTnOu8Wu3S3mEvvFLP2Pq UhuvTt1Kyp+gOMfJtzBwmUS5baknbeoC50+LBUhuX7YhZsDM/7RxSVQ+zkKDie2ZaZAC jKg8lNGUaa6UMh1k9OF6BfupyXjgnkq0HOanbxABWxSWU3KErERJDjX6zVV2t0SyJy9V DmFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LDZKl3InJry2uc3BIzMNfTpvGwSU2yaFbHElAaRG5qQ=; b=WYTllD0zRxAsfUp1yta5/Awi5WCmNRoxH1kMfqg3nQ0fECUiOlPhdVoL1T1hLuRy0U 61lnsviguIUKaCIFvFj+U+bHFOjqO4lOhr6bnaLDNdRbaetVrjxDErxIVTtUkoEsczOI LMnygT2XJnVisjPk/I0iiNBzTmlioaV0qIX8+rRMLuZ/Z1UqSwprcKIVLwuiGlG56spL R0/FRL6XVH9A8LRAWo/ARCXQ797zAJrG/eSdcMrvGkHVlsdr/Vbu9D9omVR09PrpfMAw zWI68+sm8YHhPuC+BG2p/FPL03cL5fRBe18NFoVWvTjHb614kOkiUyGiIEVEbIITTltz tyVA== X-Gm-Message-State: AOAM530L65wbS8aMcrv49A4iYq4uGSDs1uBgdyOicamBkFgNC+2vjo0O XfutF2CLLjsYUeRNWm99+w8kPw== X-Google-Smtp-Source: ABdhPJz/vVr3OJXyZlMWYsG92ngxqPN50LTfIeQ7B9iEBdz2c/s+YMUMpzvB5cqkzSlJlvTwOBxIvA== X-Received: by 2002:a05:6a00:22d6:b029:1cb:35ac:d8e0 with SMTP id f22-20020a056a0022d6b02901cb35acd8e0mr408493pfj.17.1613087202720; Thu, 11 Feb 2021 15:46:42 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id iq6sm5932740pjb.6.2021.02.11.15.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 15:46:42 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, arnaud.pouliquen@st.com Subject: [PATCH v5 14/19] remoteproc: Add return value to function rproc_shutdown() Date: Thu, 11 Feb 2021 16:46:22 -0700 Message-Id: <20210211234627.2669674-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211234627.2669674-1-mathieu.poirier@linaro.org> References: <20210211234627.2669674-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210211_184645_116094_80BA0ECA X-CRM114-Status: GOOD ( 18.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, mcoquelin.stm32@gmail.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a return value to function rproc_shutdown() in order to properly deal with error conditions that may occur. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 19 ++++++++++++++----- include/linux/remoteproc.h | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 9a77cb6d6470..62f708662052 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1966,7 +1966,7 @@ EXPORT_SYMBOL(rproc_boot); * returns, and users can still use it with a subsequent rproc_boot(), if * needed. */ -void rproc_shutdown(struct rproc *rproc) +int rproc_shutdown(struct rproc *rproc) { struct device *dev = &rproc->dev; int ret; @@ -1974,15 +1974,19 @@ void rproc_shutdown(struct rproc *rproc) ret = mutex_lock_interruptible(&rproc->lock); if (ret) { dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); - return; + return ret; } - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING) { + ret = -EPERM; goto out; + } /* if the remote proc is still needed, bail out */ - if (!atomic_dec_and_test(&rproc->power)) + if (!atomic_dec_and_test(&rproc->power)) { + ret = -EBUSY; goto out; + } ret = rproc_stop(rproc, false); if (ret) { @@ -1994,7 +1998,11 @@ void rproc_shutdown(struct rproc *rproc) rproc_resource_cleanup(rproc); /* release HW resources if needed */ - rproc_unprepare_device(rproc); + ret = rproc_unprepare_device(rproc); + if (ret) { + atomic_inc(&rproc->power); + goto out; + } rproc_disable_iommu(rproc); @@ -2007,6 +2015,7 @@ void rproc_shutdown(struct rproc *rproc) rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); + return ret; } EXPORT_SYMBOL(rproc_shutdown); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e5f52a12a650..5b49c4018e90 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -664,7 +664,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len, u32 da, const char *name, ...); int rproc_boot(struct rproc *rproc); -void rproc_shutdown(struct rproc *rproc); +int rproc_shutdown(struct rproc *rproc); int rproc_detach(struct rproc *rproc); int rproc_set_firmware(struct rproc *rproc, const char *fw_name); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);