[PATCH 3/4] video/backlight-pwm: code readability improvement.

iw3gtf at arcor.de iw3gtf at arcor.de
Thu Jul 14 07:17:17 PDT 2016


We use the local variable 'length' instead of the lengthy
'pwm_backlight->backlight.brightness_max' within pwm_backlight_parse_dt().
---
 drivers/video/backlight-pwm.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index 53cf4e9..5ff40a9 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -133,12 +133,11 @@ static int pwm_backlight_parse_dt(struct device_d *dev,
 	if (!prop)
 		return -EINVAL;
 
-	pwm_backlight->backlight.brightness_max = length / sizeof(u32);
+	length /= sizeof(u32);
 
 	/* read brightness levels from DT property */
-	if (pwm_backlight->backlight.brightness_max > 0) {
-		size_t size = sizeof(*pwm_backlight->levels) *
-			pwm_backlight->backlight.brightness_max;
+	if (length > 0) {
+		size_t size = sizeof(*pwm_backlight->levels) * length;
 
 		pwm_backlight->levels = xzalloc(size);
 		if (!pwm_backlight->levels)
@@ -146,11 +145,11 @@ static int pwm_backlight_parse_dt(struct device_d *dev,
 
 		ret = of_property_read_u32_array(node, "brightness-levels",
 						 pwm_backlight->levels,
-						 pwm_backlight->backlight.brightness_max);
+						 length);
 		if (ret < 0)
 			return ret;
 
-		for (i = 0; i < pwm_backlight->backlight.brightness_max; i++)
+		for (i = 0; i < length; i++)
 			if (pwm_backlight->levels[i] > pwm_backlight->scale)
 				pwm_backlight->scale = pwm_backlight->levels[i];
 
-- 
2.9.1




More information about the barebox mailing list