From patchwork Tue Oct 29 11:06:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 177997 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp4701044ill; Tue, 29 Oct 2019 04:07:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJNehKoWz+jNC4kVShgEnMTfETelro+SXFUWO3MXi51umRZTmdIAFxwOiEh2TxJmXFZyDS X-Received: by 2002:a17:906:34c8:: with SMTP id h8mr2553961ejb.135.1572347224602; Tue, 29 Oct 2019 04:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572347224; cv=none; d=google.com; s=arc-20160816; b=ZVeEm80BmC2ErJGLxUKRgEV0/LYgEwQV4r0GlWP6ywlI7PGXV+EkAtKs+9uX200j5O 8X/jQd8/CPQBG2pyaroMGoo0+mC2OIaYzBEuG3fboEYW5X98xYD4IwhOqbp79jDCeipM xazSu9XkgeO18kDMtC+J8vK+12A+FKxsIbwNt6S3vkPKwHb/dtWKNU17V5MqVPhCgX9l 7U5ecJWA+R19yXppG9QoMK+EJnphZFmMO7/sJzsmOx/UpvUwK7NLpTgNawsJ+zqJV3cf RPj/QHDB00DONeG3e1H85O7GcMG8WrN8UivBDfcFxv2P9zvWyVAHt/84mDiEgQiiQ814 JR5w== 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=688krb0cuXp8PBo5LNpKaF8uHqzMW0iPGXhDwBHrBV8=; b=Utl6jx2Bo7i5YmhZk64VewM2UuPURHgK6kPpdaRRFrAoizUf0gZCpjXbVEs30Pgjzd nDmaABeO67a1KBCOk+XvKFhdIMjM610j/10yVdFg9VYnTIe6jNKprExjcMw6hbMTFle/ GJwIYuhoVnyG48Qh/9RzN3dMFGdbcKFaEgrkHYS84+zGGCTojbK4M951+DyORAIsVu8w UHAtKonBV+CmA/l/aLY4uI9Lk9D3NW+kcszcOwK6K8qqCkSOnEXytNRYRcsYt7lMKUkt nf/yoth+BS0p7A9iuxe2Q1BYRbk/qiaVTYIDtKOIxoUdtcNGuAM24msv/disgcykqjIh ZJSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JNSO4JzG; 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 f37si9831622eda.190.2019.10.29.04.07.04; Tue, 29 Oct 2019 04:07:04 -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=JNSO4JzG; 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 S1732006AbfJ2LHD (ORCPT + 26 others); Tue, 29 Oct 2019 07:07:03 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:49544 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbfJ2LHD (ORCPT ); Tue, 29 Oct 2019 07:07:03 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x9TB70uh127536; Tue, 29 Oct 2019 06:07:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572347220; bh=688krb0cuXp8PBo5LNpKaF8uHqzMW0iPGXhDwBHrBV8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=JNSO4JzGcRk7WyDwSX6vmDdAHtZE7FLDUBJYGcnTIot1QIIJqcB0OrILTigX+JRZI D5jGvZwOBTf+Loq6pT2pLKj/gBxcbkooHMTA/wreqh2wrrqAt+r+qEUSLUZDe2+Fce d+Nl+0GRMwbVqcGfVsIs1phheEwHh+5ahd1XLv+I= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x9TB70KN106250 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 Oct 2019 06:07:00 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 29 Oct 2019 06:07:00 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 29 Oct 2019 06:07:00 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x9TB6vaX016819; Tue, 29 Oct 2019 06:06:58 -0500 From: Kishon Vijay Abraham I To: Stephen Boyd , Michael Turquette CC: , , Tomi Valkeinen , Tero Kristo , Kishon Vijay Abraham I Subject: [PATCH v2] clk: Fix memory leak in clk_unregister() Date: Tue, 29 Oct 2019 16:36:18 +0530 Message-ID: <20191029110618.7451-1-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191022185150.9B09B20B7C@mail.kernel.org> References: <20191022185150.9B09B20B7C@mail.kernel.org> 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 Memory allocated in alloc_clk() for 'struct clk' and 'const char *con_id' while invoking clk_register() is never freed in clk_unregister(), resulting in kmemleak showing the following backtrace. backtrace: [<00000000546f5dd0>] kmem_cache_alloc+0x18c/0x270 [<0000000073a32862>] alloc_clk+0x30/0x70 [<0000000082942480>] __clk_register+0xc8/0x760 [<000000005c859fca>] devm_clk_register+0x54/0xb0 [<00000000868834a8>] 0xffff800008c60950 [<00000000d5a80534>] platform_drv_probe+0x50/0xa0 [<000000001b3889fc>] really_probe+0x108/0x348 [<00000000953fa60a>] driver_probe_device+0x58/0x100 [<0000000008acc17c>] device_driver_attach+0x6c/0x90 [<0000000022813df3>] __driver_attach+0x84/0xc8 [<00000000448d5443>] bus_for_each_dev+0x74/0xc8 [<00000000294aa93f>] driver_attach+0x20/0x28 [<00000000e5e52626>] bus_add_driver+0x148/0x1f0 [<000000001de21efc>] driver_register+0x60/0x110 [<00000000af07c068>] __platform_driver_register+0x40/0x48 [<0000000060fa80ee>] 0xffff800008c66020 Fix it here. Fixes: fcb0ee6a3d331fb ("clk: Implement clk_unregister") Cc: Tomi Valkeinen Cc: Tero Kristo Signed-off-by: Kishon Vijay Abraham I --- drivers/clk/clk.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.17.1 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 1c677d7f7f53..ecd647258c8f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3835,6 +3835,7 @@ static void clk_core_evict_parent_cache(struct clk_core *core) void clk_unregister(struct clk *clk) { unsigned long flags; + struct clk_hw *hw; if (!clk || WARN_ON_ONCE(IS_ERR(clk))) return; @@ -3879,6 +3880,9 @@ void clk_unregister(struct clk *clk) __func__, clk->core->name); kref_put(&clk->core->ref, __clk_release); + hw = clk->core->hw; + free_clk(clk); + hw->clk = NULL; unlock: clk_prepare_unlock(); }