Skip to contentSkip to conversation

cleanups for acpi/battery.c

PATCH In review Dmitry Rozhkov 2 participants 6 messages Jan 12, 2018 ACPI

lore
Share & tools
lore
#0 lore raw

This patch series does few cleanups in the file acpi/battery.c:
ACPI / battery: drop inclusion of init.h
ACPI / battery: reorder headers alphabetically
ACPI / battery: use specialized print macros
ACPI / battery: get rid of negations in conditions

  drivers/acpi/battery.c | 31 +++++++++++++++----------------
  1 file changed, 15 insertions(+), 16 deletions(-)
#1 lore raw

PATCH 1/4 ACPI / battery: drop inclusion of init.h

The driver can be built as a module thus inclusion of init.h is redundant in battery.c since it's always included by module.h.

---
 drivers/acpi/battery.c | 1 -
 1 file changed, 1 deletion(-)
drivers/acpi/battery.c +0 -1
index 19bc440820e6..bfe022f0509d 100644
@@ -23,7 +23,6 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/init.h>
 #include <linux/types.h>
 #include <linux/jiffies.h>
 #include <linux/async.h>
Signature · 1 line
2.13.6
#2 lore raw

PATCH 2/4 ACPI / battery: reorder headers alphabetically

In reply to Dmitry Rozhkov

Headers ordered alphabetically as easier to maintain. Also move the asm/unaligned.h header below more generic linux/* headers.

---
 drivers/acpi/battery.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/acpi/battery.c +7 -6
index bfe022f0509d..e2c3ec690af1 100644
@@ -21,16 +21,15 @@
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
 
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/jiffies.h>
 #include <linux/async.h>
-#include <linux/dmi.h>
 #include <linux/delay.h>
+#include <linux/dmi.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/suspend.h>
-#include <asm/unaligned.h>
+#include <linux/types.h>
 
 #ifdef CONFIG_ACPI_PROCFS_POWER
 #include <linux/proc_fs.h>
@@ -41,6 +40,8 @@
 #include <linux/acpi.h>
 #include <linux/power_supply.h>
 
+#include <asm/unaligned.h>
+
 #include "battery.h"
 
 #define PREFIX "ACPI: "
Signature · 1 line
2.13.6
#3 lore raw

PATCH 3/4 ACPI / battery: use specialized print macros

In reply to Dmitry Rozhkov

The kernel provides specialized macros for printing info and warning messages which make the code shorter.

Use the specialized macros instead of bare printk()'s.

Also format one user visible string literal into a searchable one line string.

---
 drivers/acpi/battery.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/battery.c +3 -5
index e2c3ec690af1..36c525bc38ba 100644
@@ -554,8 +554,7 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
 		battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
 		(s16)(battery->rate_now) < 0) {
 		battery->rate_now = abs((s16)battery->rate_now);
-		printk_once(KERN_WARNING FW_BUG
-			    "battery: (dis)charge rate invalid.\n");
+		pr_warn_once(FW_BUG "battery: (dis)charge rate invalid.\n");
 	}
 
 	if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)
@@ -1056,8 +1055,7 @@ static int acpi_battery_add_fs(struct acpi_device *device)
 	struct proc_dir_entry *entry = NULL;
 	int i;
 
-	printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded,"
-			" please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
+	pr_warning(PREFIX "Deprecated procfs I/F for battery is loaded, please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
 	if (!acpi_device_dir(device)) {
 		acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
 						     acpi_battery_dir);
@@ -1269,7 +1267,7 @@ static int acpi_battery_add(struct acpi_device *device)
 	}
 #endif
 
-	printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
+	pr_info(PREFIX "%s Slot [%s] (battery %s)\n",
 		ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
 		device->status.battery_present ? "present" : "absent");
 
Signature · 1 line
2.13.6
#4 lore raw

Re: [PATCH 3/4] ACPI / battery: use specialized print macros

Quoted 2 lines · Dmitry Rozhkov
(quoted diff) +1 -0
+	pr_warning(PREFIX "Deprecated procfs I/F for battery is

loaded, please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");

A nit: it can be pr_warn().

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#5 lore raw

PATCH 4/4 ACPI / battery: get rid of negations in conditions

In reply to Dmitry Rozhkov

Simple conditions without negations inflict less cognitive load on readers.

Rework conditional branches not to use negations. Also add braces around single statement branches where their counterpart else-branches consist of more than one statement as suggested in the paragraph 3 of the coding style.

---
 drivers/acpi/battery.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/acpi/battery.c +5 -4
index 36c525bc38ba..38b5eed72685 100644
@@ -848,7 +848,7 @@ static int acpi_battery_print_info(struct seq_file *seq, int result)
 			   acpi_battery_units(battery));
 
 	seq_printf(seq, "battery technology:      %srechargeable\n",
-		   (!battery->technology)?"non-":"");
+		   battery->technology ? "" : "non-");
 
 	if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
 		seq_printf(seq, "design voltage:          unknown\n");
@@ -1135,7 +1135,9 @@ static int battery_notify(struct notifier_block *nb,
 		if (!acpi_battery_present(battery))
 			return 0;
 
-		if (!battery->bat) {
+		if (battery->bat) {
+			acpi_battery_refresh(battery);
+		} else {
 			result = acpi_battery_get_info(battery);
 			if (result)
 				return result;
@@ -1143,8 +1145,7 @@ static int battery_notify(struct notifier_block *nb,
 			result = sysfs_add_battery(battery);
 			if (result)
 				return result;
-		} else
-			acpi_battery_refresh(battery);
+		}
 
 		acpi_battery_init_alarm(battery);
 		acpi_battery_get_state(battery);
Signature · 1 line
2.13.6