From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F272613B58A for ; Wed, 20 May 2026 01:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779242166; cv=none; b=bJD4mCwS3tS+hNa/s/W/KHs9NIfrxFMJM7yTBdxy/jyOpzSKJZbX9RmJoEKRsFjVP5PZ3TX8qkL2MEEgqN0+5Ix8IRHFItWxae5l4H3uT6oy9GFeHY8glwsM1ClpnlHTkTpHjDo1z7ExJA+gaLpqabNTGS8qN+c3JLzL5bdzHDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779242166; c=relaxed/simple; bh=J9yA9RayiTGG2cpWnf9UwyF1kHsWJ5VhhD4Nmdp2zYo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YKphtg1PNYbAp/O1a8nogSrNa2SKcmdhTygHPV1T7TIrigEeo8cvO4aK1a1w8JQ3TppQQ+99ZdWp5ceeqKTYIxeOCHhz6GOoil0thz2Sh27zP2JbPOD529Tx3lkWwLYH8X8DnG05oxcU3OozUqv1P8J0FSZ/hCbf5cQZO6MC4Hg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=jlvDqXGJ; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=VzHweeFc; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="jlvDqXGJ"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="VzHweeFc" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64JLmrkC2143814 for ; Wed, 20 May 2026 01:56:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= FEXZISxwxOfs11/JZOUamWM44R+suinsjRVfMvngbwE=; b=jlvDqXGJwc8fumDB pMENL0YIAPcwgf/njC9hynTVcTZRWnvYgb5f6Pg4DFPS8sAWTmGuJgM7jER4aA7w QTTjdu6OI7opuVR/ed7HIntdMJoGlfIKXJtdHndq0lQbnlodg/eTO5CVNHuQQmyd TDCuWO6+4mrYGp1iaDoGpDTPF9FBbsyoWSJvayHhY0WdbuUmhqPusCAd8V6Gblgj eXApAqVPQ+/HprykzOxkg164s1wrsUEljFVwRK+l9P1VRu0a27Bdpqz7IAtQK2nv LwbdUqD8AdeYIkG1VilbyQr2/Da4NzNOkdBExvk9TFUoSUUdgPrordYKx4S/Dg7o +DMO+A== Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e8t3tjd4v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 20 May 2026 01:56:03 +0000 (GMT) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2ba115ab6bbso45055325ad.3 for ; Tue, 19 May 2026 18:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1779242163; x=1779846963; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=FEXZISxwxOfs11/JZOUamWM44R+suinsjRVfMvngbwE=; b=VzHweeFcxRPlWBfszrA8lsYkxsmp25RI9z5sRMmNJOZdguGcdH2rL+GKolRKDHBU0B OeuOb7MUh/C1+A3cvDT430pLtNWwT0wmnWZ8Cp2Tzfj9/X1unpjSqnQj5NZn+clrjPKS vl04LgWFBFOm6HXXThJ841BnR2ruZ5qFn2YuJ7fMCGT+n6/JOws7GhyHU9AOh1MuJgu3 LMQet70u0eG2NEGRXJaIv5CEBGuyyycaqogz/gH9YuNEC5z5IMR6GBvnPssJFPzEj/m7 G0vTsQ9zSaY0byQZKburnkVrNM66csKWsThIGEGo4HiWeueC/TttkAsfn8FIHXbo1V1C LSQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779242163; x=1779846963; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FEXZISxwxOfs11/JZOUamWM44R+suinsjRVfMvngbwE=; b=U4Goiit3MTeKowaksodieymU8fbgrrsttKE5gSbXhhbf5AK4IPrWEftnhcyUmd8+Ry PQWDByUiotQTjqkbmk4UtbxP7TtFCvIivaLJK9Uub2T3LP/2LMwFFuZw+eIcq4jhNM0+ dZuQ/XMK403733O6E+ALSDBb2z2HbADOLpP15Tc7Ro5x2zaea5XttUbSUjRGULWE61O2 Ge1CCWbnlBZdq0rCBuM1wbZOb6HqfifpZfRDVFdRl1w5tsBi+1/fRH8o/k2ukzK4eWbS ljynhDETutSn9ESoZ3lBxKqyU+FXrNc1Tw3E12U1u0D0OcBxxBAfUjGKKxNm4D/n0WCY 0rrw== X-Forwarded-Encrypted: i=1; AFNElJ8Aw6l5mIyESVsayS/D+ePYB5aJP0XAL5AshjibRxiecrrWoZjERBV2kVv/TeIFmB+RNDMRO2/FZ8deYEI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5GQHtqZnweNp4kFXYNViVYRutHqa8iTVNJi2u7YGjjhvyXeuT TQN+EoFDCprpdsXWfCzFi1IbSy8a4y/UVm65rC3u++KE7FA3g9nS/VKYbLg8CO4WJDSoymF7T9t awWkVK6cOuaYHwJMlXPWWWbwHqVuLyiMX5NVsuIAT56hKBbysrjWNVi3UI75TDJtwvsg= X-Gm-Gg: Acq92OG90f/4rLpEl2UEckORw+wKktyiYB7HmOOkkyATt9pBsvXnbO6NbjquKTITENk hWpLAqdwMnHyzlhHRgTG39gjlsSXR4i/q9x/dybRdOdVSdoyG51ih+7BYnjmKn1nUhs+48EGeS0 TlbI4TF9i7uLadTAxCXXvFLnH7X/J6+K1xLoYWvlSYJapz8N/0jEsezkQd/+qJwjmzXV73fWNc9 rQhkbH8en7DkrOQCL5GOE+xEg7iuS1DdJUbSFkmy3TKFnMO8CVsOY+RyYgrNPWPViWsRVOh7GC2 NDmf8keAWtUn4nFVfWFJeB5SD6v4ye7tC6KuzJK6ut/BKUNFosfqjoil9hLbl0tyeq9VXYpb9QI hoZ3b2jq+e00u3/0meoXqOL0/+/aYMRt46VTNX/7JISazdMZqqkk3crB2cKtXGiT2JF0MXwgVLS XEsVgipBf8pgw= X-Received: by 2002:a17:903:3c6e:b0:2bd:8c9a:a684 with SMTP id d9443c01a7336-2bd8c9aa6famr221079035ad.4.1779242162664; Tue, 19 May 2026 18:56:02 -0700 (PDT) X-Received: by 2002:a17:903:3c6e:b0:2bd:8c9a:a684 with SMTP id d9443c01a7336-2bd8c9aa6famr221078795ad.4.1779242162173; Tue, 19 May 2026 18:56:02 -0700 (PDT) Received: from [10.133.33.129] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2be2f604fdfsm53223025ad.18.2026.05.19.18.55.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 May 2026 18:56:01 -0700 (PDT) Message-ID: <5b3785a1-0f53-4b61-bc18-880091c2ce12@oss.qualcomm.com> Date: Wed, 20 May 2026 09:55:56 +0800 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] coresight: fix resource leaks on path build failure To: James Clark Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Suzuki K Poulose , Mike Leach , Leo Yan , Alexander Shishkin , Mathieu Poirier , Tingwei Zhang , Greg Kroah-Hartman References: <20260513-fix-memory-leak-issue-v1-1-49822d7bc7d4@oss.qualcomm.com> Content-Language: en-US From: Jie Gan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=feCdDUQF c=1 sm=1 tr=0 ts=6a0d14b3 cx=c_pps a=MTSHoo12Qbhz2p7MsH1ifg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=c92rfblmAAAA:8 a=EUspDBNiAAAA:8 a=KKAkSRfTAAAA:8 a=Rcy_sKP7lcXEsWT_VP8A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=GvdueXVYPmCkWapjIL-Q:22 a=GvGzcOZaWPEFPQC_NcjD:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: 9FpjO304FL9Cn591In5zYlTbamzuIvs4 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTIwMDAxNSBTYWx0ZWRfXxblx8XbhwKLo dsCenBJLi0wfkCetGnHeOALuHDBWpxK//Hy0cMSruaGlvT0GprfjFxeeNz90K0CQdpAL1qI1KcM vdmociYaUMJB9tTtkrNFeGZc1uBGmiGFRNH8ISsmLl+9Iq58FJkbWUWwCZbs3aR+qD2XS05ig1/ CUwRu4JT8L9hq2kMKezzWuIPezCL4jIH+P9fC+umz/WvsoxV+WDn8n6dcL3J72sSThAdYtWl7jK s1Qe3fKn/9uTKirFA7bOh+JKlaheWVjIs37PFiC8y3ltRoPFsT17PqggZzai4DGKCNS0R5HXshp 74uM9R7+M4R1UAuzfw+XYG1RVdkixHHeG+cxB6z83YA0Sb2H1UiSVZord8ahgWl7HfwaZfbOKzn EXyggTwGh23OfkDSwjpQB4hWHzN6XsOx2i5t0mQiciwfo/4wj1TRQ/d2cQRYQpwAKbBMOcUsz7g T7L1YHIKiMBgKxc1SDA== X-Proofpoint-GUID: 9FpjO304FL9Cn591In5zYlTbamzuIvs4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-19_06,2026-05-18_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605200015 On 5/19/2026 9:57 PM, James Clark wrote: > > > On 13/05/2026 2:32 am, Jie Gan wrote: >> Two related leaks when _coresight_build_path() encounters an error after >> coresight_grab_device() has already incremented the pm_runtime, module, >> and device references for a node: >> >> 1. In _coresight_build_path(), if kzalloc_obj() for the path node fails >>     after coresight_grab_device() succeeds, coresight_drop_device() was >>     never called, permanently leaking all three references. >> >> 2. In coresight_build_path(), on failure the partial path was freed with >>     kfree(path) instead of coresight_release_path(path).  kfree() only >>     frees the coresight_path struct itself; it does not iterate path_list >>     to call coresight_drop_device() and kfree() for each coresight_node >>     already added by deeper recursive calls, leaking both the pm_runtime, >>     module, and device references and the node memory for every element >>     on the partial path. >> >> Fix both by adding coresight_drop_device() in the OOM unwind of >> _coresight_build_path(), and replacing kfree(path) with >> coresight_release_path(path) in coresight_build_path(). >> >> Fixes: 32b0707a4182 ("coresight: Add try_get_module() in >> coresight_grab_device()") >> Fixes: b3e94405941e ("coresight: associating path with session rather >> than tracer") >> Signed-off-by: Jie Gan >> --- >>   drivers/hwtracing/coresight/coresight-core.c | 6 ++++-- >>   1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/ >> hwtracing/coresight/coresight-core.c >> index 46f247f73cf6..c1354ea8e11d 100644 >> --- a/drivers/hwtracing/coresight/coresight-core.c >> +++ b/drivers/hwtracing/coresight/coresight-core.c >> @@ -825,8 +825,10 @@ static int _coresight_build_path(struct >> coresight_device *csdev, >>           return ret; >>       node = kzalloc_obj(struct coresight_node); >> -    if (!node) >> +    if (!node) { >> +        coresight_drop_device(csdev); >>           return -ENOMEM; >> +    } >>       node->csdev = csdev; >>       list_add(&node->link, &path->path_list); >> @@ -851,7 +853,7 @@ struct coresight_path *coresight_build_path(struct >> coresight_device *source, >>       rc = _coresight_build_path(source, source, sink, path); >>       if (rc) { >> -        kfree(path); >> +        coresight_release_path(path); >>           return ERR_PTR(rc); >>       } >> >> --- >> base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83 >> change-id: 20260513-fix-memory-leak-issue-034b4a45265e >> >> Best regards, > > Looks good to me, but sashiko is complaining: https://sashiko.dev/#/ > patchset/20260513-fix-memory-leak-issue- > v1-1-49822d7bc7d4%40oss.qualcomm.com > > I'm trying to understand why it's saying that, but I think the scenario > is that if there are multiple correct paths to a sink, when one path > partially fails and a second path succeeds you could get a path_list > with some garbage entries in it. I think the coresight_release_path is added to address this situation. We suffered the path partially failure, and we need release all nodes already added to the path. > > That's kind of a different and existing issue to the one you've fixed, > and assumes that multiple paths to one sink are possible, which I'm not > sure is supported? Each path is unique. We only deal with the issue path for balancing the reference count. Thanks, Jie > > It might be as easy as breaking the loop early for any return value > other than -ENODEV, but I'll leave it to you to decide whether to do > that here or not. > > Reviewed-by: James Clark >