From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33BD727815D for ; Mon, 26 Jan 2026 15:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769442514; cv=none; b=X4Rhksd9YZCjmrMIiR9Hv08IdWtrdLI+UcwcjW1qyBhwAtDx16bjGrfTUlbTenqQSzARK+gUoExDPW2RVj+j580SJwUqoYL1IC+Y7kAqGYDD+YIBHjJDGbuYRXXv2vs6pOAZ7QIf24mp0ETGjnWGVtISK2e/md5gtRQmZ8Pq2kc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769442514; c=relaxed/simple; bh=/dWrSK3dKWHIfOE7xeSg1B5Ax12lGKK+fyIZ5kT5T0M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K7uZbcA6RisVtSfWzwYpDh5vsUcWWwiFTYwe8fN0D2D6KNdTIZYZCW9CoHq+sKDqHL3hd/OsRk3Mpw80ykJYkboRs0XHIBkLOYxA4GxitFdRiVOpWiAovUf/Vb/MLrLbuBQqPHKmmEp9qbcSPRlmrruKiP9d81XWzKO029W/GZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C660C339; Mon, 26 Jan 2026 07:48:24 -0800 (PST) Received: from [10.57.68.157] (unknown [10.57.68.157]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C1C703F73F; Mon, 26 Jan 2026 07:48:29 -0800 (PST) Message-ID: <062c51c2-082d-4771-83df-3e5bfa90927d@arm.com> Date: Mon, 26 Jan 2026 15:48:28 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/8] coresight: Fix memory leak in coresight_alloc_device_name() Content-Language: en-GB To: Leo Yan , Mike Leach , James Clark , Alexander Shishkin , Greg Kroah-Hartman , Mathieu Poirier , Mao Jinlong Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20260126-arm_coresight_refactor_dev_register-v2-0-b5a3c0441c15@arm.com> <20260126-arm_coresight_refactor_dev_register-v2-1-b5a3c0441c15@arm.com> From: Suzuki K Poulose In-Reply-To: <20260126-arm_coresight_refactor_dev_register-v2-1-b5a3c0441c15@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Leo On 26/01/2026 13:52, Leo Yan wrote: > The memory leak detector reports: > > echo clear > /sys/kernel/debug/kmemleak > modprobe coresight_funnel > rmmod coresight_funnel > > # Scan memory leak and report it > echo scan > /sys/kernel/debug/kmemleak > cat /sys/kernel/debug/kmemleak > unreferenced object 0xffff0008020c7200 (size 64): > comm "modprobe", pid 410, jiffies 4295333721 > hex dump (first 32 bytes): > d8 da fe 7e 09 00 ff ff e8 2e ff 7e 09 00 ff ff ...~.......~.... > b0 6c ff 7e 09 00 ff ff 30 83 00 7f 09 00 ff ff .l.~....0....... > backtrace (crc 4116a690): > kmemleak_alloc+0xd8/0xf8 > __kmalloc_node_track_caller_noprof+0x2c8/0x6f0 > krealloc_node_align_noprof+0x13c/0x2c8 > coresight_alloc_device_name+0xe4/0x158 [coresight] > 0xffffd327ecef8394 > 0xffffd327ecef85ec > amba_probe+0x118/0x1c8 > really_probe+0xc8/0x3f0 > __driver_probe_device+0x88/0x190 > driver_probe_device+0x44/0x120 > __driver_attach+0x100/0x238 > bus_for_each_dev+0x84/0xf0 > driver_attach+0x2c/0x40 > bus_add_driver+0x128/0x258 > driver_register+0x64/0x138 > __amba_driver_register+0x2c/0x48 > > Change to use devm_krealloc_array() for allocation fwnode_list so that > the device model can automatically release the memory when the module > is unloaded. > > Fixes: 0f5f9b6ba9e1 ("coresight: Use platform agnostic names") > Signed-off-by: Leo Yan > --- > drivers/hwtracing/coresight/coresight-core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index c660cf8adb1c7cafff8f85e501f056e4e151e372..ed304f292b7b02e89c59053d43f88fbf663cc993 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -1546,7 +1546,7 @@ char *coresight_alloc_device_name(struct coresight_dev_list *dict, > if (idx < 0) { > /* Make space for the new entry */ > idx = dict->nr_idx; > - list = krealloc_array(dict->fwnode_list, > + list = devm_krealloc_array(dev, dict->fwnode_list, > idx + 1, sizeof(*dict->fwnode_list), This is wrong. This would mean, the array gets released when the "dev" goes away and thats not good. This is a per-driver list, not a per-device list. Also, please remember that, we need to keep that node alive when the device goes away, to make sure to allocate the same device name when if/it comes back. May be, you could release the list and array, when the "driver" goes away. Kind regards Suzuki > GFP_KERNEL); > if (ZERO_OR_NULL_PTR(list)) { >