hwmon: (lm95241) Use HWMON_CHANNEL_INFO macro
authorGuenter Roeck <linux@roeck-us.net>
Sun, 31 Mar 2019 17:53:48 +0000 (10:53 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 16 Apr 2019 00:19:53 +0000 (17:19 -0700)
The HWMON_CHANNEL_INFO macro simplifies the code, reduces the likelihood
of errors, and makes the code easier to read.

The conversion was done automatically with coccinelle. The semantic patch
used to make this change is as follows.

@r@
initializer list elements;
identifier i;
@@

-u32 i[] = {
-  elements,
-  0
-};

@s@
identifier r.i,j,ty;
@@

-struct hwmon_channel_info j = {
-       .type = ty,
-       .config = i,
-};

@script:ocaml t@
ty << s.ty;
elements << r.elements;
shorter;
elems;
@@

shorter :=
   make_ident (List.hd(List.rev (Str.split (Str.regexp "_") ty)));
elems :=
   make_ident
    (String.concat ","
     (List.map (fun x -> Printf.sprintf "\n\t\t\t   %s" x)
       (Str.split (Str.regexp " , ") elements)))

@@
identifier s.j,t.shorter;
identifier t.elems;
@@

- &j
+ HWMON_CHANNEL_INFO(shorter,elems)

This patch does not introduce functional changes. Many thanks to
Julia Lawall for providing the semantic patch.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lm95241.c

index 3ff1889..6c5215e 100644 (file)
@@ -418,33 +418,15 @@ static void lm95241_init_client(struct i2c_client *client,
                                  data->model);
 }
 
-static const u32 lm95241_chip_config[] = {
-       HWMON_C_UPDATE_INTERVAL,
-       0
-};
-
-static const struct hwmon_channel_info lm95241_chip = {
-       .type = hwmon_chip,
-       .config = lm95241_chip_config,
-};
-
-static const u32 lm95241_temp_config[] = {
-       HWMON_T_INPUT,
-       HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MIN | HWMON_T_TYPE |
-               HWMON_T_FAULT,
-       HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MIN | HWMON_T_TYPE |
-               HWMON_T_FAULT,
-       0
-};
-
-static const struct hwmon_channel_info lm95241_temp = {
-       .type = hwmon_temp,
-       .config = lm95241_temp_config,
-};
-
 static const struct hwmon_channel_info *lm95241_info[] = {
-       &lm95241_chip,
-       &lm95241_temp,
+       HWMON_CHANNEL_INFO(chip,
+                          HWMON_C_UPDATE_INTERVAL),
+       HWMON_CHANNEL_INFO(temp,
+                          HWMON_T_INPUT,
+                          HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MIN |
+                          HWMON_T_TYPE | HWMON_T_FAULT,
+                          HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MIN |
+                          HWMON_T_TYPE | HWMON_T_FAULT),
        NULL
 };