From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A162CA0EDC for ; Wed, 20 Aug 2025 11:13:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B99E910E6F0; Wed, 20 Aug 2025 11:13:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="TlfxQRPi"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9503610E6FA for ; Wed, 20 Aug 2025 11:13:07 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 88DC443292; Wed, 20 Aug 2025 11:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1755688385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ou3MSRgBG8cP602wOscwCCqhc/Oa+T0DZwTTZNBffYE=; b=TlfxQRPi7CCIbzE9v7GFaL7B4qSx0xwJC2B3ssCV6ueN+1gXFc6zORcuq9Sk8Xxcnk83Gy lGxCe6BMFQhgEyOf5BTdumULIco7b7+Pz4BVy+XwmjivQ7+Y7X8RJqeMCiQEN+F8sijIHO dRmhlReSijd+b9G3cg1p3hZA16sNytLVZ2F1rkMkkwE2VKFOMzm504vS3gniWL35/b9Qkx w2G85zGZ3MKYj/VJTCHAAqqbeyb/AYzKQulY1pjhiRifd9lNjVKZStPlTVVy56oOlvfS8R uS09Gk3wVnnTMrvjmKhtDPJG12kXpVXXLQvJAcQkGC7DVQOh2zM/D+pUPcRZgg== Date: Wed, 20 Aug 2025 13:13:02 +0200 From: Luca Ceresoli To: Maxime Ripard Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Hui Pu , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Baryshkov Subject: Re: [PATCH 2/2] drm/bridge: ti-sn65dsi83: protect device resources on unplug Message-ID: <20250820131302.6a2da5ef@booty> In-Reply-To: References: <20250808-drm-bridge-atomic-vs-remove-v1-0-a52e933b08a8@bootlin.com> <20250808-drm-bridge-atomic-vs-remove-v1-2-a52e933b08a8@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.3.1 (GTK 3.24.49; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduheekvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfgjfhhoofggtgfgsehtjeertdertddvnecuhfhrohhmpefnuhgtrgcuvegvrhgvshholhhiuceolhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepgeelffefgfehhfdtvdefueefieevkefggfelkeeiudetkeektedvhedukefgvddvnecuffhomhgrihhnpegsohhothhlihhnrdgtohhmnecukfhppedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgdphhgvlhhopegsohhothihpdhmrghilhhfrhhomheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepudeipdhrtghpthhtohepmhhrihhprghrugeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghnughriigvjhdrhhgrjhgurgesihhnthgvlhdrtghomhdprhgtphhtthhopehnvghilhdrrghrmhhsthhrohhngheslhhinhgrr hhordhorhhgpdhrtghpthhtoheprhhfohhssheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepnfgruhhrvghnthdrphhinhgthhgrrhhtsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhopehjohhnrghssehkfihisghoohdrshgvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrrghrthgvnhdrlhgrnhhkhhhorhhstheslhhinhhugidrihhnthgvlhdrtghomh X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hello Maxime, On Tue, 19 Aug 2025 14:29:32 +0200 Maxime Ripard wrote: > > @@ -1005,7 +1041,24 @@ static void sn65dsi83_remove(struct i2c_client *client) > > { > > struct sn65dsi83 *ctx = i2c_get_clientdata(client); > > > > + drm_bridge_unplug(&ctx->bridge); > > drm_bridge_remove(&ctx->bridge); > > Shouldn't we merge drm_bridge_unplug with the release part of > devm_drm_bridge_alloc? I'm not sure I got what you are suggesting here, sorry. Do you mean that __devm_drm_bridge_alloc() should add a devres action to call drm_bridge_unplug(), so the unplug is called implicitly and does not need to be called explicitly by all drivers? If that's what you mean, I don't think that would work. Unless I'm missing something, devres actions are always invoked just after the driver .remove callback. But we need to call drm_bridge_unplug() at the beginning (or just before) .remove, at least for drivers that need to do something in .remove that cannot be done by devm. In pseudocode: mybridge_remove() { drm_bridge_unplug(); <-- explicit call as in my patch xyz_disable(); drm_bridge_unplug(); <-- implicitly done by devres } We want xyz_disable() to be done after drm_bridge_unplug(), so other code paths using drm_bridge_enter/exit() won't mess with xyz. devres actions cannot be added to be executed _before_ .remove, AFAIK. > > + /* > > + * sn65dsi83_atomic_disable() should release some resources, but it > > + * cannot if we call drm_bridge_unplug() before it can > > + * drm_bridge_enter(). If that happens, let's release those > > + * resources now. > > + */ > > + if (ctx->disable_resources_needed) { > > + if (!ctx->irq) > > + sn65dsi83_monitor_stop(ctx); > > + > > + gpiod_set_value_cansleep(ctx->enable_gpio, 0); > > + usleep_range(10000, 11000); > > + > > + regulator_disable(ctx->vcc); > > + } > > I'm not sure you need this. Wouldn't registering a devm action do the > same thing? Good idea, thanks. I'll give it a try. Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com