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 314FA1D27B6; Fri, 19 Dec 2025 11:38:06 +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=1766144288; cv=none; b=lP3KfLqf1dsGeHq2QYnY7YSAMEhdxTXhwLfdKhr5pURboA3dN1zjEBFUitL9dDjRZ7AuhIsAYnucHlTD5FDF5x1muyGtYDIQlgr7Stl7cmx+ZfO4NkoGC3rxiXHG7DYmYScd8gUxO7bnJbNLVVQdvXJNATFzfYVR2a5FJtIz2lw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766144288; c=relaxed/simple; bh=zHGig3CuQ6Nlf/dQEirvPe68gAeQ1ot1Qt7FxB9iqBk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WYWWa8BJ34g7wULi0/PwTr1upuWplqf/ItaW4cjoCXdiJm1Bi01ozG1zxMe1Li8A+/+T5fNm4f0ehhnUKwB0lSO0YsAyMlWryjqSsqGGsMF/mOWRVn7X3Y+/llpB68CtgTqcdOLZvvZnp16/yNubAzwBRVXImz7c05lRU3kKVKs= 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 3CC65FEC; Fri, 19 Dec 2025 03:37:59 -0800 (PST) Received: from localhost (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EA68B3F73F; Fri, 19 Dec 2025 03:38:05 -0800 (PST) Date: Fri, 19 Dec 2025 11:38:03 +0000 From: Leo Yan To: Suzuki K Poulose Cc: Ma Ke , jie.gan@oss.qualcomm.com, james.clark@linaro.org, akpm@linux-foundation.org, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, mike.leach@linaro.org, stable@vger.kernel.org Subject: Re: [PATCH v2 RESEND] coresight: etm-perf: Fix reference count leak in etm_setup_aux Message-ID: <20251219113803.GC9788@e132581.arm.com> References: <20251219023949.12699-1-make24@iscas.ac.cn> <20251219094141.GA9788@e132581.arm.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: On Fri, Dec 19, 2025 at 09:59:54AM +0000, Suzuki K Poulose wrote: [...] > > diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c > > index 0db64c5f4995..2b34f818ba88 100644 > > --- a/drivers/hwtracing/coresight/coresight-platform.c > > +++ b/drivers/hwtracing/coresight/coresight-platform.c > > @@ -107,14 +107,16 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) > > * platform bus. > > */ > > dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); > > - if (dev) > > - return dev; > > /* > > * We have a configurable component - circle through the AMBA bus > > * looking for the device that matches the endpoint node. > > */ > > - return bus_find_device_by_fwnode(&amba_bustype, fwnode); > > + if (!dev) > > + dev = bus_find_device_by_fwnode(&amba_bustype, fwnode); > > + > > + put_device(dev); > > ^^ NAK, see below. > > > + return dev; > > } > > /* > > @@ -274,7 +276,6 @@ static int of_coresight_parse_endpoint(struct device *dev, > > of_node_put(rparent); > > of_node_put(rep); > > - put_device(rdev); > > This doesn't look good. We can't use the "dev" reliably without the > reference count. We are opening up use-after-free. My understanding is we don't grab a device from coresight_find_device_by_fwnode(). The callers only check whether the device is present on the bus; if it isn't, the driver defers probe. This is similiar to coresight_find_csdev_by_fwnode(), which calls put_device(dev) to release refcnt immediately. This is why I suggested the change, so the two functions behave consistently. Thanks, Leo