From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 A91E63C07A for ; Thu, 12 Mar 2026 17:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773336633; cv=none; b=AEz8fgtbnJV/ySCQPX/iTQP8dzlXL6D6Ikq3pveJMUF/OWSz83FR/X//eZeis6Y6QegXeEa3EvalyBd9EWGLO+xyzIFR8p8Hd4ZoTTlkyxpTNmGJMnLfq859axp6Z0v27Kxgtpi/JFtU0HQn+IsKMoVNs0WcabXThm6dZ8WD+Tk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773336633; c=relaxed/simple; bh=qNfYSVGIOrhVvdqZtId6YKo09GcseD8xFMjOFaFbZ8I=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:To:From:Subject: References:In-Reply-To; b=s5Pyxq4j2/O2W8znwbFwAA4rdaommzBzd5kqLgrFbN/YdwqGFYFeZ5CJqcm6LxUshDjYqvxkPbfdvQ3uEXBmk1g7EblpBQAfy2uuweV47OAzTZodmvABXHmM1CfwdZ+MH5sHV5hZEQFI7BaDB261l3Lx4CwiSN+KI9kxmV6iOKM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=eOcN8kbq; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="eOcN8kbq" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id AD434C415A9; Thu, 12 Mar 2026 17:30:50 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id BEEA16001B; Thu, 12 Mar 2026 17:30:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8B63F103686EE; Thu, 12 Mar 2026 18:30:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1773336628; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=ojA5kgEFX5C9rF7JLxEzCUAGdAQqEGLeKAjjT9Y7YhE=; b=eOcN8kbqOLqamC+20v9ynFsBO1M/Ja3dkiV5DndS47knCL5qs5Z7mjR+4cNQSWcPgAdFqs FRaLIXoDcJQIpGiHXJyYL6Ak1Al/JWYKC8fCMPNRMDyXcy0CozCSov6mVN0EImqLGrS8d2 oKXhMS7oRQDnI9r6ZmcbAimRl4C2tiXnRlulQe7V90XT1oSvkas3SsOcSiRVuOEKZaYoFA Xe3+PDe6qny8BzWr8RV1BVzM79dUDJaNPezA3Fa9xEaPbb/ilfO5XtkbZkHqO/fun+TGXq /lwB+B84HbEHPu4QX5xtgzWIwWvW3B6wXnxbn+XyUoXqOvdumhZwCnB5QJ5IBw== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 12 Mar 2026 18:30:22 +0100 Message-Id: Cc: "Marco Felsch" , , To: "Liu Ying" , "Andrzej Hajda" , "Neil Armstrong" , "Robert Foss" , "Laurent Pinchart" , "Jonas Karlman" , "Jernej Skrabec" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "David Airlie" , "Simona Vetter" From: "Luca Ceresoli" Subject: Re: [PATCH] drm/bridge: Fix refcount shown via debugfs for encoder_bridges_show() X-Mailer: aerc 0.20.1 References: <20260312-drm-misc-next-2026-03-05-fix-encoder-bridges-refcount-v1-1-b9ba3d844732@nxp.com> In-Reply-To: <20260312-drm-misc-next-2026-03-05-fix-encoder-bridges-refcount-v1-1-b9ba3d844732@nxp.com> X-Last-TLS-Session-Version: TLSv1.3 Hello Liu, Maxime, On Thu Mar 12, 2026 at 7:05 AM CET, Liu Ying wrote: > A typical bridge refcount value is 3 after a bridge chain is formed: > - devm_drm_bridge_alloc() initializes the refcount value to be 1. > - drm_bridge_add() gets an additional reference hence 2. > - drm_bridge_attach() gets the third reference hence 3. > > This typical refcount value aligns with allbridges_show()'s behaviour. > However, since encoder_bridges_show() uses > drm_for_each_bridge_in_chain_scoped() to automatically get/put the > bridge reference while iterating, a bogus reference is accidentally > got when showing the wrong typical refcount value as 4 to users via > debugfs. Fix this by caching the refcount value returned from > kref_read() while iterating and explicitly decreasing the cached > refcount value by 1 before showing it to users. Good point, indeed the refcount shown by /dri//encoder-0/bridges is by one unit higher than the one shown in /dri/bridges. I understand it's puzzling from a debugfs user point of view. As you noticed, this is because the _scoped loop holds an extra ref on the current bridge. For other reasons I proposed a mutex for stronger protection around the bridge chain [v2]. With the mutex the extra ref is redundant, so in [v2] the extra ref is removed, thus making your patch unneeded. However Maxime asked to keep the extra ref, and so my latest iteration [v4] still has the extra ref. That series is still on the mailing list, we are still in time to rediscuss it. @Maxime: based on the issue Liu is trying to work around, do you think it would make sense to go back to the initial approach for that series? I.e. drm_for_each_bridge_in_chain_scoped() grabs the chain lock, which is a superset of the per-bridge refcount, and thus the refcount can be dropped? This would remove the debugfs issue, slightly simplify drm_for_each_bridge_in_chain_scoped(), and introduce no new issues AFAIK. [v2] https://lore.kernel.org/all/20251003-drm-bridge-alloc-encoder-chain-mu= tex-v2-4-78bf61580a06@bootlin.com/ [v4] https://lore.kernel.org/all/20260113-drm-bridge-alloc-encoder-chain-mu= tex-v4-4-60f3135adc45@bootlin.com/ Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com