Merge tag 'platform-drivers-x86-v3.19-1' of git://git.infradead.org/users/dvhart...
[linux-2.6-block.git] / drivers / platform / x86 / eeepc-laptop.c
index bd533c22be570a736795b2a35a83a7439a1d76d5..844c2096bde9244c3daaf504892f2bbcefad3db0 100644 (file)
@@ -263,13 +263,11 @@ static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm,
 /*
  * Sys helpers
  */
-static int parse_arg(const char *buf, unsigned long count, int *val)
+static int parse_arg(const char *buf, int *val)
 {
-       if (!count)
-               return 0;
        if (sscanf(buf, "%i", val) != 1)
                return -EINVAL;
-       return count;
+       return 0;
 }
 
 static ssize_t store_sys_acpi(struct device *dev, int cm,
@@ -278,12 +276,13 @@ static ssize_t store_sys_acpi(struct device *dev, int cm,
        struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
        int rv, value;
 
-       rv = parse_arg(buf, count, &value);
-       if (rv > 0)
-               value = set_acpi(eeepc, cm, value);
-       if (value < 0)
+       rv = parse_arg(buf, &value);
+       if (rv < 0)
+               return rv;
+       rv = set_acpi(eeepc, cm, value);
+       if (rv < 0)
                return -EIO;
-       return rv;
+       return count;
 }
 
 static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
@@ -296,30 +295,34 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
        return sprintf(buf, "%d\n", value);
 }
 
-#define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm)                    \
-       static ssize_t show_##_name(struct device *dev,                 \
+#define EEEPC_ACPI_SHOW_FUNC(_name, _cm)                               \
+       static ssize_t _name##_show(struct device *dev,                 \
                                    struct device_attribute *attr,      \
                                    char *buf)                          \
        {                                                               \
                return show_sys_acpi(dev, _cm, buf);                    \
-       }                                                               \
-       static ssize_t store_##_name(struct device *dev,                \
+       }
+
+#define EEEPC_ACPI_STORE_FUNC(_name, _cm)                              \
+       static ssize_t _name##_store(struct device *dev,                \
                                     struct device_attribute *attr,     \
                                     const char *buf, size_t count)     \
        {                                                               \
                return store_sys_acpi(dev, _cm, buf, count);            \
-       }                                                               \
-       static struct device_attribute dev_attr_##_name = {             \
-               .attr = {                                               \
-                       .name = __stringify(_name),                     \
-                       .mode = _mode },                                \
-               .show   = show_##_name,                                 \
-               .store  = store_##_name,                                \
        }
 
-EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA);
-EEEPC_CREATE_DEVICE_ATTR(cardr, 0644, CM_ASL_CARDREADER);
-EEEPC_CREATE_DEVICE_ATTR(disp, 0200, CM_ASL_DISPLAYSWITCH);
+#define EEEPC_CREATE_DEVICE_ATTR_RW(_name, _cm)                                \
+       EEEPC_ACPI_SHOW_FUNC(_name, _cm)                                \
+       EEEPC_ACPI_STORE_FUNC(_name, _cm)                               \
+       static DEVICE_ATTR_RW(_name)
+
+#define EEEPC_CREATE_DEVICE_ATTR_WO(_name, _cm)                                \
+       EEEPC_ACPI_STORE_FUNC(_name, _cm)                               \
+       static DEVICE_ATTR_WO(_name)
+
+EEEPC_CREATE_DEVICE_ATTR_RW(camera, CM_ASL_CAMERA);
+EEEPC_CREATE_DEVICE_ATTR_RW(cardr, CM_ASL_CARDREADER);
+EEEPC_CREATE_DEVICE_ATTR_WO(disp, CM_ASL_DISPLAYSWITCH);
 
 struct eeepc_cpufv {
        int num;
@@ -329,14 +332,17 @@ struct eeepc_cpufv {
 static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c)
 {
        c->cur = get_acpi(eeepc, CM_ASL_CPUFV);
+       if (c->cur < 0)
+               return -ENODEV;
+
        c->num = (c->cur >> 8) & 0xff;
        c->cur &= 0xff;
-       if (c->cur < 0 || c->num <= 0 || c->num > 12)
+       if (c->num == 0 || c->num > 12)
                return -ENODEV;
        return 0;
 }
 
-static ssize_t show_available_cpufv(struct device *dev,
+static ssize_t available_cpufv_show(struct device *dev,
                                    struct device_attribute *attr,
                                    char *buf)
 {
@@ -353,7 +359,7 @@ static ssize_t show_available_cpufv(struct device *dev,
        return len;
 }
 
-static ssize_t show_cpufv(struct device *dev,
+static ssize_t cpufv_show(struct device *dev,
                          struct device_attribute *attr,
                          char *buf)
 {
@@ -365,7 +371,7 @@ static ssize_t show_cpufv(struct device *dev,
        return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
 }
 
-static ssize_t store_cpufv(struct device *dev,
+static ssize_t cpufv_store(struct device *dev,
                           struct device_attribute *attr,
                           const char *buf, size_t count)
 {
@@ -377,16 +383,18 @@ static ssize_t store_cpufv(struct device *dev,
                return -EPERM;
        if (get_cpufv(eeepc, &c))
                return -ENODEV;
-       rv = parse_arg(buf, count, &value);
+       rv = parse_arg(buf, &value);
        if (rv < 0)
                return rv;
-       if (!rv || value < 0 || value >= c.num)
+       if (value < 0 || value >= c.num)
                return -EINVAL;
-       set_acpi(eeepc, CM_ASL_CPUFV, value);
-       return rv;
+       rv = set_acpi(eeepc, CM_ASL_CPUFV, value);
+       if (rv)
+               return rv;
+       return count;
 }
 
-static ssize_t show_cpufv_disabled(struct device *dev,
+static ssize_t cpufv_disabled_show(struct device *dev,
                          struct device_attribute *attr,
                          char *buf)
 {
@@ -395,24 +403,23 @@ static ssize_t show_cpufv_disabled(struct device *dev,
        return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
 }
 
-static ssize_t store_cpufv_disabled(struct device *dev,
+static ssize_t cpufv_disabled_store(struct device *dev,
                           struct device_attribute *attr,
                           const char *buf, size_t count)
 {
        struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
        int rv, value;
 
-       rv = parse_arg(buf, count, &value);
+       rv = parse_arg(buf, &value);
        if (rv < 0)
                return rv;
 
        switch (value) {
        case 0:
                if (eeepc->cpufv_disabled)
-                       pr_warn("cpufv enabled (not officially supported "
-                               "on this model)\n");
+                       pr_warn("cpufv enabled (not officially supported on this model)\n");
                eeepc->cpufv_disabled = false;
-               return rv;
+               return count;
        case 1:
                return -EPERM;
        default:
@@ -421,29 +428,9 @@ static ssize_t store_cpufv_disabled(struct device *dev,
 }
 
 
-static struct device_attribute dev_attr_cpufv = {
-       .attr = {
-               .name = "cpufv",
-               .mode = 0644 },
-       .show   = show_cpufv,
-       .store  = store_cpufv
-};
-
-static struct device_attribute dev_attr_available_cpufv = {
-       .attr = {
-               .name = "available_cpufv",
-               .mode = 0444 },
-       .show   = show_available_cpufv
-};
-
-static struct device_attribute dev_attr_cpufv_disabled = {
-       .attr = {
-               .name = "cpufv_disabled",
-               .mode = 0644 },
-       .show   = show_cpufv_disabled,
-       .store  = store_cpufv_disabled
-};
-
+static DEVICE_ATTR_RW(cpufv);
+static DEVICE_ATTR_RO(available_cpufv);
+static DEVICE_ATTR_RW(cpufv_disabled);
 
 static struct attribute *platform_attributes[] = {
        &dev_attr_camera.attr,
@@ -545,7 +532,7 @@ static int eeepc_led_init(struct eeepc_laptop *eeepc)
        eeepc->tpd_led.name = "eeepc::touchpad";
        eeepc->tpd_led.brightness_set = tpd_led_set;
        if (get_acpi(eeepc, CM_ASL_TPD) >= 0) /* if method is available */
-         eeepc->tpd_led.brightness_get = tpd_led_get;
+               eeepc->tpd_led.brightness_get = tpd_led_get;
        eeepc->tpd_led.max_brightness = 1;
 
        rv = led_classdev_register(&eeepc->platform_device->dev,
@@ -592,59 +579,58 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
        mutex_lock(&eeepc->hotplug_lock);
        pci_lock_rescan_remove();
 
-       if (eeepc->hotplug_slot) {
-               port = acpi_get_pci_dev(handle);
-               if (!port) {
-                       pr_warning("Unable to find port\n");
-                       goto out_unlock;
-               }
+       if (!eeepc->hotplug_slot)
+               goto out_unlock;
 
-               bus = port->subordinate;
+       port = acpi_get_pci_dev(handle);
+       if (!port) {
+               pr_warning("Unable to find port\n");
+               goto out_unlock;
+       }
 
-               if (!bus) {
-                       pr_warn("Unable to find PCI bus 1?\n");
-                       goto out_put_dev;
-               }
+       bus = port->subordinate;
 
-               if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
-                       pr_err("Unable to read PCI config space?\n");
-                       goto out_put_dev;
-               }
+       if (!bus) {
+               pr_warn("Unable to find PCI bus 1?\n");
+               goto out_put_dev;
+       }
 
-               absent = (l == 0xffffffff);
+       if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
+               pr_err("Unable to read PCI config space?\n");
+               goto out_put_dev;
+       }
+
+       absent = (l == 0xffffffff);
 
-               if (blocked != absent) {
-                       pr_warn("BIOS says wireless lan is %s, "
-                               "but the pci device is %s\n",
-                               blocked ? "blocked" : "unblocked",
-                               absent ? "absent" : "present");
-                       pr_warn("skipped wireless hotplug as probably "
-                               "inappropriate for this model\n");
+       if (blocked != absent) {
+               pr_warn("BIOS says wireless lan is %s, but the pci device is %s\n",
+                       blocked ? "blocked" : "unblocked",
+                       absent ? "absent" : "present");
+               pr_warn("skipped wireless hotplug as probably inappropriate for this model\n");
+               goto out_put_dev;
+       }
+
+       if (!blocked) {
+               dev = pci_get_slot(bus, 0);
+               if (dev) {
+                       /* Device already present */
+                       pci_dev_put(dev);
                        goto out_put_dev;
                }
-
-               if (!blocked) {
-                       dev = pci_get_slot(bus, 0);
-                       if (dev) {
-                               /* Device already present */
-                               pci_dev_put(dev);
-                               goto out_put_dev;
-                       }
-                       dev = pci_scan_single_device(bus, 0);
-                       if (dev) {
-                               pci_bus_assign_resources(bus);
-                               pci_bus_add_device(dev);
-                       }
-               } else {
-                       dev = pci_get_slot(bus, 0);
-                       if (dev) {
-                               pci_stop_and_remove_bus_device(dev);
-                               pci_dev_put(dev);
-                       }
+               dev = pci_scan_single_device(bus, 0);
+               if (dev) {
+                       pci_bus_assign_resources(bus);
+                       pci_bus_add_device(dev);
+               }
+       } else {
+               dev = pci_get_slot(bus, 0);
+               if (dev) {
+                       pci_stop_and_remove_bus_device(dev);
+                       pci_dev_put(dev);
                }
-out_put_dev:
-               pci_dev_put(port);
        }
+out_put_dev:
+       pci_dev_put(port);
 
 out_unlock:
        pci_unlock_rescan_remove();
@@ -680,22 +666,21 @@ static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc,
 
        status = acpi_get_handle(NULL, node, &handle);
 
-       if (ACPI_SUCCESS(status)) {
-               status = acpi_install_notify_handler(handle,
-                                                    ACPI_SYSTEM_NOTIFY,
-                                                    eeepc_rfkill_notify,
-                                                    eeepc);
-               if (ACPI_FAILURE(status))
-                       pr_warn("Failed to register notify on %s\n", node);
-
-               /*
-                * Refresh pci hotplug in case the rfkill state was
-                * changed during setup.
-                */
-               eeepc_rfkill_hotplug(eeepc, handle);
-       } else
+       if (ACPI_FAILURE(status))
                return -ENODEV;
 
+       status = acpi_install_notify_handler(handle,
+                                            ACPI_SYSTEM_NOTIFY,
+                                            eeepc_rfkill_notify,
+                                            eeepc);
+       if (ACPI_FAILURE(status))
+               pr_warn("Failed to register notify on %s\n", node);
+
+       /*
+        * Refresh pci hotplug in case the rfkill state was
+        * changed during setup.
+        */
+       eeepc_rfkill_hotplug(eeepc, handle);
        return 0;
 }
 
@@ -707,20 +692,21 @@ static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc,
 
        status = acpi_get_handle(NULL, node, &handle);
 
-       if (ACPI_SUCCESS(status)) {
-               status = acpi_remove_notify_handler(handle,
-                                                    ACPI_SYSTEM_NOTIFY,
-                                                    eeepc_rfkill_notify);
-               if (ACPI_FAILURE(status))
-                       pr_err("Error removing rfkill notify handler %s\n",
-                               node);
-                       /*
-                        * Refresh pci hotplug in case the rfkill
-                        * state was changed after
-                        * eeepc_unregister_rfkill_notifier()
-                        */
-               eeepc_rfkill_hotplug(eeepc, handle);
-       }
+       if (ACPI_FAILURE(status))
+               return;
+
+       status = acpi_remove_notify_handler(handle,
+                                            ACPI_SYSTEM_NOTIFY,
+                                            eeepc_rfkill_notify);
+       if (ACPI_FAILURE(status))
+               pr_err("Error removing rfkill notify handler %s\n",
+                       node);
+               /*
+                * Refresh pci hotplug in case the rfkill
+                * state was changed after
+                * eeepc_unregister_rfkill_notifier()
+                */
+       eeepc_rfkill_hotplug(eeepc, handle);
 }
 
 static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
@@ -833,11 +819,15 @@ static int eeepc_new_rfkill(struct eeepc_laptop *eeepc,
        return 0;
 }
 
+static char EEEPC_RFKILL_NODE_1[] = "\\_SB.PCI0.P0P5";
+static char EEEPC_RFKILL_NODE_2[] = "\\_SB.PCI0.P0P6";
+static char EEEPC_RFKILL_NODE_3[] = "\\_SB.PCI0.P0P7";
+
 static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc)
 {
-       eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
-       eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
-       eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
+       eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
+       eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
+       eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
        if (eeepc->wlan_rfkill) {
                rfkill_unregister(eeepc->wlan_rfkill);
                rfkill_destroy(eeepc->wlan_rfkill);
@@ -909,9 +899,9 @@ static int eeepc_rfkill_init(struct eeepc_laptop *eeepc)
        if (result == -EBUSY)
                result = 0;
 
-       eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
-       eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
-       eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
+       eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
+       eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
+       eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
 
 exit:
        if (result && result != -ENODEV)
@@ -927,7 +917,7 @@ static int eeepc_hotk_thaw(struct device *device)
        struct eeepc_laptop *eeepc = dev_get_drvdata(device);
 
        if (eeepc->wlan_rfkill) {
-               bool wlan;
+               int wlan;
 
                /*
                 * Work around bios bug - acpi _PTS turns off the wireless led
@@ -935,7 +925,8 @@ static int eeepc_hotk_thaw(struct device *device)
                 * we should kick it ourselves in case hibernation is aborted.
                 */
                wlan = get_acpi(eeepc, CM_ASL_WLAN);
-               set_acpi(eeepc, CM_ASL_WLAN, wlan);
+               if (wlan >= 0)
+                       set_acpi(eeepc, CM_ASL_WLAN, wlan);
        }
 
        return 0;
@@ -947,9 +938,9 @@ static int eeepc_hotk_restore(struct device *device)
 
        /* Refresh both wlan rfkill state and pci hotplug */
        if (eeepc->wlan_rfkill) {
-               eeepc_rfkill_hotplug_update(eeepc, "\\_SB.PCI0.P0P5");
-               eeepc_rfkill_hotplug_update(eeepc, "\\_SB.PCI0.P0P6");
-               eeepc_rfkill_hotplug_update(eeepc, "\\_SB.PCI0.P0P7");
+               eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_1);
+               eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_2);
+               eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_3);
        }
 
        if (eeepc->bluetooth_rfkill)
@@ -973,7 +964,6 @@ static const struct dev_pm_ops eeepc_pm_ops = {
 static struct platform_driver platform_driver = {
        .driver = {
                .name = EEEPC_LAPTOP_FILE,
-               .owner = THIS_MODULE,
                .pm = &eeepc_pm_ops,
        }
 };
@@ -990,18 +980,28 @@ static struct platform_driver platform_driver = {
 #define EEEPC_EC_SFB0      0xD0
 #define EEEPC_EC_FAN_CTRL  (EEEPC_EC_SFB0 + 3) /* Byte containing SF25  */
 
+static inline int eeepc_pwm_to_lmsensors(int value)
+{
+       return value * 255 / 100;
+}
+
+static inline int eeepc_lmsensors_to_pwm(int value)
+{
+       value = clamp_val(value, 0, 255);
+       return value * 100 / 255;
+}
+
 static int eeepc_get_fan_pwm(void)
 {
        u8 value = 0;
 
        ec_read(EEEPC_EC_FAN_PWM, &value);
-       return value * 255 / 100;
+       return eeepc_pwm_to_lmsensors(value);
 }
 
 static void eeepc_set_fan_pwm(int value)
 {
-       value = clamp_val(value, 0, 255);
-       value = value * 100 / 255;
+       value = eeepc_lmsensors_to_pwm(value);
        ec_write(EEEPC_EC_FAN_PWM, value);
 }
 
@@ -1015,15 +1015,19 @@ static int eeepc_get_fan_rpm(void)
        return high << 8 | low;
 }
 
+#define EEEPC_EC_FAN_CTRL_BIT  0x02
+#define EEEPC_FAN_CTRL_MANUAL  1
+#define EEEPC_FAN_CTRL_AUTO    2
+
 static int eeepc_get_fan_ctrl(void)
 {
        u8 value = 0;
 
        ec_read(EEEPC_EC_FAN_CTRL, &value);
-       if (value & 0x02)
-               return 1; /* manual */
+       if (value & EEEPC_EC_FAN_CTRL_BIT)
+               return EEEPC_FAN_CTRL_MANUAL;
        else
-               return 2; /* automatic */
+               return EEEPC_FAN_CTRL_AUTO;
 }
 
 static void eeepc_set_fan_ctrl(int manual)
@@ -1031,10 +1035,10 @@ static void eeepc_set_fan_ctrl(int manual)
        u8 value = 0;
 
        ec_read(EEEPC_EC_FAN_CTRL, &value);
-       if (manual == 1)
-               value |= 0x02;
+       if (manual == EEEPC_FAN_CTRL_MANUAL)
+               value |= EEEPC_EC_FAN_CTRL_BIT;
        else
-               value &= ~0x02;
+               value &= ~EEEPC_EC_FAN_CTRL_BIT;
        ec_write(EEEPC_EC_FAN_CTRL, value);
 }
 
@@ -1042,10 +1046,11 @@ static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
 {
        int rv, value;
 
-       rv = parse_arg(buf, count, &value);
-       if (rv > 0)
-               set(value);
-       return rv;
+       rv = parse_arg(buf, &value);
+       if (rv < 0)
+               return rv;
+       set(value);
+       return count;
 }
 
 static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
@@ -1053,26 +1058,36 @@ static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
        return sprintf(buf, "%d\n", get());
 }
 
-#define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _get, _set)             \
-       static ssize_t show_##_name(struct device *dev,                 \
+#define EEEPC_SENSOR_SHOW_FUNC(_name, _get)                            \
+       static ssize_t _name##_show(struct device *dev,                 \
                                    struct device_attribute *attr,      \
                                    char *buf)                          \
        {                                                               \
                return show_sys_hwmon(_get, buf);                       \
-       }                                                               \
-       static ssize_t store_##_name(struct device *dev,                \
+       }
+
+#define EEEPC_SENSOR_STORE_FUNC(_name, _set)                           \
+       static ssize_t _name##_store(struct device *dev,                \
                                     struct device_attribute *attr,     \
                                     const char *buf, size_t count)     \
        {                                                               \
                return store_sys_hwmon(_set, buf, count);               \
-       }                                                               \
-       static DEVICE_ATTR(_name, _mode, show_##_name, store_##_name)
+       }
+
+#define EEEPC_CREATE_SENSOR_ATTR_RW(_name, _get, _set)                 \
+       EEEPC_SENSOR_SHOW_FUNC(_name, _get)                             \
+       EEEPC_SENSOR_STORE_FUNC(_name, _set)                            \
+       static DEVICE_ATTR_RW(_name)
 
-EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
-EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
-                        eeepc_get_fan_pwm, eeepc_set_fan_pwm);
-EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
-                        eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
+#define EEEPC_CREATE_SENSOR_ATTR_RO(_name, _get)                       \
+       EEEPC_SENSOR_SHOW_FUNC(_name, _get)                             \
+       static DEVICE_ATTR_RO(_name)
+
+EEEPC_CREATE_SENSOR_ATTR_RO(fan1_input, eeepc_get_fan_rpm);
+EEEPC_CREATE_SENSOR_ATTR_RW(pwm1, eeepc_get_fan_pwm,
+                           eeepc_set_fan_pwm);
+EEEPC_CREATE_SENSOR_ATTR_RW(pwm1_enable, eeepc_get_fan_ctrl,
+                           eeepc_set_fan_ctrl);
 
 static struct attribute *hwmon_attrs[] = {
        &dev_attr_pwm1.attr,
@@ -1158,8 +1173,7 @@ static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
 
 static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
 {
-       if (eeepc->backlight_device)
-               backlight_device_unregister(eeepc->backlight_device);
+       backlight_device_unregister(eeepc->backlight_device);
        eeepc->backlight_device = NULL;
 }
 
@@ -1218,7 +1232,7 @@ static void eeepc_input_exit(struct eeepc_laptop *eeepc)
 static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
 {
        if (!eeepc->inputdev)
-               return ;
+               return;
        if (!sparse_keymap_report_event(eeepc->inputdev, event, 1, true))
                pr_info("Unknown key %x pressed\n", event);
 }
@@ -1226,6 +1240,7 @@ static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
 static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
 {
        struct eeepc_laptop *eeepc = acpi_driver_data(device);
+       int old_brightness, new_brightness;
        u16 count;
 
        if (event > ACPI_MAX_SYS_NOTIFY)
@@ -1236,34 +1251,32 @@ static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
                                        count);
 
        /* Brightness events are special */
-       if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX) {
-
-               /* Ignore them completely if the acpi video driver is used */
-               if (eeepc->backlight_device != NULL) {
-                       int old_brightness, new_brightness;
-
-                       /* Update the backlight device. */
-                       old_brightness = eeepc_backlight_notify(eeepc);
-
-                       /* Convert event to keypress (obsolescent hack) */
-                       new_brightness = event - NOTIFY_BRN_MIN;
-
-                       if (new_brightness < old_brightness) {
-                               event = NOTIFY_BRN_MIN; /* brightness down */
-                       } else if (new_brightness > old_brightness) {
-                               event = NOTIFY_BRN_MAX; /* brightness up */
-                       } else {
-                               /*
-                               * no change in brightness - already at min/max,
-                               * event will be desired value (or else ignored)
-                               */
-                       }
-                       eeepc_input_notify(eeepc, event);
-               }
-       } else {
-               /* Everything else is a bona-fide keypress event */
+       if (event < NOTIFY_BRN_MIN || event > NOTIFY_BRN_MAX) {
                eeepc_input_notify(eeepc, event);
+               return;
        }
+
+       /* Ignore them completely if the acpi video driver is used */
+       if (!eeepc->backlight_device)
+               return;
+
+       /* Update the backlight device. */
+       old_brightness = eeepc_backlight_notify(eeepc);
+
+       /* Convert event to keypress (obsolescent hack) */
+       new_brightness = event - NOTIFY_BRN_MIN;
+
+       if (new_brightness < old_brightness) {
+               event = NOTIFY_BRN_MIN; /* brightness down */
+       } else if (new_brightness > old_brightness) {
+               event = NOTIFY_BRN_MAX; /* brightness up */
+       } else {
+               /*
+                * no change in brightness - already at min/max,
+                * event will be desired value (or else ignored)
+                */
+       }
+       eeepc_input_notify(eeepc, event);
 }
 
 static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
@@ -1295,8 +1308,8 @@ static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
         */
        if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) {
                eeepc->cpufv_disabled = true;
-               pr_info("model %s does not officially support setting cpu "
-                       "speed\n", model);
+               pr_info("model %s does not officially support setting cpu speed\n",
+                       model);
                pr_info("cpufv disabled to avoid instability\n");
        }
 
@@ -1322,8 +1335,8 @@ static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name)
           Check if cm_getv[cm] works and, if yes, assume cm should be set. */
        if (!(eeepc->cm_supported & (1 << cm))
            && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) {
-               pr_info("%s (%x) not reported by BIOS,"
-                       " enabling anyway\n", name, 1 << cm);
+               pr_info("%s (%x) not reported by BIOS, enabling anyway\n",
+                       name, 1 << cm);
                eeepc->cm_supported |= 1 << cm;
        }
 }
@@ -1424,8 +1437,9 @@ static int eeepc_acpi_add(struct acpi_device *device)
                result = eeepc_backlight_init(eeepc);
                if (result)
                        goto fail_backlight;
-       } else
+       } else {
                pr_info("Backlight controlled by ACPI video driver\n");
+       }
 
        result = eeepc_input_init(eeepc);
        if (result)