Skip to contentSkip to conversation

backlight: Simplify probe in few drivers

PATCH Applied Krzysztof Kozlowski 3 participants 10 messages Mar 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover backlight: Simplify probe in few drivers

Hi,

Simplify old code in few backlight drivers.

Changes in v2
=============
1. Patch #1: Drop "Error :" msg.
2. Add Rb tags.
Link to v1: https://lore.kernel.org/r/[email protected]

Best regards,
Krzysztof

---
Krzysztof Kozlowski (7):
backlight: gpio: Simplify with dev_err_probe()
backlight: l4f00242t03: Simplify with dev_err_probe()
backlight: bd6107: Handle deferred probe
backlight: as3711_bl: Handle deferred probe
backlight: lm3630a_bl: Handle deferred probe
backlight: lm3630a_bl: Simplify probe return on gpio request error
backlight: pandora_bl: Drop unneeded ENOMEM error message

 drivers/video/backlight/as3711_bl.c      |  6 ++----
 drivers/video/backlight/bd6107.c         |  9 +++------
 drivers/video/backlight/gpio_backlight.c | 10 +++-------
 drivers/video/backlight/l4f00242t03.c    | 34 +++++++++++++-------------------
 drivers/video/backlight/lm3630a_bl.c     | 13 +++++-------
 drivers/video/backlight/pandora_bl.c     |  4 +---
 6 files changed, 28 insertions(+), 48 deletions(-)

---
base-commit: 1870cdc0e8dee32e3c221704a2977898ba4c10e8
change-id: 20240304-backlight-probe-31dee1efe662

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>
#1 lore raw

PATCH v2 1/7 backlight: gpio: Simplify with dev_err_probe()

Common pattern of handling deferred probe can be simplified with dev_err_probe(). Less code and also it prints the error value.

---
 drivers/video/backlight/gpio_backlight.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/video/backlight/gpio_backlight.c +3 -7
index d28c30b2a35d..e0c8c2a3f5dc 100644
@@ -64,13 +64,9 @@ static int gpio_backlight_probe(struct platform_device *pdev)
 	def_value = device_property_read_bool(dev, "default-on");
 
 	gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS);
-	if (IS_ERR(gbl->gpiod)) {
-		ret = PTR_ERR(gbl->gpiod);
-		if (ret != -EPROBE_DEFER)
-			dev_err(dev,
-				"Error: The gpios parameter is missing or invalid.\n");
-		return ret;
-	}
+	if (IS_ERR(gbl->gpiod))
+		return dev_err_probe(dev, PTR_ERR(gbl->gpiod),
+				     "The gpios parameter is missing or invalid\n");
 
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 2/7 backlight: l4f00242t03: Simplify with dev_err_probe()

In reply to Krzysztof Kozlowski

Common pattern of handling deferred probe can be simplified with dev_err_probe(). Less code and also it prints the error value.

---
 drivers/video/backlight/l4f00242t03.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/video/backlight/l4f00242t03.c +14 -20
index cc763cf15f53..bd5137ee203b 100644
@@ -179,34 +179,28 @@ static int l4f00242t03_probe(struct spi_device *spi)
 	priv->spi = spi;
 
 	priv->reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH);
-	if (IS_ERR(priv->reset)) {
-		dev_err(&spi->dev,
-			"Unable to get the lcd l4f00242t03 reset gpio.\n");
-		return PTR_ERR(priv->reset);
-	}
+	if (IS_ERR(priv->reset))
+		return dev_err_probe(&spi->dev, PTR_ERR(priv->reset),
+				     "Unable to get the lcd l4f00242t03 reset gpio.\n");
 	gpiod_set_consumer_name(priv->reset, "lcd l4f00242t03 reset");
 
 	priv->enable = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW);
