* cleanups for acpi/battery.c
@ 2018-01-12 13:58 Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 1/4] ACPI / battery: drop inclusion of init.h Dmitry Rozhkov
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Dmitry Rozhkov @ 2018-01-12 13:58 UTC (permalink / raw)
To: rjw, lenb, linux-acpi; +Cc: andriy.shevchenko
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(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] ACPI / battery: drop inclusion of init.h
2018-01-12 13:58 cleanups for acpi/battery.c Dmitry Rozhkov
@ 2018-01-12 13:58 ` Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 2/4] ACPI / battery: reorder headers alphabetically Dmitry Rozhkov
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Rozhkov @ 2018-01-12 13:58 UTC (permalink / raw)
To: rjw, lenb, linux-acpi; +Cc: andriy.shevchenko, Dmitry Rozhkov
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.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
---
drivers/acpi/battery.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 19bc440820e6..bfe022f0509d 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -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>
--
2.13.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] ACPI / battery: reorder headers alphabetically
2018-01-12 13:58 cleanups for acpi/battery.c Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 1/4] ACPI / battery: drop inclusion of init.h Dmitry Rozhkov
@ 2018-01-12 13:58 ` Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 3/4] ACPI / battery: use specialized print macros Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 4/4] ACPI / battery: get rid of negations in conditions Dmitry Rozhkov
3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Rozhkov @ 2018-01-12 13:58 UTC (permalink / raw)
To: rjw, lenb, linux-acpi; +Cc: andriy.shevchenko, Dmitry Rozhkov
Headers ordered alphabetically as easier to maintain.
Also move the asm/unaligned.h header below more generic linux/*
headers.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
---
drivers/acpi/battery.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index bfe022f0509d..e2c3ec690af1 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -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: "
--
2.13.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] ACPI / battery: use specialized print macros
2018-01-12 13:58 cleanups for acpi/battery.c Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 1/4] ACPI / battery: drop inclusion of init.h Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 2/4] ACPI / battery: reorder headers alphabetically Dmitry Rozhkov
@ 2018-01-12 13:58 ` Dmitry Rozhkov
2018-01-12 18:52 ` Andy Shevchenko
2018-01-12 13:58 ` [PATCH 4/4] ACPI / battery: get rid of negations in conditions Dmitry Rozhkov
3 siblings, 1 reply; 6+ messages in thread
From: Dmitry Rozhkov @ 2018-01-12 13:58 UTC (permalink / raw)
To: rjw, lenb, linux-acpi; +Cc: andriy.shevchenko, 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.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
---
drivers/acpi/battery.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index e2c3ec690af1..36c525bc38ba 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -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");
--
2.13.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] ACPI / battery: get rid of negations in conditions
2018-01-12 13:58 cleanups for acpi/battery.c Dmitry Rozhkov
` (2 preceding siblings ...)
2018-01-12 13:58 ` [PATCH 3/4] ACPI / battery: use specialized print macros Dmitry Rozhkov
@ 2018-01-12 13:58 ` Dmitry Rozhkov
3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Rozhkov @ 2018-01-12 13:58 UTC (permalink / raw)
To: rjw, lenb, linux-acpi; +Cc: andriy.shevchenko, 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.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
---
drivers/acpi/battery.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 36c525bc38ba..38b5eed72685 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -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);
--
2.13.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] ACPI / battery: use specialized print macros
2018-01-12 13:58 ` [PATCH 3/4] ACPI / battery: use specialized print macros Dmitry Rozhkov
@ 2018-01-12 18:52 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2018-01-12 18:52 UTC (permalink / raw)
To: Dmitry Rozhkov, rjw, lenb, linux-acpi
On Fri, 2018-01-12 at 15:58 +0200, Dmitry Rozhkov wrote:
> + 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().
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-01-12 18:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-12 13:58 cleanups for acpi/battery.c Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 1/4] ACPI / battery: drop inclusion of init.h Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 2/4] ACPI / battery: reorder headers alphabetically Dmitry Rozhkov
2018-01-12 13:58 ` [PATCH 3/4] ACPI / battery: use specialized print macros Dmitry Rozhkov
2018-01-12 18:52 ` Andy Shevchenko
2018-01-12 13:58 ` [PATCH 4/4] ACPI / battery: get rid of negations in conditions Dmitry Rozhkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).