Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90968e8e authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Richard Purdie
Browse files

backlight: Remove excessive (un)likelys



Remove excessive numbers of (un)likely()s in the backlight core.

There are no hot paths in this code so rely on compiler to do
the right thing.

Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarRichard Purdie <rpurdie@rpsys.net>
parent dfcba200
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -37,7 +37,7 @@ static int fb_notifier_callback(struct notifier_block *self,
		if (!bd->props->check_fb ||
		if (!bd->props->check_fb ||
		    bd->props->check_fb(evdata->info)) {
		    bd->props->check_fb(evdata->info)) {
			bd->props->fb_blank = *(int *)evdata->data;
			bd->props->fb_blank = *(int *)evdata->data;
			if (likely(bd->props && bd->props->update_status))
			if (bd->props && bd->props->update_status)
				bd->props->update_status(bd);
				bd->props->update_status(bd);
		}
		}
	up(&bd->sem);
	up(&bd->sem);
@@ -73,7 +73,7 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
	struct backlight_device *bd = to_backlight_device(cdev);
	struct backlight_device *bd = to_backlight_device(cdev);


	down(&bd->sem);
	down(&bd->sem);
	if (likely(bd->props))
	if (bd->props)
		rc = sprintf(buf, "%d\n", bd->props->power);
		rc = sprintf(buf, "%d\n", bd->props->power);
	up(&bd->sem);
	up(&bd->sem);


@@ -94,10 +94,10 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
		return -EINVAL;
		return -EINVAL;


	down(&bd->sem);
	down(&bd->sem);
	if (likely(bd->props)) {
	if (bd->props) {
		pr_debug("backlight: set power to %d\n", power);
		pr_debug("backlight: set power to %d\n", power);
		bd->props->power = power;
		bd->props->power = power;
		if (likely(bd->props->update_status))
		if (bd->props->update_status)
			bd->props->update_status(bd);
			bd->props->update_status(bd);
		rc = count;
		rc = count;
	}
	}
@@ -112,7 +112,7 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
	struct backlight_device *bd = to_backlight_device(cdev);
	struct backlight_device *bd = to_backlight_device(cdev);


	down(&bd->sem);
	down(&bd->sem);
	if (likely(bd->props))
	if (bd->props)
		rc = sprintf(buf, "%d\n", bd->props->brightness);
		rc = sprintf(buf, "%d\n", bd->props->brightness);
	up(&bd->sem);
	up(&bd->sem);


@@ -133,14 +133,14 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
		return -EINVAL;
		return -EINVAL;


	down(&bd->sem);
	down(&bd->sem);
	if (likely(bd->props)) {
	if (bd->props) {
		if (brightness > bd->props->max_brightness)
		if (brightness > bd->props->max_brightness)
			rc = -EINVAL;
			rc = -EINVAL;
		else {
		else {
			pr_debug("backlight: set brightness to %d\n",
			pr_debug("backlight: set brightness to %d\n",
				 brightness);
				 brightness);
			bd->props->brightness = brightness;
			bd->props->brightness = brightness;
			if (likely(bd->props->update_status))
			if (bd->props->update_status)
				bd->props->update_status(bd);
				bd->props->update_status(bd);
			rc = count;
			rc = count;
		}
		}
@@ -156,7 +156,7 @@ static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *bu
	struct backlight_device *bd = to_backlight_device(cdev);
	struct backlight_device *bd = to_backlight_device(cdev);


	down(&bd->sem);
	down(&bd->sem);
	if (likely(bd->props))
	if (bd->props)
		rc = sprintf(buf, "%d\n", bd->props->max_brightness);
		rc = sprintf(buf, "%d\n", bd->props->max_brightness);
	up(&bd->sem);
	up(&bd->sem);


@@ -170,7 +170,7 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
	struct backlight_device *bd = to_backlight_device(cdev);
	struct backlight_device *bd = to_backlight_device(cdev);


	down(&bd->sem);
	down(&bd->sem);
	if (likely(bd->props && bd->props->get_brightness))
	if (bd->props && bd->props->get_brightness)
		rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd));
		rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd));
	up(&bd->sem);
	up(&bd->sem);


@@ -227,7 +227,7 @@ struct backlight_device *backlight_device_register(const char *name,
	pr_debug("backlight_device_alloc: name=%s\n", name);
	pr_debug("backlight_device_alloc: name=%s\n", name);


	new_bd = kmalloc(sizeof(struct backlight_device), GFP_KERNEL);
	new_bd = kmalloc(sizeof(struct backlight_device), GFP_KERNEL);
	if (unlikely(!new_bd))
	if (!new_bd)
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);


	init_MUTEX(&new_bd->sem);
	init_MUTEX(&new_bd->sem);
