From patchwork Tue Sep 17 08:53:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 830059 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (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 24E71165EEF; Tue, 17 Sep 2024 08:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726563215; cv=none; b=dHDhoGRS8Qbcw1Ykj9Ip3WYEE8mTc0xK0YyfcedWEeU8nPMokMyNKtp5keEu43yNYW2A8lMKrU970GLEVLPHp+gKLp95rOYDVLHmNSmvlKouHIa15SWEAUX7UB73qzaZGhXHY6Mlr3Jio35KA2SqweMNPskp67PVS4OY815o65I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726563215; c=relaxed/simple; bh=z+d3irWh7mStagZJOo4SmN0ZvOkr+sZJxcsZgV6KR3E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oamGMGj9KYmCGrulipiK+QYjKf3jZBACHpMq/yXmO/UKMEigy/TMQacAk31xEnr6E9FfTeCmUyOr7a2xk0GMnWYn9eJZs/auNHpIEENTrDlsOuqLgAI7VchixdNLB/3oQp6nlbxxeWnkbjYs3cpxPhyGbzSXdKNFkIySqbHmca8= 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=Cb8FfdzX; arc=none smtp.client-ip=217.70.183.193 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="Cb8FfdzX" Received: by mail.gandi.net (Postfix) with ESMTPSA id 17F8124000F; Tue, 17 Sep 2024 08:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726563211; 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=NbWGpJQEJyMacI+BAl0HLXVEczFckWr8+kUC/shDjy8=; b=Cb8FfdzXhk4g/9rQXsYItNmhlK4goP3zY1+tFtY78i0f8wuTgUyL/2LfWvtmw27SVW6D3P xfCyqEyCt4Qw44LRO2OXqZymPuitdlOVGiCleFKdImwG6DHaFaDDeRSXPMHPJPxOAeOwYV VSvmSh1LxxmRFlgEVjCRtxJfkx3pQ6bi3SJ4kFNHfetqmQcAHdSegwavtEZ0x7w/ULL8Co z4AKVzIgsaoTmqQJ+2z1k6apFc2LNb+iRxwYjV2GQKjY8SdGgrboDaDQVIOIeo3dL6+zbj 1SHNzhIRYYKunkA8kL1T2MHKHzxbQooxn6gdGqSXtCZN2yPLYM8I6eW8qoZW3Q== From: Luca Ceresoli Date: Tue, 17 Sep 2024 10:53:10 +0200 Subject: [PATCH v4 6/8] backlight: led-backlight: add devlink to supplier LEDs Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240917-hotplug-drm-bridge-v4-6-bc4dfee61be6@bootlin.com> References: <20240917-hotplug-drm-bridge-v4-0-bc4dfee61be6@bootlin.com> In-Reply-To: <20240917-hotplug-drm-bridge-v4-0-bc4dfee61be6@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" , Lee Jones , Daniel Thompson , Jingoo Han , Helge Deller Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, linux-fbdev@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.1 X-GND-Sasl: luca.ceresoli@bootlin.com led-backlight is a consumer of one or multiple LED class devices, but no devlink is created for such supplier-producer relationship. One consequence is that removal ordered is not correctly enforced. Issues happen for example with the following sections in a device tree overlay: // An LED driver chip pca9632@62 { compatible = "nxp,pca9632"; reg = <0x62>; // ... addon_led_pwm: led-pwm@3 { reg = <3>; label = "addon:led:pwm"; }; }; backlight-addon { compatible = "led-backlight"; leds = <&addon_led_pwm>; brightness-levels = <255>; default-brightness-level = <255>; }; On removal of the above overlay, the LED driver can be removed before the backlight device, resulting in: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 ... Call trace: led_put+0xe0/0x140 devm_led_release+0x6c/0x98 Fix by adding a devlink between the consuming led-backlight device and the supplying LED device. Signed-off-by: Luca Ceresoli --- This patch first appeared in v4. --- drivers/video/backlight/led_bl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/video/backlight/led_bl.c b/drivers/video/backlight/led_bl.c index c7aefcd6e4e3..bfbd80728036 100644 --- a/drivers/video/backlight/led_bl.c +++ b/drivers/video/backlight/led_bl.c @@ -209,6 +209,19 @@ static int led_bl_probe(struct platform_device *pdev) return PTR_ERR(priv->bl_dev); } + for (i = 0; i < priv->nb_leds; i++) { + struct device_link *link; + + link = device_link_add(&pdev->dev, priv->leds[0]->dev->parent, + DL_FLAG_AUTOREMOVE_CONSUMER); + if (!link) { + dev_err(&pdev->dev, "Failed to add devlink (consumer %s, supplier %s)\n", + dev_name(&pdev->dev), dev_name(priv->leds[0]->dev->parent)); + backlight_device_unregister(priv->bl_dev); + return -EINVAL; + } + } + for (i = 0; i < priv->nb_leds; i++) { mutex_lock(&priv->leds[i]->led_access); led_sysfs_disable(priv->leds[i]);