From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 272FC33F8C6 for ; Wed, 18 Mar 2026 04:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773807973; cv=none; b=W6Q2R77J99fjVrGE96XWY3qFAIh1QPfygphW01KfYY21/Na8933+X9kNyMhNcUnH03ncZVBziYbi9xDXw3EC5oZ63y900izM1E+hnTQGoNrU1+1KswsKH9HQG6TE5LMCEUy4g4DKcP5vsk9LIpYWs0Br6jchuNVGyUTZWrVs5Hg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773807973; c=relaxed/simple; bh=ao9pSc5sCw1GKQta3ufNSBs2/9w6iO/iOUzMVs1r/cc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VnCqLhA2fX9MGrWtqSrn6s33VieiWpCZHG2HbRwsYAzb80w7ramp0bc+XterUNb95FEb7YQxTFaKx9PcaeZc00OL6SM+vzfegx20lq66wy/QQ3E+J62h6AkDxhNb+wJ4/jD55aZl9WGhTxgQW6/0Aa02/xn9P/INPu7PXQATazU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kjMVcqtI; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kjMVcqtI" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2aae146b604so41245535ad.3 for ; Tue, 17 Mar 2026 21:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773807969; x=1774412769; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mS6wQL3flAzxGUNqpCFuEf3Disb75RCg1Pcn89gYA7Y=; b=kjMVcqtIaUZpb1hqixdNEhuHaA/V+FtH3DPnNiWf5RE1pQn+XkkgLyEyi0aWuOHhhM 8JKscMu2+ifSBrmaWr4NnZPkM2MWTUm/eqyQlrZEr2oqyjxYh/H/cvGxpV2xLzEQ35ZH /CKRd81AQxTNMFpCGArIUBRkWNl5JDwIBRRtoEPtuDS+p39sipdLod15MH6426ytRH3z 1rbUJUc4qAhxPLyS4oesKFYXh6H4VzW9GNmtAHrsUd5YLY2mkpw106SsEGN4hIX+gv/f 2evbuOZCMDPuiEs5nFptfZW5ua4fV6m+UKzFoRiVyZhyjAi1MZ9B1Y6ETKGqiUa2j3uW ZnCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773807969; x=1774412769; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mS6wQL3flAzxGUNqpCFuEf3Disb75RCg1Pcn89gYA7Y=; b=EKJTqlxItHtS0k4zvrY+bMW/74KW8SXo47vICp16T2dNBu2XSrZguRJKD3S79ZTHpa pE4BNE2ftU2YJzJLJvm47oLnxnREb+LnuiuJYxzEu2AEGygUczwjimxdIbaLC4I7s/4V 35P5dRMYWvMt8w/MgMveNmUbN62GraiJQJL3Ir0NSdajrss2tB/XtKPYlkoUqL+UHrYk JGOqi3RdUtmDYd0zFfqKtKVXcgYc5JbF5jLZvQggAi6DzAT1YrMG+fEfnCfgRhi4AaGZ Q6h+OuLuE5Uc/EK+JjqSBZskoolaVKEFnH9YfI6kqi8oVOyTpi//o/oLjnrHAxOfGAnf rwbw== X-Forwarded-Encrypted: i=1; AJvYcCXQ+bMUHObxi9cSN8D2pn9BK0V3PW5X1xx4n1w1rzbGLjv2hW84hT2tfsInhRKweTL0XhE5bX1adQVShMM=@vger.kernel.org X-Gm-Message-State: AOJu0YzJUsFdEetFFp8DyadVtv082wCRD25SEMlJgFoWsKEFRVrSkHLO 3mzVCCZMNR5zPTwFVG5pgSQWBRPuTGgHVs/IN4QsOCPxkLOqVQLuxMhW X-Gm-Gg: ATEYQzwi8Wu2vfb+0M3GT+OUOPvRuLMdcdIu6+xXLoZ5T6aWCcEWvEbX8tUVEublGNi G4UBpBEqHF65x4xYusvDFswzSkKf2YWdj6x4+PY9A7DOUXentHwHZkhR/WAgZPXbr0jyxPXFbwk 4me+Kib52O7F+WB6/V4JVlIVmoQ7KEkuIp/uaEbE3uM1fq1PmFJOt5mxMZgjFhBKwCf+1XtjlRn 4gv7nZ6tessSKCxawsrqbgYeFzvuLbTigQGpgOujpX6yCsEZ78ouIUYm/ajhjcRtkzoNRAh2XVU v0ILIX4Ot4f6XYZF29rIeGMD2jyNg8ZHvNV5U9C7fKkLvZiSZDt4k3nI58lqq9QpO65wm+vJ9Je FklY1Vt5tZcVNpvkLdX1t9o1U4nHYgsgXViKX7ieytGtRNLObEHX0gClOotNwiJfAxxGEthKijh 5GaDyXByibsrUq/rVIZMbTaKob+IF5lSmaYc0= X-Received: by 2002:a17:903:2c06:b0:2b0:5fbe:12ff with SMTP id d9443c01a7336-2b06e3d3502mr21630435ad.30.1773807969311; Tue, 17 Mar 2026 21:26:09 -0700 (PDT) Received: from google.com ([2402:7500:a44:85b:1959:174c:5a7c:eeda]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b06e41927bsm13325195ad.10.2026.03.17.21.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 21:26:08 -0700 (PDT) Date: Wed, 18 Mar 2026 12:26:04 +0800 From: Kuan-Wei Chiu To: Gui-Dong Han Cc: Georgi Djakov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, akaieurus@gmail.com, me@ziyao.cc Subject: Re: [PATCH] interconnect: debugfs: fix devm_kstrdup and kfree mismatch Message-ID: References: <20260318024815.7655-1-hanguidong02@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260318024815.7655-1-hanguidong02@gmail.com> On Wed, Mar 18, 2026 at 10:48:15AM +0800, Gui-Dong Han wrote: > debugfs_write_file_str() uses standard kfree() to release old strings. > Initializing src_node and dst_node with devm_kstrdup() creates a memory > management mismatch. If a user writes to these debugfs nodes, the > devm-allocated memory is freed via kfree(), leaving a dangling pointer > in the device resource list that can lead to a double free. > > Fix this by using standard kstrdup() instead. Since the interconnect > subsystem is strictly built-in and cannot be unloaded as a module, there > is no exit path requiring manual cleanup of these strings. The error > handling path is also simplified by taking advantage of the fact that > kfree(NULL) is a safe no-op. > > Fixes: 8cc27f5c6dd1 ("interconnect: debugfs: initialize src_node and dst_node to empty strings") > Signed-off-by: Gui-Dong Han LGTM. Thanks for the patch. Reviewed-by: Kuan-Wei Chiu Regards, Kuan-Wei > --- > I noticed this memory management mismatch while working on similar > debugfs string initialization fixes [1] recently. > > [1] https://lore.kernel.org/driver-core/20260317185920.43387-1-hanguidong02@gmail.com/ > --- > drivers/interconnect/debugfs-client.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/interconnect/debugfs-client.c b/drivers/interconnect/debugfs-client.c > index 5107bff53173..08df9188ef94 100644 > --- a/drivers/interconnect/debugfs-client.c > +++ b/drivers/interconnect/debugfs-client.c > @@ -150,10 +150,13 @@ int icc_debugfs_client_init(struct dentry *icc_dir) > return ret; > } > > - src_node = devm_kstrdup(&pdev->dev, "", GFP_KERNEL); > - dst_node = devm_kstrdup(&pdev->dev, "", GFP_KERNEL); > - if (!src_node || !dst_node) > + src_node = kstrdup("", GFP_KERNEL); > + dst_node = kstrdup("", GFP_KERNEL); > + if (!src_node || !dst_node) { > + kfree(dst_node); > + kfree(src_node); > return -ENOMEM; > + } > > client_dir = debugfs_create_dir("test_client", icc_dir); > > -- > 2.43.0 >