@@ -239,7 +239,7 @@ struct backlight_device *backlight_device_register(const char *name,
	class_set_devdata(&new_bd->class_dev, devdata);
	class_set_devdata(&new_bd->class_dev, devdata);


	rc = class_device_register(&new_bd->class_dev);
	rc = class_device_register(&new_bd->class_dev);
	if (unlikely(rc)) {
	if (rc) {
		kfree(new_bd);
		kfree(new_bd);
		return ERR_PTR(rc);
		return ERR_PTR(rc);
	}
	}
@@ -254,7 +254,7 @@ struct backlight_device *backlight_device_register(const char *name,
	for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) {
	for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) {
		rc = class_device_create_file(&new_bd->class_dev,
		rc = class_device_create_file(&new_bd->class_dev,
					      &bl_class_device_attributes[i]);
					      &bl_class_device_attributes[i]);
		if (unlikely(rc)) {
		if (rc) {
			while (--i >= 0)
			while (--i >= 0)
				class_device_remove_file(&new_bd->class_dev,
				class_device_remove_file(&new_bd->class_dev,
							 &bl_class_device_attributes[i]);
							 &bl_class_device_attributes[i]);
+8 −8
Original line number Original line Diff line number Diff line
@@ -67,7 +67,7 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
	struct lcd_device *ld = to_lcd_device(cdev);
	struct lcd_device *ld = to_lcd_device(cdev);


	down(&ld->sem);
	down(&ld->sem);
	if (likely(ld->props && ld->props->get_power))
	if (ld->props && ld->props->get_power)
		rc = sprintf(buf, "%d\n", ld->props->get_power(ld));
		rc = sprintf(buf, "%d\n", ld->props->get_power(ld));
	else
	else
		rc = -ENXIO;
		rc = -ENXIO;
@@ -90,7 +90,7 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
		return -EINVAL;
		return -EINVAL;


	down(&ld->sem);
	down(&ld->sem);
	if (likely(ld->props && ld->props->set_power)) {
	if (ld->props && ld->props->set_power) {
		pr_debug("lcd: set power to %d\n", power);
		pr_debug("lcd: set power to %d\n", power);
		ld->props->set_power(ld, power);
		ld->props->set_power(ld, power);
		rc = count;
		rc = count;
@@ -106,7 +106,7 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
	struct lcd_device *ld = to_lcd_device(cdev);
	struct lcd_device *ld = to_lcd_device(cdev);


	down(&ld->sem);
	down(&ld->sem);
	if (likely(ld->props && ld->props->get_contrast))
	if (ld->props && ld->props->get_contrast)
		rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld));
		rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld));
	up(&ld->sem);
	up(&ld->sem);


@@ -127,7 +127,7 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
		return -EINVAL;
		return -EINVAL;


	down(&ld->sem);
	down(&ld->sem);
	if (likely(ld->props && ld->props->set_contrast)) {
	if (ld->props && ld->props->set_contrast) {
		pr_debug("lcd: set contrast to %d\n", contrast);
		pr_debug("lcd: set contrast to %d\n", contrast);
		ld->props->set_contrast(ld, contrast);
		ld->props->set_contrast(ld, contrast);
		rc = count;
		rc = count;
@@ -143,7 +143,7 @@ static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf)
	struct lcd_device *ld = to_lcd_device(cdev);
	struct lcd_device *ld = to_lcd_device(cdev);


	down(&ld->sem);
	down(&ld->sem);
	if (likely(ld->props))
	if (ld->props)
		rc = sprintf(buf, "%d\n", ld->props->max_contrast);
		rc = sprintf(buf, "%d\n", ld->props->max_contrast);
	up(&ld->sem);
	up(&ld->sem);


@@ -194,7 +194,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
	pr_debug("lcd_device_register: name=%s\n", name);
	pr_debug("lcd_device_register: name=%s\n", name);


	new_ld = kmalloc(sizeof(struct lcd_device), GFP_KERNEL);
	new_ld = kmalloc(sizeof(struct lcd_device), GFP_KERNEL);
	if (unlikely(!new_ld))
	if (!new_ld)
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);


	init_MUTEX(&new_ld->sem);
	init_MUTEX(&new_ld->sem);
@@ -205,7 +205,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
	class_set_devdata(&new_ld->class_dev, devdata);
	class_set_devdata(&new_ld->class_dev, devdata);


	rc = class_device_register(&new_ld->class_dev);
	rc = class_device_register(&new_ld->class_dev);
	if (unlikely(rc)) {
	if (rc) {
		kfree(new_ld);
		kfree(new_ld);
		return ERR_PTR(rc);
		return ERR_PTR(rc);
	}
	}
@@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
	for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) {
	for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) {
		rc = class_device_create_file(&new_ld->class_dev,
		rc = class_device_create_file(&new_ld->class_dev,
					      &lcd_class_device_attributes[i]);
					      &lcd_class_device_attributes[i]);
		if (unlikely(rc)) {
		if (rc) {
			while (--i >= 0)
			while (--i >= 0)
				class_device_remove_file(&new_ld->class_dev,
				class_device_remove_file(&new_ld->class_dev,
							 &lcd_class_device_attributes[i]);
							 &lcd_class_device_attributes[i]);