From patchwork Fri Jan 2 00:50:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1168 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315097; bh=E2Mwh2H2gMIeLHYBwJihrUCuUWec+lByo4KqW/rXcWA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=l6d7ErDcHoD/ckvhf+Oh2F2pvkT0D065CcxkP5SGUXxOOOgZ/4BrxXqV8hsxaR80C LrL4aVejzD2S+biu8Fy+5twYS3TIJd5o6B8lEAdkP2dw9aYWvlcaOUGhpcxogAR6ww CEihnURCf81C8QcXpTUMmikgLmzAw7SX0H9DTHpuPC5DVPIpQ7Q7p1pumBTf6Ib/dI wS0rYH50QhuucyrU11RAcwECjunvk/27iKNMbZANkJ2FADgQiuU3HiKFBQR1lP16X+ vPW5lKfdOf0yWkSwJXBhSph4eow7Lr2yee2O5parX02OaIr3bQTyBT53ME/hTnLwtb vVtwZnrFQB9JQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C2F6D68F58 for ; Thu, 1 Jan 2026 17:51:37 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id rPAtoj2suVln for ; Thu, 1 Jan 2026 17:51:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315096; bh=E2Mwh2H2gMIeLHYBwJihrUCuUWec+lByo4KqW/rXcWA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=F7SKfu08hcpofxChBSeHQe9VWR855JxOGFrDPVxO0UfBk/GDWFL8glPhPqbHA+NBw vgtqUoXutyircJD0qb53BFAFFsOphHbd9+I4F1AvqtBb+zPNq9zIPN8hlOW2nYxMXc fH36Z7mzOKrYTDcmAGuUr9F3vidKSiM4VUpreZ4y0IEQUoybCIv5pyvmwLYlNKTXrw HJlgDJeEmqCEqWLd4pO9NMbeTqU5N6COtg5TkU5W95uFFF3fAD2rZf+yiXnbrz6OI5 g8BUlPXs7K5pJs8p+5CNxTLCRO3mYyOF4yJ/4XCqQ1hIWd4RM6RmJF0umPHfiMX1G6 WuuyL1LrVNSgg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F0BA868F56 for ; Thu, 1 Jan 2026 17:51:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315095; bh=nwpGfLIxsKNTqNyE7PjZQsjB9SlAx580SZ91UpYAsmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gh5bxGPAVZKSYFXdwySPLJmjpX2N2nMoyAaLOaZZNMaCpg/coa2EgTHI1fPgPm8dE BBPNerGb51ilTKGEWQTWv7nCccMEBAyWPGMNtHUkL4u3laxTE3aMyyhcL726qpXaK4 JuwhNtK//7o13o0vtvEf/OTZn/5uO5WsDoS12UKb2kTHxHi9+fA8UTtKAEPulaq/Dv CfUhePVw5CpQrDAV9upMS+CsunqEMg6bRxnxZ7GmS48ZZT1MFzi9TrnyXfT0JznmjB K8okzEYOAw/QPnVojZJB98eLYplj9AsadjLcwhAQlh29AsOrlEMznjLr5ylDowItHF okgoux6Pq/eYQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4A03B68F58; Thu, 1 Jan 2026 17:51:35 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id Bowe3wSmuBgQ; Thu, 1 Jan 2026 17:51:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315091; bh=cTYW1yNJqFceXrOIJ6XIu+HKhgFNXrzA6XKuzlVvTuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U6d2/n9kI6lccYVCagiRGigb7va0BYW2nXevbTo+FmZbMplNEajBtzwBAXTMwPi8s 78BY4TU2k65LM+pfragkU9VgqmmaI1Evozy3DQ24H4ZykwJ4M23OCw7+AN3GkgJlKj X3HgHRUXJNSHydXvkZPxL5Rk/dbj5UkS2SR1u5BoK3BihdQnuWjisLuF0huHqkwvYa xA0EgL7IBLsMYGNLrYFKNf5gCut4lJkbVDsGix2zB0T5ApVhLWPF+KkX13gD8YSxnI FnwWWk+ksMQzPHFfbaA9srxZ4v6y7djre27o4fC9IV7fQAQYOB0XDTTOnBzsq8jW9y 4trrDBZJeX6qg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D3AD868F56; Thu, 1 Jan 2026 17:51:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Thu, 1 Jan 2026 17:50:34 -0700 Message-ID: <20260102005112.552256-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260102005112.552256-1-sjg@u-boot.org> References: <20260102005112.552256-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CNU2H5GJG76YSKVTD6OXK5HC26L4IOXW X-Message-ID-Hash: CNU2H5GJG76YSKVTD6OXK5HC26L4IOXW X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 04/30] video: Avoid uclass allocation in video_idle() cyclic List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass When the test framework reinits driver model, it orphans existing uclasses without calling their destroy callbacks. The video_idle() callback remains registered and when it runs, it calls uclass_get() which creates new uclasses if they don't exist. A surprising time when it runs is when any environment variable is read. Use uclass_find() instead, which returns NULL if the uclass doesn't exist, allowing video_idle to gracefully exit without allocating memory. This avoids memory-leak detection failures in tests like dm_test_host() Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/video-uclass.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index f50452cc956..383be0d96b8 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -669,10 +669,14 @@ static void video_idle(struct cyclic_info *cyc) { struct video_uc_priv *uc_priv; struct uclass *uc; - int ret; - ret = uclass_get(UCLASS_VIDEO, &uc); - if (ret) + /* + * Use uclass_find() rather than uclass_get() since the latter may + * create a new uclass if the test framework has reinitialised driver + * model while this cyclic function is still registered. + */ + uc = uclass_find(UCLASS_VIDEO); + if (!uc) return; uc_priv = uclass_get_priv(uc); @@ -683,13 +687,15 @@ static void video_idle(struct cyclic_info *cyc) if (CONFIG_IS_ENABLED(CURSOR)) { struct udevice *cons; - struct uclass *uc; /* Handle cursor display for each video console */ - uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, cons, uc) { - if (device_active(cons)) { - vidconsole_idle(cons); - video_sync(cons->parent, true); + uc = uclass_find(UCLASS_VIDEO_CONSOLE); + if (uc) { + list_for_each_entry(cons, &uc->dev_head, uclass_node) { + if (device_active(cons)) { + vidconsole_idle(cons); + video_sync(cons->parent, true); + } } } } else {