-	if (IS_ERR(priv->enable)) {
-		dev_err(&spi->dev,
-			"Unable to get the lcd l4f00242t03 data en gpio.\n");
-		return PTR_ERR(priv->enable);
-	}
+	if (IS_ERR(priv->enable))
+		return dev_err_probe(&spi->dev, PTR_ERR(priv->enable),
+				     "Unable to get the lcd l4f00242t03 data en gpio.\n");
 	gpiod_set_consumer_name(priv->enable, "lcd l4f00242t03 data enable");
 
 	priv->io_reg = devm_regulator_get(&spi->dev, "vdd");
-	if (IS_ERR(priv->io_reg)) {
-		dev_err(&spi->dev, "%s: Unable to get the IO regulator\n",
-		       __func__);
-		return PTR_ERR(priv->io_reg);
-	}
+	if (IS_ERR(priv->io_reg))
+		return dev_err_probe(&spi->dev, PTR_ERR(priv->io_reg),
+				     "%s: Unable to get the IO regulator\n",
+				     __func__);
 
 	priv->core_reg = devm_regulator_get(&spi->dev, "vcore");
-	if (IS_ERR(priv->core_reg)) {
-		dev_err(&spi->dev, "%s: Unable to get the core regulator\n",
-		       __func__);
-		return PTR_ERR(priv->core_reg);
-	}
+	if (IS_ERR(priv->core_reg))
+		return dev_err_probe(&spi->dev, PTR_ERR(priv->core_reg),
+				     "%s: Unable to get the core regulator\n",
+				     __func__);
 
 	priv->ld = devm_lcd_device_register(&spi->dev, "l4f00242t03", &spi->dev,
 					priv, &l4f_ops);
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 3/7 backlight: bd6107: Handle deferred probe

In reply to Krzysztof Kozlowski

Don't pollute dmesg on deferred probe and simplify the code with dev_err_probe().

---
 drivers/video/backlight/bd6107.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/backlight/bd6107.c +3 -6
index c95a12bf0ce2..b1e7126380ef 100644
@@ -119,7 +119,6 @@ static int bd6107_probe(struct i2c_client *client)
 	struct backlight_device *backlight;
 	struct backlight_properties props;
 	struct bd6107 *bd;
-	int ret;
 
 	if (pdata == NULL) {
 		dev_err(&client->dev, "No platform data\n");
@@ -147,11 +146,9 @@ static int bd6107_probe(struct i2c_client *client)
 	 * the reset.
 	 */
 	bd->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH);
-	if (IS_ERR(bd->reset)) {
-		dev_err(&client->dev, "unable to request reset GPIO\n");
-		ret = PTR_ERR(bd->reset);
-		return ret;
-	}
+	if (IS_ERR(bd->reset))
+		return dev_err_probe(&client->dev, PTR_ERR(bd->reset),
+				     "unable to request reset GPIO\n");
 
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 4/7 backlight: as3711_bl: Handle deferred probe

In reply to Krzysztof Kozlowski

Don't pollute dmesg on deferred probe and simplify the code with dev_err_probe().

---
 drivers/video/backlight/as3711_bl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/video/backlight/as3711_bl.c +2 -4
