gpioset: use gpiod_line_config_set_output_values()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 12 Jan 2023 18:13:12 +0000 (19:13 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 25 Jan 2023 08:42:02 +0000 (09:42 +0100)
Use the new line config function to shrink the gpioset code and drop one
for loop.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tools/gpioset.c

index a871a1695bbdc4ab11eb04525845f0f4a5238e0d..1429d65abb4d8e9f73063044267a076651127452 100644 (file)
@@ -870,9 +870,9 @@ int main(int argc, char **argv)
        struct gpiod_line_config *line_cfg;
        struct line_resolver *resolver;
        enum gpiod_line_value *values;
-       int i, j, num_lines, ret;
        struct gpiod_chip *chip;
        unsigned int *offsets;
+       int i, num_lines, ret;
        struct config cfg;
        char **lines;
 
@@ -933,15 +933,16 @@ int main(int argc, char **argv)
                                                        values);
 
                gpiod_line_config_reset(line_cfg);
-               for (j = 0; j < num_lines; j++) {
-                       gpiod_line_settings_set_output_value(settings,
-                                                            values[j]);
-
-                       ret = gpiod_line_config_add_line_settings(
-                               line_cfg, &offsets[j], 1, settings);
-                       if (ret)
-                               die_perror("unable to add line settings");
-               }
+
+               ret = gpiod_line_config_add_line_settings(line_cfg, offsets,
+                                                         num_lines, settings);
+               if (ret)
+                       die_perror("unable to add line settings");
+
+               ret = gpiod_line_config_set_output_values(line_cfg,
+                                                         values, num_lines);
+               if (ret)
+                       die_perror("unable to set output values");
 
                chip = gpiod_chip_open(resolver->chips[i].path);
                if (!chip)