Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3542627pxb; Mon, 1 Mar 2021 12:50:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5IsPkIVfeLZ8hlx+6IevSfbUSCTgbGi8xCe6/rjhvRRLURZBpXIAnFwIdtXcpX5CoYUsN X-Received: by 2002:a17:906:4c56:: with SMTP id d22mr18410515ejw.426.1614631823007; Mon, 01 Mar 2021 12:50:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614631823; cv=none; d=google.com; s=arc-20160816; b=lXiio9K3BjXMc8bdlstWSH2D/TQdsb2dCPkfeWXuKuyvhpynV+OaXZJbEw/8RZKuEn 29ngIIsm4xeZTOufQ5TpnyHJQ5VPYolig8jWBJICBnqQqbWLX1TnAgem6o1uyMxEu7uj NTO75WYKQJKhcr5onAzf1onnN2F7KA4HXvt6E7iGbV9OB+S1FM0JoHuIMkYdR0Xa1UgF K/j7eW/u0erWGZXFxpzeK5t8mAwdz+a7xkV4XXNslbsboFHud+oZxLt0tXZ4RiZhK1/D Csn6RfaQH8FxTBDxBxFiODRqIwPI3WjGRPV+8WDKU+a0swmzJ7k7zjeQzD46rAB2C/Lq xRrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WwSSPwPTk7dWsVT3Ug3lj7LFbN5Oq5miLhQ7mfKCdNI=; b=keujUbUmWVpW9J+ES1aArURDUJELl2wcsumLmMiPiDVlxP42teIui5lU5mLPpoOhev 86nHGJG02ZRl2+pJqHDQ4CjKNNIO7asX/S/f7xw3+EZRj0zBpfgFDXgUJcS8TAUcCSCi 5JhS46sCHiQpYZk9ZTQYC/IQsLWlwrihfJjdW97Rt3Ie6bNInBmkHzV7Y6FsCxQ+Q+to 1iIxJGH6b4koKs+RhIAOgfyGee4Lx6RJrgtpV4ewCO7A3iJqMsLquKkFXdLFYBZ2GlvC 3EsmUSxHszigXpqwdnW3DFoFrQRkDxrzYwRdbJomkEOoOJbTTgDDtZO22ljCVhrVcvKs WQLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ngJ6K4Q8; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr14si8027013ejc.470.2021.03.01.12.50.00; Mon, 01 Mar 2021 12:50:22 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=ngJ6K4Q8; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242464AbhCAUqx (ORCPT + 99 others); Mon, 1 Mar 2021 15:46:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:37622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235420AbhCARIe (ORCPT ); Mon, 1 Mar 2021 12:08:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 20EFC64E22; Mon, 1 Mar 2021 16:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616911; bh=Iy9kRPaR+bK/aY1mDsfPGvJ80ZFkIG90snHKzTQecEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ngJ6K4Q8xLCs1SWFn8viDRaIAl4wyvX8BdVgxQK4vNh4mXpiSoJgTdipDNujEFPyQ 0X7EHEl+H+osB3zZCqU4+Y9EGMctmppt46Q+u/5Y6lHvpLFuldsGsRLrw9XOTrjFM/ YiPXtfzuRj2D347Ktlm+qwpsQ/rXXniqn0qpWluM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ulf Hansson , Arnd Bergmann , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Sasha Levin Subject: [PATCH 4.19 138/247] amba: Fix resource leak for drivers without .remove Date: Mon, 1 Mar 2021 17:12:38 +0100 Message-Id: <20210301161038.424723940@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Uwe Kleine-König [ Upstream commit de5d7adb89367bbc87b4e5ce7afe7ae9bd86dc12 ] Consider an amba driver with a .probe but without a .remove callback (e.g. pl061_gpio_driver). The function amba_probe() is called to bind a device and so dev_pm_domain_attach() and others are called. As there is no remove callback amba_remove() isn't called at unbind time however and so calling dev_pm_domain_detach() is missed and the pm domain keeps active. To fix this always use the core driver callbacks and handle missing amba callbacks there. For probe refuse registration as a driver without probe doesn't make sense. Fixes: 7cfe249475fd ("ARM: AMBA: Add pclk support to AMBA bus infrastructure") Reviewed-by: Ulf Hansson Reviewed-by: Arnd Bergmann Link: https://lore.kernel.org/r/20210126165835.687514-2-u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König Signed-off-by: Sasha Levin --- drivers/amba/bus.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 41b706403ef72..2380ebd9b7fda 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -284,10 +284,11 @@ static int amba_remove(struct device *dev) { struct amba_device *pcdev = to_amba_device(dev); struct amba_driver *drv = to_amba_driver(dev->driver); - int ret; + int ret = 0; pm_runtime_get_sync(dev); - ret = drv->remove(pcdev); + if (drv->remove) + ret = drv->remove(pcdev); pm_runtime_put_noidle(dev); /* Undo the runtime PM settings in amba_probe() */ @@ -304,7 +305,9 @@ static int amba_remove(struct device *dev) static void amba_shutdown(struct device *dev) { struct amba_driver *drv = to_amba_driver(dev->driver); - drv->shutdown(to_amba_device(dev)); + + if (drv->shutdown) + drv->shutdown(to_amba_device(dev)); } /** @@ -317,12 +320,13 @@ static void amba_shutdown(struct device *dev) */ int amba_driver_register(struct amba_driver *drv) { - drv->drv.bus = &amba_bustype; + if (!drv->probe) + return -EINVAL; -#define SETFN(fn) if (drv->fn) drv->drv.fn = amba_##fn - SETFN(probe); - SETFN(remove); - SETFN(shutdown); + drv->drv.bus = &amba_bustype; + drv->drv.probe = amba_probe; + drv->drv.remove = amba_remove; + drv->drv.shutdown = amba_shutdown; return driver_register(&drv->drv); } -- 2.27.0