From patchwork Tue Mar 15 05:32:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1605377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=YACsgTVV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4KHhrL5rpxz9sDX for ; Tue, 15 Mar 2022 16:32:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236064AbiCOFd7 (ORCPT ); Tue, 15 Mar 2022 01:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242505AbiCOFd6 (ORCPT ); Tue, 15 Mar 2022 01:33:58 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F272BF9 for ; Mon, 14 Mar 2022 22:32:46 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 15-20020a17090a098f00b001bef0376d5cso1431923pjo.5 for ; Mon, 14 Mar 2022 22:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=igfc1SMJHpw1q6l2ONoR0vUiKjn+ncWR0wqDqW2ZfQ0=; b=YACsgTVVdHBN5cLJwvGcRHnMJHl2k70bkTE51k42qUaABip/62hJoUVBxL5cz5xFXv X9+TTDuUnchhGdmY8VuhqbwJwzExYEtZH6+2KBdDsjXhlpU4EdZ0b9XEzAftbNM2TPtU 23I0a2wE22hZOSvnly62MC2gOXnnZje9tYodPxtG7jfZwcyh+gC0DYNmtWY3JQgk7ey/ 7JaXJy8h4Y1wqv74lh/7JIM5W7MArzwxMnvyI6SGn1QVhd1oW8P61ST4hXEreIoPh2nJ xgw2eqgPVWKV7eyHeh3kl40o25b8FtksbJGLOPRB7Q5DxedikV9eM7F1t4xqyDpsk3ga FHZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=igfc1SMJHpw1q6l2ONoR0vUiKjn+ncWR0wqDqW2ZfQ0=; b=e7QOIIAQN0GemtkR0Y8L+MjHdMlTx8kSbGCZGF5WAIWqP7w5Q0DJvi6ErcBZcutR73 JOY6loX8Enu9GgAD6Ig8MOdbAz0BofmdrjO94mJaSDawwB2t9b+M3xnZF4Xj4WW5FIRO mlsxe/bq/YcqUFy15mF+5AE9JvNKRBRD9K0DtH0diuML1pj3weBURXVmuqo7hHS1o31w 4c3iJWLBIbJr/kznJuw18mCrGZlQYymd48HLnZFxZ4RA8PjIrQGOrK5tXV0EdOBPbHl1 MCpK4BqASY1IuEkIGeHkmnVaAVtIyq9BWKNOwx9SghdFYEZdX+9bELh+zL1rzkNAq8M7 Ti5w== X-Gm-Message-State: AOAM530scy17C/N29pg1MDptgZHn/kAWffrrPo+aqsp5rOAYVjK2kSm/ UChRfhioQL4jrKGzB9z8nivr46Q+fwbGww== X-Google-Smtp-Source: ABdhPJw0+6zBE1bM6bx0yxIoefVR1Z5NGF26FWPKUAmnk2/1bBA6xtcoEn924nEIvzajVs4W+XYTxw== X-Received: by 2002:a17:903:244c:b0:151:b4ad:9632 with SMTP id l12-20020a170903244c00b00151b4ad9632mr26592518pls.30.1647322365969; Mon, 14 Mar 2022 22:32:45 -0700 (PDT) Received: from sol.home.arpa ([124.148.64.37]) by smtp.gmail.com with ESMTPSA id a22-20020a056a000c9600b004f7ba8b445asm8840631pfv.65.2022.03.14.22.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 22:32:45 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod v2][PATCH 1/3] core: rename gpiod_chip_info_event_wait and gpiod_chip_info_event_read Date: Tue, 15 Mar 2022 13:32:18 +0800 Message-Id: <20220315053220.102934-2-warthog618@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220315053220.102934-1-warthog618@gmail.com> References: <20220315053220.102934-1-warthog618@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Another couple of functions that don't follow the gpiod___ pattern. So rename gpiod_chip_info_event_wait to gpiod_chip_wait_info_event and gpiod_chip_info_event_read to gpiod_chip_read_info_event. Signed-off-by: Kent Gibson --- include/gpiod.h | 4 ++-- lib/chip.c | 4 ++-- tests/tests-info-event.c | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index 2365630..956ee12 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -151,7 +151,7 @@ int gpiod_chip_get_fd(struct gpiod_chip *chip); * @return 0 if wait timed out, -1 if an error occurred, 1 if an event is * pending. */ -int gpiod_chip_info_event_wait(struct gpiod_chip *chip, uint64_t timeout_ns); +int gpiod_chip_wait_info_event(struct gpiod_chip *chip, uint64_t timeout_ns); /** * @brief Read a single line status change event from the chip. @@ -160,7 +160,7 @@ int gpiod_chip_info_event_wait(struct gpiod_chip *chip, uint64_t timeout_ns); * freed by the caller using ::gpiod_info_event_free. * @note If no events are pending, this function will block. */ -struct gpiod_info_event *gpiod_chip_info_event_read(struct gpiod_chip *chip); +struct gpiod_info_event *gpiod_chip_read_info_event(struct gpiod_chip *chip); /** * @brief Map a line's name to its offset within the chip. diff --git a/lib/chip.c b/lib/chip.c index b881be1..50d8312 100644 --- a/lib/chip.c +++ b/lib/chip.c @@ -164,14 +164,14 @@ GPIOD_API int gpiod_chip_get_fd(struct gpiod_chip *chip) return chip->fd; } -GPIOD_API int gpiod_chip_info_event_wait(struct gpiod_chip *chip, +GPIOD_API int gpiod_chip_wait_info_event(struct gpiod_chip *chip, uint64_t timeout_ns) { return gpiod_poll_fd(chip->fd, timeout_ns); } GPIOD_API struct gpiod_info_event * -gpiod_chip_info_event_read(struct gpiod_chip *chip) +gpiod_chip_read_info_event(struct gpiod_chip *chip) { return gpiod_info_event_read_fd(chip->fd); } diff --git a/tests/tests-info-event.c b/tests/tests-info-event.c index 32ae690..0640d66 100644 --- a/tests/tests-info-event.c +++ b/tests/tests-info-event.c @@ -50,7 +50,7 @@ GPIOD_TEST_CASE(event_timeout) g_assert_nonnull(info); gpiod_test_return_if_failed(); - ret = gpiod_chip_info_event_wait(chip, 100000000); + ret = gpiod_chip_wait_info_event(chip, 100000000); g_assert_cmpint(ret, ==, 0); } @@ -130,11 +130,11 @@ GPIOD_TEST_CASE(request_reconfigure_release_events) request_reconfigure_release_line, &ctx); g_thread_ref(thread); - ret = gpiod_chip_info_event_wait(chip, 1000000000); + ret = gpiod_chip_wait_info_event(chip, 1000000000); g_assert_cmpint(ret, >, 0); gpiod_test_join_thread_and_return_if_failed(thread); - request_event = gpiod_chip_info_event_read(chip); + request_event = gpiod_chip_read_info_event(chip); g_assert_nonnull(request_event); gpiod_test_join_thread_and_return_if_failed(thread); @@ -148,11 +148,11 @@ GPIOD_TEST_CASE(request_reconfigure_release_events) g_assert_cmpint(gpiod_line_info_get_direction(request_info), ==, GPIOD_LINE_DIRECTION_INPUT); - ret = gpiod_chip_info_event_wait(chip, 1000000000); + ret = gpiod_chip_wait_info_event(chip, 1000000000); g_assert_cmpint(ret, >, 0); gpiod_test_join_thread_and_return_if_failed(thread); - reconfigure_event = gpiod_chip_info_event_read(chip); + reconfigure_event = gpiod_chip_read_info_event(chip); g_assert_nonnull(reconfigure_event); gpiod_test_join_thread_and_return_if_failed(thread); @@ -166,11 +166,11 @@ GPIOD_TEST_CASE(request_reconfigure_release_events) g_assert_cmpint(gpiod_line_info_get_direction(reconfigure_info), ==, GPIOD_LINE_DIRECTION_OUTPUT); - ret = gpiod_chip_info_event_wait(chip, 1000000000); + ret = gpiod_chip_wait_info_event(chip, 1000000000); g_assert_cmpint(ret, >, 0); gpiod_test_join_thread_and_return_if_failed(thread); - release_event = gpiod_chip_info_event_read(chip); + release_event = gpiod_chip_read_info_event(chip); g_assert_nonnull(release_event); gpiod_test_join_thread_and_return_if_failed(thread); @@ -243,7 +243,7 @@ GPIOD_TEST_CASE(chip_fd_can_be_polled) g_assert_cmpint(ret, >, 0); gpiod_test_join_thread_and_return_if_failed(thread); - event = gpiod_chip_info_event_read(chip); + event = gpiod_chip_read_info_event(chip); g_assert_nonnull(event); gpiod_test_join_thread_and_return_if_failed(thread); @@ -283,11 +283,11 @@ GPIOD_TEST_CASE(unwatch_and_check_that_no_events_are_generated) request = gpiod_test_request_lines_or_fail(chip, req_cfg, line_cfg); - ret = gpiod_chip_info_event_wait(chip, 100000000); + ret = gpiod_chip_wait_info_event(chip, 100000000); g_assert_cmpint(ret, >, 0); gpiod_test_return_if_failed(); - event = gpiod_chip_info_event_read(chip); + event = gpiod_chip_read_info_event(chip); g_assert_nonnull(event); gpiod_test_return_if_failed(); @@ -298,6 +298,6 @@ GPIOD_TEST_CASE(unwatch_and_check_that_no_events_are_generated) gpiod_line_request_release(request); request = NULL; - ret = gpiod_chip_info_event_wait(chip, 100000000); + ret = gpiod_chip_wait_info_event(chip, 100000000); g_assert_cmpint(ret, ==, 0); } From patchwork Tue Mar 15 05:32:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1605378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=WSAdRMRL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4KHhrd4hRPz9sDX for ; Tue, 15 Mar 2022 16:33:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344859AbiCOFeN (ORCPT ); Tue, 15 Mar 2022 01:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344851AbiCOFeH (ORCPT ); Tue, 15 Mar 2022 01:34:07 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E24426C3 for ; Mon, 14 Mar 2022 22:32:55 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id h2so13859114pfh.6 for ; Mon, 14 Mar 2022 22:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kAVdOmwt/qXJYTeSpszyIg2oJUh4OyCICloIuINos0Y=; b=WSAdRMRL8sNPC8WBqVbQOYPU/U3ePKGNI5CNz2vY/TMwoKTdY1GOqCF/my6nvdWjjx 2r9Bil+isaCeTaf4809EbDAiQjoZr87C9YxQL8Jz8M9317cSJo2KZL+csM72dZtjLTcT mrPYOlpqGG+0yLpxrgH+9UgfDuiyh/NkBJJFa2VxaA6KdoAn+BjbsEtR/ZNP5pzpd2xY wP6amSKN+n4XiiDoq1SqTY2UiRFVrrtSIJ0YW4jBfNSSiCDu6mP89DtheIMyHCTGD8Wq d+f/bPCWUBoS1/0lO3tFQG6Y8epGpY8Xfg19fn6f2qP3aGGEm7QpsZq4poSJA1OA/3Hu ks+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kAVdOmwt/qXJYTeSpszyIg2oJUh4OyCICloIuINos0Y=; b=UMgnwVD9T99/pTdUNcAyb1xTKsGroTjZYvWmoovSw7DHpo6RRj6P5LYIWsMNS5xgQf vHU8MOsCdDG9O7kmNMKMnWWWCEZkuyE4ZWdnZB3W2jMM8alaZTDQxZ3I8DNnBBK4akm3 AqOGEClkT5Xu4m3RkTKGCd92O8b3SWdxfDjpvImGdMpgKqwMNyKKDk/KIuny5+u0NRR7 wAsRZTGIWVOLhWKbtL+1QWynvw8rtSFEPmeYt2TfRw9BhhBbTh8laea0k/1dGomX9yT6 BEoDk9mK4YvG8oinmLYWnAbVPwAZlK4KvDa4pjoHL3ZDPHjaMz1MFc9lLkmC3Ed3tsfA c/Mw== X-Gm-Message-State: AOAM5339/WmZ5SGgjjKhxTN+IgO+GmXRRe1PqumF62Zvf9gs7tT5GSWP 7CvjVbWlBzmcF4jofe4b1gXRPOIzKwvwow== X-Google-Smtp-Source: ABdhPJxCSXUyNA3Ag4loFS5J7LbOI8OkSHv0yhz3ZfKlKniHWOyA11xt6edXHKZleVN9qFAsvILjIA== X-Received: by 2002:a63:82c1:0:b0:37c:9950:2fec with SMTP id w184-20020a6382c1000000b0037c99502fecmr22284135pgd.13.1647322374251; Mon, 14 Mar 2022 22:32:54 -0700 (PDT) Received: from sol.home.arpa ([124.148.64.37]) by smtp.gmail.com with ESMTPSA id a22-20020a056a000c9600b004f7ba8b445asm8840631pfv.65.2022.03.14.22.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 22:32:53 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod v2][PATCH 2/3] core: split chip_info out of chip Date: Tue, 15 Mar 2022 13:32:19 +0800 Message-Id: <20220315053220.102934-3-warthog618@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220315053220.102934-1-warthog618@gmail.com> References: <20220315053220.102934-1-warthog618@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The core library should be minimalist, only performing the operations required, but gpiod_chip_open() always fetches the chip info, even though the majority of the time the chip will only be used to request a line, so the chip info is not required. Split the chip_info from the chip, in the same style as line_info, and update methods and tools appropriately. In the rare occasions that the user requires the chip info they can request it themselves using gpiod_chip_get_info(), as demonstrated in the tool changes. Signed-off-by: Kent Gibson --- include/gpiod.h | 69 +++++++++++++++++++++++-------- lib/Makefile.am | 1 + lib/chip-info.c | 72 ++++++++++++++++++++++++++++++++ lib/chip.c | 85 ++++++++++++++++---------------------- lib/internal.h | 2 + tests/Makefile.am | 1 + tests/gpiod-test-helpers.h | 3 ++ tests/tests-chip-info.c | 54 ++++++++++++++++++++++++ tests/tests-chip.c | 32 -------------- tools/gpiodetect.c | 13 ++++-- tools/gpiofind.c | 8 +++- tools/gpioinfo.c | 16 ++++--- 12 files changed, 249 insertions(+), 107 deletions(-) create mode 100644 lib/chip-info.c create mode 100644 tests/tests-chip-info.c diff --git a/include/gpiod.h b/include/gpiod.h index 956ee12..e099515 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -41,6 +41,7 @@ extern "C" { */ struct gpiod_chip; +struct gpiod_chip_info; struct gpiod_line_info; struct gpiod_line_config; struct gpiod_request_config; @@ -75,18 +76,12 @@ struct gpiod_chip *gpiod_chip_open(const char *path); void gpiod_chip_close(struct gpiod_chip *chip); /** - * @brief Get the name of the chip as represented in the kernel. + * @brief Get information about the chip. * @param chip GPIO chip object. - * @return Pointer to a human-readable string containing the chip name. + * @return New GPIO chip info object or NULL if an error occurred. The returned + * object must be freed by the caller using ::gpiod_chip_info_free. */ -const char *gpiod_chip_get_name(struct gpiod_chip *chip); - -/** - * @brief Get the label of the chip as represented in the kernel. - * @param chip GPIO chip object. - * @return Pointer to a human-readable string containing the chip label. - */ -const char *gpiod_chip_get_label(struct gpiod_chip *chip); +struct gpiod_chip_info *gpiod_chip_get_info(struct gpiod_chip *chip); /** * @brief Get the path used to open the chip. @@ -95,13 +90,6 @@ const char *gpiod_chip_get_label(struct gpiod_chip *chip); */ const char *gpiod_chip_get_path(struct gpiod_chip *chip); -/** - * @brief Get the number of lines exposed by the chip. - * @param chip GPIO chip object. - * @return Number of GPIO lines. - */ -size_t gpiod_chip_get_num_lines(struct gpiod_chip *chip); - /** * @brief Get a snapshot of information about a line. * @param chip GPIO chip object. @@ -187,6 +175,53 @@ gpiod_chip_request_lines(struct gpiod_chip *chip, struct gpiod_request_config *req_cfg, struct gpiod_line_config *line_cfg); +/** + * @} + * + * @defgroup chip_info Chip info + * @{ + * + * Functions for retrieving kernel information about chips. + * + * Line info object contains an immutable snapshot of a chip's status. + * + * The chip info contains all the publicly available information about a + * chip. + * + * Some accessor methods return pointers. Those pointers refer to internal + * fields. The lifetimes of those fields are tied to the lifetime of the + * containing chip info object. + * Such pointers remain valid until ::gpiod_chip_info_free is called on the + * containing chip info object. They must not be freed by the caller. + */ + +/** + * @brief Free a chip info object and release all associated resources. + * @param info GPIO chip info object to free. + */ +void gpiod_chip_info_free(struct gpiod_chip_info *info); + +/** + * @brief Get the name of the chip as represented in the kernel. + * @param info GPIO chip info object. + * @return Pointer to a human-readable string containing the chip name. + */ +const char *gpiod_chip_info_get_name(struct gpiod_chip_info *info); + +/** + * @brief Get the label of the chip as represented in the kernel. + * @param info GPIO chip info object. + * @return Pointer to a human-readable string containing the chip label. + */ +const char *gpiod_chip_info_get_label(struct gpiod_chip_info *info); + +/** + * @brief Get the number of lines exposed by the chip. + * @param info GPIO chip info object. + * @return Number of GPIO lines. + */ +size_t gpiod_chip_info_get_num_lines(struct gpiod_chip_info *info); + /** * @} * diff --git a/lib/Makefile.am b/lib/Makefile.am index b6854d9..1bd2b2e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,6 +3,7 @@ lib_LTLIBRARIES = libgpiod.la libgpiod_la_SOURCES = chip.c \ + chip-info.c \ edge-event.c \ info-event.c \ internal.h \ diff --git a/lib/chip-info.c b/lib/chip-info.c new file mode 100644 index 0000000..df1f66a --- /dev/null +++ b/lib/chip-info.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// SPDX-FileCopyrightText: 2022 Bartosz Golaszewski + +/* Line attribute data structure and functions. */ + +#include +#include +#include + +#include "internal.h" + +struct gpiod_chip_info { + size_t num_lines; + char name[32]; + char label[32]; +}; + +GPIOD_API void gpiod_chip_info_free(struct gpiod_chip_info *info) +{ + if (!info) + return; + + free(info); +} + + +GPIOD_API const char *gpiod_chip_info_get_name(struct gpiod_chip_info *info) +{ + return info->name; +} + +GPIOD_API const char *gpiod_chip_info_get_label(struct gpiod_chip_info *info) +{ + return info->label; +} + +GPIOD_API size_t gpiod_chip_info_get_num_lines(struct gpiod_chip_info *info) +{ + return info->num_lines; +} + +struct gpiod_chip_info * +gpiod_chip_info_from_kernel(struct gpiochip_info *uinfo) +{ + struct gpiod_chip_info *info; + + info = malloc(sizeof(*info)); + if (!info) + return NULL; + + memset(info, 0, sizeof(*info)); + + info->num_lines = uinfo->lines; + + /* + * GPIO device must have a name - don't bother checking this field. In + * the worst case (would have to be a weird kernel bug) it'll be empty. + */ + strncpy(info->name, uinfo->name, sizeof(info->name)); + + /* + * The kernel sets the label of a GPIO device to "unknown" if it + * hasn't been defined in DT, board file etc. On the off-chance that + * we got an empty string, do the same. + */ + if (uinfo->label[0] == '\0') + strncpy(info->label, "unknown", sizeof(info->label)); + else + strncpy(info->label, uinfo->label, sizeof(info->label)); + + return info; +} diff --git a/lib/chip.c b/lib/chip.c index 50d8312..2dcabb3 100644 --- a/lib/chip.c +++ b/lib/chip.c @@ -15,17 +15,13 @@ struct gpiod_chip { int fd; - size_t num_lines; - char name[32]; - char label[32]; char *path; }; GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path) { - struct gpiochip_info info; struct gpiod_chip *chip; - int ret, fd; + int fd; if (!gpiod_is_gpiochip_device(path)) return NULL; @@ -39,39 +35,15 @@ GPIOD_API struct gpiod_chip *gpiod_chip_open(const char *path) goto err_close_fd; memset(chip, 0, sizeof(*chip)); - memset(&info, 0, sizeof(info)); chip->path = strdup(path); if (!chip->path) goto err_free_chip; - ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &info); - if (ret < 0) - goto err_free_path; - chip->fd = fd; - chip->num_lines = info.lines; - - /* - * GPIO device must have a name - don't bother checking this field. In - * the worst case (would have to be a weird kernel bug) it'll be empty. - */ - strncpy(chip->name, info.name, sizeof(chip->name)); - - /* - * The kernel sets the label of a GPIO device to "unknown" if it - * hasn't been defined in DT, board file etc. On the off-chance that - * we got an empty string, do the same. - */ - if (info.label[0] == '\0') - strncpy(chip->label, "unknown", sizeof(chip->label)); - else - strncpy(chip->label, info.label, sizeof(chip->label)); return chip; -err_free_path: - free(chip->path); err_free_chip: free(chip); err_close_fd: @@ -90,14 +62,29 @@ GPIOD_API void gpiod_chip_close(struct gpiod_chip *chip) free(chip); } -GPIOD_API const char *gpiod_chip_get_name(struct gpiod_chip *chip) +static int chip_read_chip_info(int fd, struct gpiochip_info *info) { - return chip->name; + int ret; + + memset(info, 0, sizeof(*info)); + + ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, info); + if (ret) + return -1; + + return 0; } -GPIOD_API const char *gpiod_chip_get_label(struct gpiod_chip *chip) +GPIOD_API struct gpiod_chip_info *gpiod_chip_get_info(struct gpiod_chip *chip) { - return chip->label; + struct gpiochip_info info; + int ret; + + ret = chip_read_chip_info(chip->fd, &info); + if (ret < 0) + return NULL; + + return gpiod_chip_info_from_kernel(&info); } GPIOD_API const char *gpiod_chip_get_path(struct gpiod_chip *chip) @@ -105,23 +92,18 @@ GPIOD_API const char *gpiod_chip_get_path(struct gpiod_chip *chip) return chip->path; } -GPIOD_API size_t gpiod_chip_get_num_lines(struct gpiod_chip *chip) -{ - return chip->num_lines; -} - static int chip_read_line_info(int fd, unsigned int offset, - struct gpio_v2_line_info *infobuf, bool watch) + struct gpio_v2_line_info *info, bool watch) { int ret, cmd; - memset(infobuf, 0, sizeof(*infobuf)); - infobuf->offset = offset; + memset(info, 0, sizeof(*info)); + info->offset = offset; cmd = watch ? GPIO_V2_GET_LINEINFO_WATCH_IOCTL : GPIO_V2_GET_LINEINFO_IOCTL; - ret = ioctl(fd, cmd, infobuf); + ret = ioctl(fd, cmd, info); if (ret) return -1; @@ -131,14 +113,14 @@ static int chip_read_line_info(int fd, unsigned int offset, static struct gpiod_line_info * chip_get_line_info(struct gpiod_chip *chip, unsigned int offset, bool watch) { - struct gpio_v2_line_info infobuf; + struct gpio_v2_line_info info; int ret; - ret = chip_read_line_info(chip->fd, offset, &infobuf, watch); + ret = chip_read_line_info(chip->fd, offset, &info, watch); if (ret) return NULL; - return gpiod_line_info_from_kernel(&infobuf); + return gpiod_line_info_from_kernel(&info); } GPIOD_API struct gpiod_line_info * @@ -178,16 +160,21 @@ gpiod_chip_read_info_event(struct gpiod_chip *chip) GPIOD_API int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) { - struct gpio_v2_line_info infobuf; + struct gpiochip_info chinfo; + struct gpio_v2_line_info linfo; unsigned int offset; int ret; - for (offset = 0; offset < chip->num_lines; offset++) { - ret = chip_read_line_info(chip->fd, offset, &infobuf, false); + ret = chip_read_chip_info(chip->fd, &chinfo); + if (ret < 0) + return -1; + + for (offset = 0; offset < chinfo.lines; offset++) { + ret = chip_read_line_info(chip->fd, offset, &linfo, false); if (ret) return -1; - if (strcmp(name, infobuf.name) == 0) + if (strcmp(name, linfo.name) == 0) return offset; } diff --git a/lib/internal.h b/lib/internal.h index 9af2cda..ffef578 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -18,6 +18,8 @@ #define GPIOD_BIT(nr) (1UL << (nr)) +struct gpiod_chip_info * +gpiod_chip_info_from_kernel(struct gpiochip_info *infobuf); struct gpiod_line_info * gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf); int gpiod_request_config_to_kernel(struct gpiod_request_config *config, diff --git a/tests/Makefile.am b/tests/Makefile.am index 89bf868..f37dc03 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,6 +23,7 @@ gpiod_test_SOURCES = \ gpiod-test-sim.c \ gpiod-test-sim.h \ tests-chip.c \ + tests-chip-info.c \ tests-edge-event.c \ tests-info-event.c \ tests-line-config.c \ diff --git a/tests/gpiod-test-helpers.h b/tests/gpiod-test-helpers.h index 4aa4202..acba686 100644 --- a/tests/gpiod-test-helpers.h +++ b/tests/gpiod-test-helpers.h @@ -18,6 +18,9 @@ typedef struct gpiod_chip struct_gpiod_chip; G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_chip, gpiod_chip_close); +typedef struct gpiod_chip_info struct_gpiod_chip_info; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_chip_info, gpiod_chip_info_free); + typedef struct gpiod_line_info struct_gpiod_line_info; G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_line_info, gpiod_line_info_free); diff --git a/tests/tests-chip-info.c b/tests/tests-chip-info.c new file mode 100644 index 0000000..bffe823 --- /dev/null +++ b/tests/tests-chip-info.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2017-2022 Bartosz Golaszewski + +#include +#include +#include + +#include "gpiod-test.h" +#include "gpiod-test-helpers.h" +#include "gpiod-test-sim.h" + +#define GPIOD_TEST_GROUP "chip-info" + +GPIOD_TEST_CASE(get_chip_info_name) +{ + g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); + g_autoptr(struct_gpiod_chip) chip = NULL; + g_autoptr(struct_gpiod_chip_info) info = NULL; + + chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); + + info = gpiod_chip_get_info(chip); + g_assert_nonnull(info); + g_assert_cmpstr(gpiod_chip_info_get_name(info), ==, + g_gpiosim_chip_get_name(sim)); +} + +GPIOD_TEST_CASE(get_chip_info_label) +{ + g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("label", "foobar", + NULL); + g_autoptr(struct_gpiod_chip) chip = NULL; + g_autoptr(struct_gpiod_chip_info) info = NULL; + + chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); + info = gpiod_chip_get_info(chip); + g_assert_nonnull(info); + + g_assert_cmpstr(gpiod_chip_info_get_label(info), ==, "foobar"); +} + +GPIOD_TEST_CASE(get_num_lines) +{ + g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 16, NULL); + g_autoptr(struct_gpiod_chip) chip = NULL; + g_autoptr(struct_gpiod_chip_info) info = NULL; + + chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); + info = gpiod_chip_get_info(chip); + g_assert_nonnull(info); + + g_assert_cmpuint(gpiod_chip_info_get_num_lines(info), ==, 16); +} + diff --git a/tests/tests-chip.c b/tests/tests-chip.c index 09906e3..3fad16d 100644 --- a/tests/tests-chip.c +++ b/tests/tests-chip.c @@ -47,28 +47,6 @@ GPIOD_TEST_CASE(open_chip_not_a_gpio_device) gpiod_test_expect_errno(ENODEV); } -GPIOD_TEST_CASE(get_chip_name) -{ - g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); - g_autoptr(struct_gpiod_chip) chip = NULL; - - chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); - - g_assert_cmpstr(gpiod_chip_get_name(chip), ==, - g_gpiosim_chip_get_name(sim)); -} - -GPIOD_TEST_CASE(get_chip_label) -{ - g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("label", "foobar", - NULL); - g_autoptr(struct_gpiod_chip) chip = NULL; - - chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); - - g_assert_cmpstr(gpiod_chip_get_label(chip), ==, "foobar"); -} - GPIOD_TEST_CASE(get_chip_path) { g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); @@ -80,16 +58,6 @@ GPIOD_TEST_CASE(get_chip_path) g_assert_cmpstr(gpiod_chip_get_path(chip), ==, path); } -GPIOD_TEST_CASE(get_num_lines) -{ - g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 16, NULL); - g_autoptr(struct_gpiod_chip) chip = NULL; - - chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim)); - - g_assert_cmpuint(gpiod_chip_get_num_lines(chip), ==, 16); -} - GPIOD_TEST_CASE(get_fd) { g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new(NULL); diff --git a/tools/gpiodetect.c b/tools/gpiodetect.c index 6ce3cb8..8f6e8b3 100644 --- a/tools/gpiodetect.c +++ b/tools/gpiodetect.c @@ -34,6 +34,7 @@ int main(int argc, char **argv) { int optc, opti, num_chips, i; struct gpiod_chip *chip; + struct gpiod_chip_info *info; struct dirent **entries; for (;;) { @@ -70,11 +71,17 @@ int main(int argc, char **argv) if (!chip) die_perror("unable to open %s", entries[i]->d_name); + info = gpiod_chip_get_info(chip); + if (!info) + die_perror("unable to get info for %s", entries[i]->d_name); + + printf("%s [%s] (%zu lines)\n", - gpiod_chip_get_name(chip), - gpiod_chip_get_label(chip), - gpiod_chip_get_num_lines(chip)); + gpiod_chip_info_get_name(info), + gpiod_chip_info_get_label(info), + gpiod_chip_info_get_num_lines(info)); + gpiod_chip_info_free(info); gpiod_chip_close(chip); free(entries[i]); } diff --git a/tools/gpiofind.c b/tools/gpiofind.c index 910cb8b..36eba86 100644 --- a/tools/gpiofind.c +++ b/tools/gpiofind.c @@ -34,6 +34,7 @@ int main(int argc, char **argv) { int i, num_chips, optc, opti, offset; struct gpiod_chip *chip; + struct gpiod_chip_info *info; struct dirent **entries; for (;;) { @@ -76,8 +77,13 @@ int main(int argc, char **argv) offset = gpiod_chip_find_line(chip, argv[0]); if (offset >= 0) { + info = gpiod_chip_get_info(chip); + if (!info) + die_perror("unable to get info for %s", entries[i]->d_name); + printf("%s %u\n", - gpiod_chip_get_name(chip), offset); + gpiod_chip_info_get_name(info), offset); + gpiod_chip_info_free(info); gpiod_chip_close(chip); return EXIT_SUCCESS; } diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c index c852b36..fbe2a13 100644 --- a/tools/gpioinfo.c +++ b/tools/gpioinfo.c @@ -125,19 +125,24 @@ static PRINTF(3, 4) void prinfo(bool *of, static void list_lines(struct gpiod_chip *chip) { bool flag_printed, of, active_low; + struct gpiod_chip_info *chip_info; struct gpiod_line_info *info; const char *name, *consumer; - size_t i, offset; + size_t i, offset, num_lines; int direction; + chip_info = gpiod_chip_get_info(chip); + if (!chip_info) + die_perror("unable to retrieve the chip info from chip"); + + num_lines = gpiod_chip_info_get_num_lines(chip_info); printf("%s - %zu lines:\n", - gpiod_chip_get_name(chip), gpiod_chip_get_num_lines(chip)); + gpiod_chip_info_get_name(chip_info), num_lines); - for (offset = 0; offset < gpiod_chip_get_num_lines(chip); offset++) { + for (offset = 0; offset < num_lines; offset++) { info = gpiod_chip_get_line_info(chip, offset); if (!info) - die_perror("unable to retrieve the line object from chip"); - + die_perror("unable to retrieve the line info from chip"); name = gpiod_line_info_get_name(info); consumer = gpiod_line_info_get_consumer(info); direction = gpiod_line_info_get_direction(info); @@ -184,6 +189,7 @@ static void list_lines(struct gpiod_chip *chip) gpiod_line_info_free(info); } + gpiod_chip_info_free(chip_info); } int main(int argc, char **argv) From patchwork Tue Mar 15 05:32:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1605379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=CBTwuAlo; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4KHhrj0Glcz9sDX for ; Tue, 15 Mar 2022 16:33:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242505AbiCOFeS (ORCPT ); Tue, 15 Mar 2022 01:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344882AbiCOFeP (ORCPT ); Tue, 15 Mar 2022 01:34:15 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BF9125F7 for ; Mon, 14 Mar 2022 22:33:02 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id a5so17864255pfv.2 for ; Mon, 14 Mar 2022 22:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fpu4nip1Oxgtdtlw5drYbar1aq+6hwtm+1CnkHAnzpw=; b=CBTwuAlojoiHI2rfWruJaV5HvpFzVwB47jPaGF5tF0Vvr17pTAwbEBGCWBlcrChq5K C1PkfocQnOQIIwd0tzYQmCwbCuCGLTaPQx2jYjps06O8dau1LDBKYt8+pmIWDqW15eDg yu0o6+J0RpCAfEQRICn1roozfC/C/3YYFUdCbsrt8NQibM+yqZwso6TipsrRnmAc/EzW yY2inQag16uVbOPw8YhmoWg3SjHjdXZFlbrxnpgApAjxQz0vcqKc4Ezmjy9vHYtUJfW6 w4oMJhUWVmh1XHEtfQXN9CqPA0XHBJqm+HEjKmnT1+swPa1tC2pr/70/lUFNzS2W/QeS bgwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fpu4nip1Oxgtdtlw5drYbar1aq+6hwtm+1CnkHAnzpw=; b=c9vsgKlcSd0jfyY7rGjq7x4LzrS8Vc+aY1T3LT5WtB2SFHhc7LSLTlPMQUKD3VGB1S 2IFhD93VLikZaxGXjXF5wrMm7gN8gyyKOhK7y4ssrni2MvopdmruM7ud06a7BKcm7C1f Z3ww1+zunEG9fdQm8r7D3CN71siVNZXM24E20QTUlzTWq1N42Jf1srpovc0wxjwdsN+6 msjBODw5ppMXOX+DApfPnXAUYt7It4K7ywPFVXEO6Z5hMWcS/AJfojdLSfpnv/v/ir8+ uXNhUiA3r1MzlZ62fqLzwKDiHmJGIixiLoiNeQ+quwnMLX1CQlMjEMKI8wligbRE08jr 72rA== X-Gm-Message-State: AOAM533hrqbbdxOMxL1Xogsh1SD5S7itUsvqRoZ6BNzcMaIkcwJsYgf2 SsLkXaOEEIZYXnHRLp6fAei3SsV+XAICIQ== X-Google-Smtp-Source: ABdhPJx1jHPKTrqKBZmnjNOdiRaaKFDAcD8TMfCOVbhDakbMv4QToajL65qe2W4VTNT3fetaFeDLLQ== X-Received: by 2002:a63:4b1e:0:b0:365:8bc:6665 with SMTP id y30-20020a634b1e000000b0036508bc6665mr23227398pga.445.1647322379789; Mon, 14 Mar 2022 22:32:59 -0700 (PDT) Received: from sol.home.arpa ([124.148.64.37]) by smtp.gmail.com with ESMTPSA id a22-20020a056a000c9600b004f7ba8b445asm8840631pfv.65.2022.03.14.22.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 22:32:59 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod v2][PATCH 3/3] line-info: rename infobuf to uinfo Date: Tue, 15 Mar 2022 13:32:20 +0800 Message-Id: <20220315053220.102934-4-warthog618@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220315053220.102934-1-warthog618@gmail.com> References: <20220315053220.102934-1-warthog618@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The infobuf variable in gpiod_line_info_from_kernel() refers to the uAPI version of the info, and the "buf" suffix doesn't really emphasise that, so rename it to uinfo. Signed-off-by: Kent Gibson --- lib/line-info.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/line-info.c b/lib/line-info.c index fc656f9..168fc86 100644 --- a/lib/line-info.c +++ b/lib/line-info.c @@ -106,7 +106,7 @@ gpiod_line_info_get_debounce_period_us(struct gpiod_line_info *info) } struct gpiod_line_info * -gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf) +gpiod_line_info_from_kernel(struct gpio_v2_line_info *uinfo) { struct gpio_v2_line_attribute *attr; struct gpiod_line_info *info; @@ -118,47 +118,47 @@ gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf) memset(info, 0, sizeof(*info)); - info->offset = infobuf->offset; - strncpy(info->name, infobuf->name, GPIO_MAX_NAME_SIZE); + info->offset = uinfo->offset; + strncpy(info->name, uinfo->name, GPIO_MAX_NAME_SIZE); - info->used = !!(infobuf->flags & GPIO_V2_LINE_FLAG_USED); - strncpy(info->consumer, infobuf->consumer, GPIO_MAX_NAME_SIZE); + info->used = !!(uinfo->flags & GPIO_V2_LINE_FLAG_USED); + strncpy(info->consumer, uinfo->consumer, GPIO_MAX_NAME_SIZE); - if (infobuf->flags & GPIO_V2_LINE_FLAG_OUTPUT) + if (uinfo->flags & GPIO_V2_LINE_FLAG_OUTPUT) info->direction = GPIOD_LINE_DIRECTION_OUTPUT; else info->direction = GPIOD_LINE_DIRECTION_INPUT; - if (infobuf->flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW) + if (uinfo->flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW) info->active_low = true; - if (infobuf->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP) + if (uinfo->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_UP) info->bias = GPIOD_LINE_BIAS_PULL_UP; - else if (infobuf->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN) + else if (uinfo->flags & GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN) info->bias = GPIOD_LINE_BIAS_PULL_DOWN; - else if (infobuf->flags & GPIO_V2_LINE_FLAG_BIAS_DISABLED) + else if (uinfo->flags & GPIO_V2_LINE_FLAG_BIAS_DISABLED) info->bias = GPIOD_LINE_BIAS_DISABLED; else info->bias = GPIOD_LINE_BIAS_UNKNOWN; - if (infobuf->flags & GPIO_V2_LINE_FLAG_OPEN_DRAIN) + if (uinfo->flags & GPIO_V2_LINE_FLAG_OPEN_DRAIN) info->drive = GPIOD_LINE_DRIVE_OPEN_DRAIN; - else if (infobuf->flags & GPIO_V2_LINE_FLAG_OPEN_SOURCE) + else if (uinfo->flags & GPIO_V2_LINE_FLAG_OPEN_SOURCE) info->drive = GPIOD_LINE_DRIVE_OPEN_SOURCE; else info->drive = GPIOD_LINE_DRIVE_PUSH_PULL; - if ((infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) && - (infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)) + if ((uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) && + (uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)) info->edge = GPIOD_LINE_EDGE_BOTH; - else if (infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) + else if (uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) info->edge = GPIOD_LINE_EDGE_RISING; - else if (infobuf->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING) + else if (uinfo->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING) info->edge = GPIOD_LINE_EDGE_FALLING; else info->edge = GPIOD_LINE_EDGE_NONE; - if (infobuf->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME) + if (uinfo->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME) info->event_clock = GPIOD_LINE_EVENT_CLOCK_REALTIME; else info->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC; @@ -167,8 +167,8 @@ gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf) * We assume that the kernel returns correct configuration and that no * attributes repeat. */ - for (i = 0; i < infobuf->num_attrs; i++) { - attr = &infobuf->attrs[i]; + for (i = 0; i < uinfo->num_attrs; i++) { + attr = &uinfo->attrs[i]; if (attr->id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE) { info->debounced = true;