mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor@insightbb.com>
To: Richard Purdie <rpurdie@rpsys.net>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [patch 3/6] Get rid of excessive amount of likely()s
Date: Fri, 11 Aug 2006 01:03:13 -0400	[thread overview]
Message-ID: <20060811050611.278227073.dtor@insightbb.com> (raw)
In-Reply-To: <20060811050310.958962036.dtor@insightbb.com>

[-- Attachment #1: backlight-cleanup.patch --]
[-- Type: text/plain, Size: 8966 bytes --]

Backlight: get rid of excessive amount of likely()s

There are no hot paths in the backlight core; do not litter the
code with likely()s and rely on compiler to do the right thing.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/video/backlight/backlight.c |   45 +++++++++++++++++-------------------
 drivers/video/backlight/lcd.c       |   37 ++++++++++++-----------------
 2 files changed, 38 insertions(+), 44 deletions(-)

Index: work/drivers/video/backlight/backlight.c
===================================================================
--- work.orig/drivers/video/backlight/backlight.c
+++ work/drivers/video/backlight/backlight.c
@@ -20,7 +20,7 @@ static ssize_t backlight_show_power(stru
 	struct backlight_device *bd = to_backlight_device(cdev);
 
 	down(&bd->sem);
-	if (likely(bd->props))
+	if (bd->props)
 		rc = sprintf(buf, "%d\n", bd->props->power);
 	up(&bd->sem);
 
@@ -41,10 +41,10 @@ static ssize_t backlight_store_power(str
 		return -EINVAL;
 
 	down(&bd->sem);
-	if (likely(bd->props)) {
+	if (bd->props) {
 		pr_debug("backlight: set power to %d\n", power);
 		bd->props->power = power;
-		if (likely(bd->props->update_status))
+		if (bd->props->update_status)
 			bd->props->update_status(bd);
 		rc = count;
 	}
@@ -59,7 +59,7 @@ static ssize_t backlight_show_brightness
 	struct backlight_device *bd = to_backlight_device(cdev);
 
 	down(&bd->sem);
-	if (likely(bd->props))
+	if (bd->props)
 		rc = sprintf(buf, "%d\n", bd->props->brightness);
 	up(&bd->sem);
 
@@ -80,14 +80,14 @@ static ssize_t backlight_store_brightnes
 		return -EINVAL;
 
 	down(&bd->sem);
-	if (likely(bd->props)) {
+	if (bd->props) {
 		if (brightness > bd->props->max_brightness)
 			rc = -EINVAL;
 		else {
 			pr_debug("backlight: set brightness to %d\n",
 				 brightness);
 			bd->props->brightness = brightness;
-			if (likely(bd->props->update_status))
+			if (bd->props->update_status)
 				bd->props->update_status(bd);
 			rc = count;
 		}
@@ -103,7 +103,7 @@ static ssize_t backlight_show_max_bright
 	struct backlight_device *bd = to_backlight_device(cdev);
 
 	down(&bd->sem);
-	if (likely(bd->props))
+	if (bd->props)
 		rc = sprintf(buf, "%d\n", bd->props->max_brightness);
 	up(&bd->sem);
 
@@ -117,7 +117,7 @@ static ssize_t backlight_show_actual_bri
 	struct backlight_device *bd = to_backlight_device(cdev);
 
 	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));
 	up(&bd->sem);
 
@@ -127,6 +127,7 @@ static ssize_t backlight_show_actual_bri
 static void backlight_class_release(struct class_device *dev)
 {
 	struct backlight_device *bd = to_backlight_device(dev);
+
 	kfree(bd);
 }
 
@@ -153,7 +154,7 @@ static int fb_notifier_callback(struct n
 				unsigned long event, void *data)
 {
 	struct backlight_device *bd;
-	struct fb_event *evdata =(struct fb_event *)data;
+	struct fb_event *evdata = data;
 
 	/* If we aren't interested in this event, skip it immediately ... */
 	if (event != FB_EVENT_BLANK)
@@ -161,13 +162,14 @@ static int fb_notifier_callback(struct n
 
 	bd = container_of(self, struct backlight_device, fb_notif);
 	down(&bd->sem);
-	if (bd->props)
+	if (bd->props) {
 		if (!bd->props->check_fb ||
 		    bd->props->check_fb(evdata->info)) {
 			bd->props->fb_blank = *(int *)evdata->data;
 			if (likely(bd->props && bd->props->update_status))
 				bd->props->update_status(bd);
 		}
+	}
 	up(&bd->sem);
 	return 0;
 }
@@ -187,35 +189,33 @@ static int fb_notifier_callback(struct n
 struct backlight_device *backlight_device_register(const char *name, void *devdata,
 						   struct backlight_properties *bp)
 {
-	int rc;
+	int err;
 	struct backlight_device *new_bd;
 
 	pr_debug("backlight_device_alloc: name=%s\n", name);
 
-	new_bd = kmalloc(sizeof(struct backlight_device), GFP_KERNEL);
-	if (unlikely(!new_bd))
+	new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL);
+	if (!new_bd)
 		return ERR_PTR(-ENOMEM);
 
 	init_MUTEX(&new_bd->sem);
 	new_bd->props = bp;
-	memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
 	new_bd->class_dev.class = &backlight_class;
 	strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
 	class_set_devdata(&new_bd->class_dev, devdata);
 
-	rc = class_device_register(&new_bd->class_dev);
-	if (unlikely(rc)) {
+	err = class_device_register(&new_bd->class_dev);
+	if (err) {
 		kfree(new_bd);
-		return ERR_PTR(rc);
+		return ERR_PTR(err);
 	}
 
-	memset(&new_bd->fb_notif, 0, sizeof(new_bd->fb_notif));
 	new_bd->fb_notif.notifier_call = fb_notifier_callback;
 
-	rc = fb_register_client(&new_bd->fb_notif);
-	if (unlikely(rc)) {
+	err = fb_register_client(&new_bd->fb_notif);
+	if (err) {
 		class_device_unregister(&new_bd->class_dev);
-		return ERR_PTR(rc);
+		return ERR_PTR(err);
 	}
 
 	return new_bd;
@@ -236,7 +236,7 @@ void backlight_device_unregister(struct 
 	pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id);
 
 	down(&bd->sem);
-	if (likely(bd->props && bd->props->update_status)) {
+	if (bd->props && bd->props->update_status) {
 		bd->props->brightness = 0;
 		bd->props->power = 0;
 		bd->props->update_status(bd);
@@ -246,7 +246,6 @@ void backlight_device_unregister(struct 
 	up(&bd->sem);
 
 	fb_unregister_client(&bd->fb_notif);
-
 	class_device_unregister(&bd->class_dev);
 }
 EXPORT_SYMBOL(backlight_device_unregister);
Index: work/drivers/video/backlight/lcd.c
===================================================================
--- work.orig/drivers/video/backlight/lcd.c
+++ work/drivers/video/backlight/lcd.c
@@ -16,14 +16,12 @@
 
 static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
 {
-	int rc;
+	int rc = -ENXIO;
 	struct lcd_device *ld = to_lcd_device(cdev);
 
 	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));
-	else
-		rc = -ENXIO;
 	up(&ld->sem);
 
 	return rc;
@@ -43,7 +41,7 @@ static ssize_t lcd_store_power(struct cl
 		return -EINVAL;
 
 	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);
 		ld->props->set_power(ld, power);
 		rc = count;
@@ -59,7 +57,7 @@ static ssize_t lcd_show_contrast(struct 
 	struct lcd_device *ld = to_lcd_device(cdev);
 
 	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));
 	up(&ld->sem);
 
@@ -80,7 +78,7 @@ static ssize_t lcd_store_contrast(struct
 		return -EINVAL;
 
 	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);
 		ld->props->set_contrast(ld, contrast);
 		rc = count;
@@ -96,7 +94,7 @@ static ssize_t lcd_show_max_contrast(str
 	struct lcd_device *ld = to_lcd_device(cdev);
 
 	down(&ld->sem);
-	if (likely(ld->props))
+	if (ld->props)
 		rc = sprintf(buf, "%d\n", ld->props->max_contrast);
 	up(&ld->sem);
 
@@ -130,7 +128,7 @@ static int fb_notifier_callback(struct n
 				 unsigned long event, void *data)
 {
 	struct lcd_device *ld;
-	struct fb_event *evdata =(struct fb_event *)data;
+	struct fb_event *evdata = data;
 
 	/* If we aren't interested in this event, skip it immediately ... */
 	if (event != FB_EVENT_BLANK)
@@ -159,35 +157,33 @@ static int fb_notifier_callback(struct n
 struct lcd_device *lcd_device_register(const char *name, void *devdata,
 				       struct lcd_properties *lp)
 {
-	int rc;
+	int err;
 	struct lcd_device *new_ld;
 
 	pr_debug("lcd_device_register: name=%s\n", name);
 
-	new_ld = kmalloc(sizeof(struct lcd_device), GFP_KERNEL);
-	if (unlikely(!new_ld))
+	new_ld = kzalloc(sizeof(struct lcd_device), GFP_KERNEL);
+	if (!new_ld)
 		return ERR_PTR(-ENOMEM);
 
 	init_MUTEX(&new_ld->sem);
 	new_ld->props = lp;
-	memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev));
 	new_ld->class_dev.class = &lcd_class;
 	strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN);
 	class_set_devdata(&new_ld->class_dev, devdata);
 
-	rc = class_device_register(&new_ld->class_dev);
-	if (unlikely(rc)) {
+	err = class_device_register(&new_ld->class_dev);
+	if (unlikely(err)) {
 		kfree(new_ld);
-		return ERR_PTR(rc);
+		return ERR_PTR(err);
 	}
 
-	memset(&new_ld->fb_notif, 0, sizeof(new_ld->fb_notif));
 	new_ld->fb_notif.notifier_call = fb_notifier_callback;
 
-	rc = fb_register_client(&new_ld->fb_notif);
-	if (unlikely(rc)) {
+	err = fb_register_client(&new_ld->fb_notif);
+	if (err) {
 		class_device_unregister(&new_ld->class_dev);
-		return ERR_PTR(rc);
+		return ERR_PTR(err);
 	}
 
 	return new_ld;
@@ -212,7 +208,6 @@ void lcd_device_unregister(struct lcd_de
 	up(&ld->sem);
 
 	fb_unregister_client(&ld->fb_notif);
-
 	class_device_unregister(&ld->class_dev);
 }
 EXPORT_SYMBOL(lcd_device_unregister);

  parent reply	other threads:[~2006-08-11  5:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-11  5:03 [patch 0/6] Backlight & lcd fixes/cleanups Dmitry Torokhov
2006-08-11  5:03 ` [patch 1/6] Convert to use default class device attributes Dmitry Torokhov
2006-08-11  5:03 ` [patch 2/6] Fix error handling when registering new device Dmitry Torokhov
2006-08-11  5:03 ` Dmitry Torokhov [this message]
2006-08-11  5:03 ` [patch 4/6] Remove "owner" from backlight_properties structure Dmitry Torokhov
2006-08-11  5:03 ` [patch 5/6] Convert to use mutexes instead of semaphores Dmitry Torokhov
2006-08-11 12:58   ` Dmitry Torokhov
2006-08-11 13:16     ` Richard Purdie
2006-08-11 13:34       ` Dmitry Torokhov
2006-08-11 13:42         ` Michael Hanselmann
2006-08-11 14:07           ` Dmitry Torokhov
2006-08-11 16:45             ` Richard Purdie
2006-08-11 17:20               ` Dmitry Torokhov
2006-08-29 20:54               ` Michael Hanselmann
2006-08-11  5:03 ` [patch 6/6] Move per-device data out of backlight_properties Dmitry Torokhov
2006-08-11  8:02   ` Richard Purdie
2006-08-11 12:27     ` Dmitry Torokhov
2006-08-11 12:55       ` Richard Purdie
2006-08-11 13:10         ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060811050611.278227073.dtor@insightbb.com \
    --to=dtor@insightbb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®