Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3760583pxt; Tue, 10 Aug 2021 10:41:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv+ToxUrpeXcjDO/YTyuFpLwS8AoqMhKfjz0Z5EOWW+8FjRxotBbawP3swL0gwT074X3tl X-Received: by 2002:a17:906:3699:: with SMTP id a25mr28512474ejc.452.1628617273469; Tue, 10 Aug 2021 10:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617273; cv=none; d=google.com; s=arc-20160816; b=LKxUx4XsKRgbscK9z1sZoEI5+/MBTzUBFit1x7BrdUEKwWzxVbKB3GvVvt4sOUNwa9 1l3R02SqMCH7u7nEKLHR8z9h3fSGOglHOkhx64+8TKhC5PPI8niv8mpIneYdGlWAwv96 C1TFmDUowzkj3cg3KEOezp3vqOZBpkcjQN86Ag2qHML0p2neCt26kleUXzcFcgMSxiKm 2vTTa4UTKbd7Js4VikQTNBVwt6OdMkRiFjKfaOPtQtnMqrEEUNzq1w/AY4pTFXbGSr3a aFOHSrjboObilsiJPWoiF6U9g+YO+BndqTlhkE+WW2BZTHQ43Vvabvzuk//3YRVyaNoY sY6g== 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=wYVi4EnWq25m0Bme5eE5j+qSBsSUXSesPZPyZx96i6Q=; b=sbLiOIrgtLlSNEOf6FJM5JjyZw7YVn1YHS/hIYRnhNe/cmTzdLi6No4nP717g5Tpjg agTedmHsMCxfZzROTPQyFbZaLuZKXr2j2jFXsOJPgfmDx6CZXElrN8hBv6iTX7FTDn5h 7w5qyfR80J8+zYY3SM6/hytFuXCpebJyDrefTF1ssHLnzgtfiITmfZucjY2unjeuOf/q eaqY5je4RdeIaov8BlfBHUeIhvoNz9R5Kq+0NaWrOqnRVn3TYHq6swAsCdNeq2+2yIt5 5QwtDSA4HwJglPAsBTCmxzL8SA8ho0e5pJNruY5OIKIZujOyc21gH8lW7L4oGWvkF1fL Raog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QQGuDLvY; 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 ec52si20759834edb.428.2021.08.10.10.40.49; Tue, 10 Aug 2021 10:41:13 -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=@linuxfoundation.org header.s=korg header.b=QQGuDLvY; 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 S234585AbhHJRhf (ORCPT + 99 others); Tue, 10 Aug 2021 13:37:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:41122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233895AbhHJRf7 (ORCPT ); Tue, 10 Aug 2021 13:35:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F41D61008; Tue, 10 Aug 2021 17:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616919; bh=aHOct+bx6Cjbr8OP3I/zD54Bd2a8hWbeDkTTOfi7ePI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QQGuDLvYsFPam2E+aFG4fEVx3qmNk5GBTzVP4fzmqsOtp2nRj05ts1SKN0SSdTGt/ 6QcBzqzVjWxtqmQeuw9imTSxKCCdZxmWlNbP6RBC8eVfLr8GMvXAA3xKMwx/DFfun0 i584qkJ9cDi6D5CfROTAbkBs/oj21fSYRGng8g48= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dong Aisheng , Brian Norris , Stephen Boyd Subject: [PATCH 5.4 49/85] clk: fix leak on devm_clk_bulk_get_all() unwind Date: Tue, 10 Aug 2021 19:30:22 +0200 Message-Id: <20210810172949.896287140@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172948.192298392@linuxfoundation.org> References: <20210810172948.192298392@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: Brian Norris commit f828b0bcacef189edbd247e9f48864fc36bfbe33 upstream. clk_bulk_get_all() allocates an array of struct clk_bulk data for us (unlike clk_bulk_get()), so we need to free it. Let's use the clk_bulk_put_all() helper. kmemleak complains, on an RK3399 Gru/Kevin system: unreferenced object 0xffffff80045def00 (size 128): comm "swapper/0", pid 1, jiffies 4294667682 (age 86.394s) hex dump (first 32 bytes): 44 32 60 fe fe ff ff ff 00 00 00 00 00 00 00 00 D2`............. 48 32 60 fe fe ff ff ff 00 00 00 00 00 00 00 00 H2`............. backtrace: [<00000000742860d6>] __kmalloc+0x22c/0x39c [<00000000b0493f2c>] clk_bulk_get_all+0x64/0x188 [<00000000325f5900>] devm_clk_bulk_get_all+0x58/0xa8 [<00000000175b9bc5>] dwc3_probe+0x8ac/0xb5c [<000000009169e2f9>] platform_drv_probe+0x9c/0xbc [<000000005c51e2ee>] really_probe+0x13c/0x378 [<00000000c47b1f24>] driver_probe_device+0x84/0xc0 [<00000000f870fcfb>] __device_attach_driver+0x94/0xb0 [<000000004d1b92ae>] bus_for_each_drv+0x8c/0xd8 [<00000000481d60c3>] __device_attach+0xc4/0x150 [<00000000a163bd36>] device_initial_probe+0x1c/0x28 [<00000000accb6bad>] bus_probe_device+0x3c/0x9c [<000000001a199f89>] device_add+0x218/0x3cc [<000000001bd84952>] of_device_add+0x40/0x50 [<000000009c658c29>] of_platform_device_create_pdata+0xac/0x100 [<0000000021c69ba4>] of_platform_bus_create+0x190/0x224 Fixes: f08c2e2865f6 ("clk: add managed version of clk_bulk_get_all") Cc: Dong Aisheng Cc: stable@vger.kernel.org Signed-off-by: Brian Norris Link: https://lore.kernel.org/r/20210731025950.2238582-1-briannorris@chromium.org Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- drivers/clk/clk-devres.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -92,13 +92,20 @@ int __must_check devm_clk_bulk_get_optio } EXPORT_SYMBOL_GPL(devm_clk_bulk_get_optional); +static void devm_clk_bulk_release_all(struct device *dev, void *res) +{ + struct clk_bulk_devres *devres = res; + + clk_bulk_put_all(devres->num_clks, devres->clks); +} + int __must_check devm_clk_bulk_get_all(struct device *dev, struct clk_bulk_data **clks) { struct clk_bulk_devres *devres; int ret; - devres = devres_alloc(devm_clk_bulk_release, + devres = devres_alloc(devm_clk_bulk_release_all, sizeof(*devres), GFP_KERNEL); if (!devres) return -ENOMEM;