index 28437c2da0f5..e6f66bb35ef5 100644
@@ -383,10 +383,8 @@ static int as3711_backlight_probe(struct platform_device *pdev)
 
 	if (pdev->dev.parent->of_node) {
 		ret = as3711_backlight_parse_dt(&pdev->dev);
-		if (ret < 0) {
-			dev_err(&pdev->dev, "DT parsing failed: %d\n", ret);
-			return ret;
-		}
+		if (ret < 0)
+			return dev_err_probe(&pdev->dev, ret, "DT parsing failed\n");
 	}
 
 	if (!pdata->su1_fb && !pdata->su2_fb) {
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 5/7 backlight: lm3630a_bl: Handle deferred probe

In reply to Krzysztof Kozlowski

Don't pollute dmesg on deferred probe and simplify the code with dev_err_probe().

---
 drivers/video/backlight/lm3630a_bl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/video/backlight/lm3630a_bl.c +3 -4
index a3412c936ca2..93fd6dbccc28 100644
@@ -563,10 +563,9 @@ static int lm3630a_probe(struct i2c_client *client)
 	/* pwm */
 	if (pdata->pwm_ctrl != LM3630A_PWM_DISABLE) {
 		pchip->pwmd = devm_pwm_get(pchip->dev, "lm3630a-pwm");
-		if (IS_ERR(pchip->pwmd)) {
-			dev_err(&client->dev, "fail : get pwm device\n");
-			return PTR_ERR(pchip->pwmd);
-		}
+		if (IS_ERR(pchip->pwmd))
+			return dev_err_probe(&client->dev, PTR_ERR(pchip->pwmd),
+					     "fail : get pwm device\n");
 
 		pwm_init_state(pchip->pwmd, &pchip->pwmd_state);
 	}
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 6/7 backlight: lm3630a_bl: Simplify probe return on gpio request error

In reply to Krzysztof Kozlowski

Code can be simpler: return directly when devm_gpiod_get_optional() failed.

---
 drivers/video/backlight/lm3630a_bl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/video/backlight/lm3630a_bl.c +2 -4
index 93fd6dbccc28..ac0a60e39e39 100644
@@ -543,10 +543,8 @@ static int lm3630a_probe(struct i2c_client *client)
 
 	pchip->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
 						GPIOD_OUT_HIGH);
-	if (IS_ERR(pchip->enable_gpio)) {
-		rval = PTR_ERR(pchip->enable_gpio);
-		return rval;
-	}
+	if (IS_ERR(pchip->enable_gpio))
+		return PTR_ERR(pchip->enable_gpio);
 
 	/* chip initialize */
 	rval = lm3630a_chip_init(pchip);
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 7/7 backlight: pandora_bl: Drop unneeded ENOMEM error message

In reply to Krzysztof Kozlowski

Core code already prints detailed information about failure of memory allocation.

---
 drivers/video/backlight/pandora_bl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/video/backlight/pandora_bl.c +1 -3
index f946470ce9f6..51faa889e01f 100644
@@ -114,10 +114,8 @@ static int pandora_backlight_probe(struct platform_device *pdev)
 	u8 r;
 
 	priv = devm_kmalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		dev_err(&pdev->dev, "failed to allocate driver private data\n");
+	if (!priv)
 		return -ENOMEM;
-	}
 
 	memset(&props, 0, sizeof(props));
 	props.max_brightness = MAX_USER_VALUE;
Signature · 1 line
2.34.1
maintainer Applied
#9 lore raw
In reply to Krzysztof Kozlowski
Quoted 9 lines · Krzysztof Kozlowski

Simplify old code in few backlight drivers.

Changes in v2
=============
1. Patch #1: Drop "Error :" msg.
2. Add Rb tags.
Link to v1: https://lore.kernel.org/r/[email protected]

[...]

Applied, thanks!

[1/7] backlight: gpio: Simplify with dev_err_probe()

      commit: 2f5929cd930b24a88d6fa73ab08ba857c59f7686
[2/7] backlight: l4f00242t03: Simplify with dev_err_probe()
      commit: d3de24fc13465a4b45047d193f729b73e062a881
[3/7] backlight: bd6107: Handle deferred probe
      commit: e00b57b4d4464071cb18d03cc8040e103c662d80
[4/7] backlight: as3711_bl: Handle deferred probe
      commit: fd9f81bc3f48d5064bfd894eeb0202f5825ea4b1
[5/7] backlight: lm3630a_bl: Handle deferred probe
      commit: c7fa2f12e74a437fc8c77b7780131b13acc2fa49
[6/7] backlight: lm3630a_bl: Simplify probe return on gpio request error
      commit: dedd6eb26bbb37139d0a0122e4b4ad94f06edaa1
[7/7] backlight: pandora_bl: Drop unneeded ENOMEM error message
      commit: 07dbc9e6e2433fe312423096efc037bf47298ed1

--
Lee Jones [李琼斯]