lkml.org 
[lkml]   [2017]   [Oct]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 14/18] ipmi: use ARRAY_SIZE
Date
Using the ARRAY_SIZE macro improves the readability of the code. In this
case, it's useless to define the macro NUM_PO_FUNCS so let's use
ARRAY_SIZE instead.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
(sizeof(E)@p /sizeof(*E))
|
(sizeof(E)@p /sizeof(E[...]))
|
(sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
drivers/char/ipmi/ipmi_poweroff.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index cd0f41fd4a51..7b36d7550840 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -40,6 +40,7 @@
#include <linux/kdev_t.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
+#include <linux/kernel.h>

#define PFX "IPMI poweroff: "

@@ -539,8 +540,6 @@ static struct poweroff_function poweroff_functions[] = {
.detect = ipmi_chassis_detect,
.poweroff_func = ipmi_poweroff_chassis },
};
-#define NUM_PO_FUNCS (sizeof(poweroff_functions) \
- / sizeof(struct poweroff_function))


/* Called on a powerdown request. */
@@ -616,7 +615,7 @@ static void ipmi_po_new_smi(int if_num, struct device *device)


/* Scan for a poweroff method */
- for (i = 0; i < NUM_PO_FUNCS; i++) {
+ for (i = 0; i < ARRAY_SIZE(poweroff_functions); i++) {
if (poweroff_functions[i].detect(ipmi_user))
goto found;
}
--
2.14.1
\
 
 \ /
  Last update: 2017-10-01 21:33    [W:0.211 / U:0.212 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site