From patchwork Sat Sep 15 00:37:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 146734 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1279207ljw; Fri, 14 Sep 2018 17:37:42 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ/35PsPEu1qOSCpP90tNBlU/hifHK0jRWYIlzJjz4mQj/Ryhbdmqs0iRchkYcDXB5hSnqc X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr14156101pga.181.1536971862192; Fri, 14 Sep 2018 17:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536971862; cv=none; d=google.com; s=arc-20160816; b=N9Cqh4LNfW243K1V80jzrJv0T6B1WOyBiIH9HB9XvGrhMUzUCtcr1onu7vd/hGsoeH MAxKp3blVp+lbmG41wGdPEnQiFGaE9MpVsBZoO1D/qQu8xPvywWjxvPso5/3RzgO+wxt 1u/Do27t4dVKrN2szhk2CE2zXUblyn62tosMLCgQnrdmJ4UOFyOrZZhR3crll+evt/BQ X7RVhAFkWTKLfw98f525qm+0fh//P0EE/PK+fjc2C1zfUWZhWgxCfYgoMT/zKfWNMG+w B8jvqBceNtf20m0eSUB5B1Kf9pXh12PvqTbzcd0AK177xO8uIjT6V7HA0tQ8PaH0vAie Hv9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=IB39Nnh1RI4spJd8J9S80MU30mSuXvMxoKfq0ImOMGw=; b=0Zr9/2wBnre1LNWasmUVatmEdjPfhkm0gydWA987q9NVEHzDaucb7994VIH+SLJebY nQKxd2svyQXW5gIma5eG0jb5BiE2UWCV5gRlWjmXEea4dP8Ror9moNsQItYKF7U8bUt1 gUd1o5R43U/7lQtwnvvNCOaaOBGPYbWn3qVSRJcmv14mWI+AVDzbpD/c4650YPMLFSgV RIc+6jU3K/KURgDVQt4JGVlTIfmc2tRhKiqx8fAK1NHZczmngqkLsErvvu6Ynw27JJ1K ZJXaVR0lZUChWyhzuHqOABegGoJUtDpJO7x1SZqK1lHoZ39n4FtQxKdqVE27P92SnzX3 YUQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=qz8QoENf; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21-v6si8751393pgs.520.2018.09.14.17.37.41; Fri, 14 Sep 2018 17:37:42 -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=@ti.com header.s=ti-com-17Q1 header.b=qz8QoENf; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727052AbeIOFyU (ORCPT + 32 others); Sat, 15 Sep 2018 01:54:20 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:42468 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725796AbeIOFyT (ORCPT ); Sat, 15 Sep 2018 01:54:19 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w8F0bR1t046767; Fri, 14 Sep 2018 19:37:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1536971847; bh=IB39Nnh1RI4spJd8J9S80MU30mSuXvMxoKfq0ImOMGw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=qz8QoENf1mqypDLikPBWqqbDexI8Q5dHoKzjbfgD/02p9UTSxp0RoyL5cX6wMBHgs hzDp6oSsPxQ7OEivXNKW+fVuMu5M2dm2uaC3zbojDwP8JxDSPAor39ebLOGmxPGtGy VeE80mhLywh5pEtvb5Nyx1sGCtONgxtApu3DaRhE= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w8F0bRZH032375; Fri, 14 Sep 2018 19:37:27 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 14 Sep 2018 19:37:28 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 14 Sep 2018 19:37:27 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w8F0bRDh002123; Fri, 14 Sep 2018 19:37:27 -0500 Received: from localhost (irmo.dhcp.ti.com [128.247.58.153]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id w8F0bRx13339; Fri, 14 Sep 2018 19:37:27 -0500 (CDT) From: Suman Anna To: Bjorn Andersson CC: Ohad Ben-Cohen , Loic Pallardy , Arnaud Pouliquen , , , Suman Anna Subject: [PATCH 1/5] remoteproc: Fix unbalanced boot with sysfs for no auto-boot rprocs Date: Fri, 14 Sep 2018 19:37:21 -0500 Message-ID: <20180915003725.17549-2-s-anna@ti.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180915003725.17549-1-s-anna@ti.com> References: <20180915003725.17549-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The remoteproc core performs automatic boot and shutdown of a remote processor during rproc_add() and rproc_del() for remote processors supporting 'auto-boot'. The remoteproc devices not using 'auto-boot' require either a remoteproc client driver or a userspace client to use the sysfs 'state' variable to perform the boot and shutdown. The in-kernel client drivers hold the corresponding remoteproc driver module's reference count when they acquire a rproc handle through the rproc_get_by_phandle() API, but there is no such support for userspace applications performing the boot through sysfs interface. The shutdown of a remoteproc upon removing a remoteproc platform driver is automatic only with 'auto-boot' and this can cause a remoteproc with no auto-boot to stay powered on and never freed up if booted using the sysfs interface without a matching stop, and when the remoteproc driver module is removed or unbound from the device. This will result in a memory leak as well as the corresponding remoteproc ida being never deallocated. Fix this by holding a module reference count for the remoteproc's driver during a sysfs 'start' and releasing it during the sysfs 'stop' operation. Signed-off-by: Suman Anna --- drivers/remoteproc/remoteproc_sysfs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- 2.18.0 Acked-by: Arnaud Pouliquen diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 47be411400e5..2142b3ea726e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. */ +#include #include #include "remoteproc_internal.h" @@ -100,14 +101,27 @@ static ssize_t state_store(struct device *dev, if (rproc->state == RPROC_RUNNING) return -EBUSY; + /* + * prevent underlying implementation from being removed + * when remoteproc does not support auto-boot + */ + if (!rproc->auto_boot && + !try_module_get(dev->parent->driver->owner)) + return -EINVAL; + ret = rproc_boot(rproc); - if (ret) + if (ret) { dev_err(&rproc->dev, "Boot failed: %d\n", ret); + if (!rproc->auto_boot) + module_put(dev->parent->driver->owner); + } } else if (sysfs_streq(buf, "stop")) { if (rproc->state != RPROC_RUNNING) return -EINVAL; rproc_shutdown(rproc); + if (!rproc->auto_boot) + module_put(dev->parent->driver->owner); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL;