From 1d92c4112cfbaf322fac3d7e781b715b8efec4bb Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 2 Jan 2017 16:23:24 +0100 Subject: [PATCH] core: update line info after a line request Currently the line information isn't updated after it's been requested. Re-read the line info after requesting it. Signed-off-by: Bartosz Golaszewski --- core.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/core.c b/core.c index a108eda..e376d6a 100644 --- a/core.c +++ b/core.c @@ -159,6 +159,23 @@ struct gpiod_line { struct gpiohandle_request *req; }; +static int update_line_info(struct gpiod_line *line, + struct gpiod_chip *chip, unsigned int offset) +{ + int status, fd; + + memset(&line->info, 0, sizeof(line->info)); + line->info.line_offset = offset; + + fd = gpiod_chip_get_fd(chip); + + status = gpio_ioctl(fd, GPIO_GET_LINEINFO_IOCTL, &line->info); + if (status < 0) + return -1; + + return 0; +} + unsigned int gpiod_line_offset(struct gpiod_line *line) { return (unsigned int)line->info.line_offset; @@ -243,6 +260,13 @@ int gpiod_line_request(struct gpiod_line *line, const char *consumer, line->requested = true; + /* Update line info to include the changes after the request. */ + status = update_line_info(line, chip, gpiod_line_offset(line)); + if (status < 0) { + gpiod_line_release(line); + return -1; + } + return 0; } @@ -430,16 +454,12 @@ gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) } line = &chip->lines[offset]; + line->chip = chip; - memset(&line->info, 0, sizeof(line->info)); - line->info.line_offset = offset; - - status = gpio_ioctl(chip->fd, GPIO_GET_LINEINFO_IOCTL, &line->info); + status = update_line_info(line, chip, offset); if (status < 0) return NULL; - line->chip = chip; - return line; } -- 2.30.2