Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp259436pxa; Wed, 26 Aug 2020 09:50:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykvMas5aX7Kc26P6xy/eZLh8WLM2EwkjT9QRs951gVOO/Na6iGqzu3J/2RYW0ZQVTf+wDI X-Received: by 2002:a17:906:b896:: with SMTP id hb22mr8912067ejb.351.1598460618812; Wed, 26 Aug 2020 09:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598460618; cv=none; d=google.com; s=arc-20160816; b=yKBa0qJbPwmn+ys6CugNM1fx47+7mIBpiw8Wrr+xMhIBt/bATFWN5l0nNigqFwH8S6 2YZsRpew5XjGLGT00brLFWnKhGZfDiSnwUwGJ7Vo00cmxfWXZ+EePClA8zKmqigNRy19 stLYnVVzMOmWjDUSYdtRbIdzMNzFEIM2WK2T8tvmjzOo/VvjxbNBj6ael6Ab/sGDXe2a 37jINpBYYQp4e8YGRs/BiWKnT9qLmXzGrrQRcU9Amf7g6sJscwlhldwAaLAJHZ/b1hnq JNnlTlUGT327OV4LgLj5yaQM3HWudR0S8e37+8SQPnwkpaLiukBcLO2ajN6TuS58GsFA 8csA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oxBIu0NnSAiLhfjGgDwxzLw/4/EIRT2u79pWVsdwMLg=; b=yNdQOR7uakRcAS9FiHHw1sPCp42kyqwKR9jKeS6yGP2sHT7keoKK1ZSZD5cJNZi1Ix zK566IQYXLLu4O7vJs6LXvCPdmI6AR9E8bZi8xgJ4i5IzAXxxAkA5yv/RfSW7T/psMzO iFGVd+Bt6SFyVRbRdYPnbB27f/MBKBHJB54zCzQTvi6a/OzqejHXy6rtgYI6ozldRg44 lVi5Y6aTXncX3EDrg3v4h8QtyDCotJXO+GqBWAVNKG7y0+ZWh1LWRfkLTtjUlubdW95k mUlfAGpSk0rC+TcDmLQ0XQhA77RNdWl0NRKhxnPrb6EAFoWJXChD2avYPJdh2NO2qqtf j/9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="k+qNTns/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si1897615ejc.145.2020.08.26.09.49.56; Wed, 26 Aug 2020 09:50:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="k+qNTns/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727020AbgHZQrI (ORCPT + 99 others); Wed, 26 Aug 2020 12:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728116AbgHZQps (ORCPT ); Wed, 26 Aug 2020 12:45:48 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FCFEC061786 for ; Wed, 26 Aug 2020 09:45:44 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id 2so1139524pjx.5 for ; Wed, 26 Aug 2020 09:45: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 :mime-version:content-transfer-encoding; bh=oxBIu0NnSAiLhfjGgDwxzLw/4/EIRT2u79pWVsdwMLg=; b=k+qNTns/opkjJEZ2Dfhp3nSo+/gW/l2mqzUB7ZbUnn1SNzUJkPTwH85YhOHspy5Vzm 8C9wf8/Fd1RmmE1VOJ6mzWgbzVHJJxiF/O6nCczbJWfkB8iAkjc0ABmO2n4fWC38V+3s BzxF3qvJtruDwI6eBJMgLFBei+5H23OQsItgXm5BhM/wP5PU0e13zhErdowD2rtvN01U YwtSnXT8idDk1mrJl/WS+YHu/eq/oYezZMR5Tr8PCDtJTA0j5Mh/rG5Cr9FSUtztzxyj yZRvbD2PyEjw7yGVLtIh4QWTABpdtvrsR7SWP2Xl3oJZbgV+uWPqgTS+BUXIz8hrN2S+ imdQ== 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=oxBIu0NnSAiLhfjGgDwxzLw/4/EIRT2u79pWVsdwMLg=; b=N7O9AThc9R+f/aBbiuA0wgNDoi3JQ6MWWV9ESRygtUYjXileA4j0yCwPfrhRBAsCyy NPxD2gRTC/c3U4Pm7o4e21cRZjjA9FH5Tc0mHTD8OoNabt31M9xPg1ziBPVCZPgtZNcx WzY+iMACCTyTN9p0rRrzr/NV2hcKeoXeeagRi7Es6bAstF3ohMVHzhzp7wdgm5tuoAdG MwHVreeQkHgrUiTp7IJOUbsGVFMpXUSnxeaNG+n6eltoP28sD866RdeSQBvELS4ie7rx gkRTeHClc/LBFUqTQI9Cth0NSROCMCqir3Q3qttrzfL+qJvLUm5p30PxAQdmh+tmg0uH U3yg== X-Gm-Message-State: AOAM530jLqeDzLGEYheO8PJii2LOK6REidIJIyHOzFDKCB2KpbJ31Sv5 cJ/tqujNQeCS5oN/HsPPcQTplg== X-Received: by 2002:a17:902:7603:: with SMTP id k3mr12394135pll.113.1598460343792; Wed, 26 Aug 2020 09:45:43 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id u3sm2548878pjn.29.2020.08.26.09.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2020 09:45:43 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/13] remoteproc: Refactor rproc delete and cdev release path Date: Wed, 26 Aug 2020 10:45:28 -0600 Message-Id: <20200826164529.224476-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200826164529.224476-1-mathieu.poirier@linaro.org> References: <20200826164529.224476-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor function rproc_del() and rproc_cdev_release() to take into account scenarios where the remote processor has been attached to. If the remote processor has been started by the remoteproc core then switch it off, and if it was attached to detach from it. This heuristic is simple and can be enhanced easily if there is a need to. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_cdev.c | 7 ++++++- drivers/remoteproc/remoteproc_core.c | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 3a3830e27050..18cffbe588c1 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -87,8 +87,13 @@ static int rproc_cdev_release(struct inode *inode, struct file *filp) { struct rproc *rproc = container_of(inode->i_cdev, struct rproc, cdev); - if (rproc->cdev_put_on_release && rproc->state == RPROC_RUNNING) + if (!rproc->cdev_put_on_release) + return 0; + + if (rproc->state == RPROC_RUNNING) rproc_shutdown(rproc); + else if (rproc->state == RPROC_ATTACHED) + rproc_detach(rproc); return 0; } diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 95bb40b4ebb3..5586582f54c5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2346,7 +2346,10 @@ int rproc_del(struct rproc *rproc) return -EINVAL; /* TODO: make sure this works with rproc->power > 1 */ - rproc_shutdown(rproc); + if (rproc->state == RPROC_RUNNING) + rproc_shutdown(rproc); + else if (rproc->state == RPROC_ATTACHED) + rproc_detach(rproc); mutex_lock(&rproc->lock); rproc->state = RPROC_DELETED; -- 2.25.1