[ARM] 5141/1: PWM: pwm_request() should return an PTR_ERR() instead of NULL.
authorBen Dooks <ben-linux@fluff.org>
Tue, 1 Jul 2008 13:18:27 +0000 (14:18 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 3 Jul 2008 12:25:07 +0000 (13:25 +0100)
Make the return of pwm_request() be more informative than just
being NULL on error by using PTR_ERR() to respond with an
approriate error.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mach-pxa/pwm.c
drivers/video/backlight/pwm_bl.c

index 7c86dd1d108f14a7ea64034e86fc31ba8268d8ad..ce28cd9fed163d4933252693e92d81c1a21c110b 100644 (file)
@@ -119,17 +119,23 @@ struct pwm_device *pwm_request(int pwm_id, const char *label)
        mutex_lock(&pwm_lock);
 
        list_for_each_entry(pwm, &pwm_list, node) {
-               if (pwm->pwm_id == pwm_id && pwm->use_count == 0) {
-                       pwm->use_count++;
-                       pwm->label = label;
+               if (pwm->pwm_id == pwm_id) {
                        found = 1;
                        break;
                }
        }
 
-       mutex_unlock(&pwm_lock);
+       if (found) {
+               if (pwm->use_count == 0) {
+                       pwm->use_count++;
+                       pwm->label = label;
+               } else
+                       pwm = ERR_PTR(-EBUSY);
+       } else
+               pwm = ERR_PTR(-ENOENT);
 
-       return (found) ? pwm : NULL;
+       mutex_unlock(&pwm_lock);
+       return pwm;
 }
 EXPORT_SYMBOL(pwm_request);
 
index 8346dfc01cf695266a39872c7999f7ec7bd387c7..6338d0e2fe0794f100e4d55c37dcb847dcf646c6 100644 (file)
@@ -87,9 +87,9 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        pb->notify = data->notify;
 
        pb->pwm = pwm_request(data->pwm_id, "backlight");
-       if (pb->pwm == NULL) {
+       if (IS_ERR(pb->pwm)) {
                dev_err(&pdev->dev, "unable to request PWM for backlight\n");
-               ret = -EBUSY;
+               ret = PTR_ERR(pb->pwm);
                goto err_pwm;
        }