core: code shrink in gpiod_simple_set_value()
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 11 Jan 2017 15:01:25 +0000 (16:01 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 11 Jan 2017 15:01:25 +0000 (16:01 +0100)
Use one of the line request helpers and omit the set value operation,
since we can set the default value when requesting the line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
core.c

diff --git a/core.c b/core.c
index 6db048fdf62e01c9b92846bcc66e94fa41704c24..0e876487de5b7d052290c871c30f731086fffe95 100644 (file)
--- a/core.c
+++ b/core.c
@@ -192,17 +192,10 @@ int gpiod_simple_get_value(const char *device,
 int gpiod_simple_set_value(const char *device, unsigned int offset, int value,
                           bool active_low, void (*cb)(void *), void *data)
 {
-       struct gpiod_line_request_config config;
        struct gpiod_chip *chip;
        struct gpiod_line *line;
        int status;
 
-       memset(&config, 0, sizeof(config));
-       config.consumer = libgpiod_consumer;
-       config.direction = GPIOD_DIRECTION_OUTPUT;
-       config.active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
-                                        : GPIOD_ACTIVE_STATE_HIGH;
-
        chip = gpiod_chip_open_lookup(device);
        if (!chip)
                return -1;
@@ -213,15 +206,9 @@ int gpiod_simple_set_value(const char *device, unsigned int offset, int value,
                return -1;
        }
 
-       status = gpiod_line_request(line, &config, 0);
-       if (status < 0) {
-               gpiod_chip_close(chip);
-               return -1;
-       }
-
-       status = gpiod_line_set_value(line, value);
+       status = gpiod_line_request_output(line, libgpiod_consumer,
+                                          active_low, value);
        if (status < 0) {
-               gpiod_line_release(line);
                gpiod_chip_close(chip);
                return -1;
        }