From patchwork Thu Feb 3 04:21:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=GP7Xu0PP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5CM0LrFz9s8q for ; Thu, 3 Feb 2022 15:23:59 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5CL5VbJz3bVt for ; Thu, 3 Feb 2022 15:23:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=GP7Xu0PP; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=GP7Xu0PP; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5B14z8mz3bVf for ; Thu, 3 Feb 2022 15:22:49 +1100 (AEDT) Received: by mail-pl1-x632.google.com with SMTP id z5so1124975plg.8 for ; Wed, 02 Feb 2022 20:22:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CTz+Zb3nuM0Ml5tqTW0KFgwUKo8tuquiqWfmc9a7zWM=; b=GP7Xu0PPrPVuUDoCu+EauxaWMOXtKM+TuM1rdENtdoJhyaPJTnJC/y/OX54YXi6Iv4 kOlzrWbeHD4GSnUNtVaXMcRoROYP+JKIIAP9ln4pYOm3SnjQPcbaYtm8/2r41kCdS8VD Xa/lGe+pyKERhfftv6AU8iCmOZ1iwaMnVkj708r0jktX6xV3gKBPKyLGJu/CLOAM7HRu 2ywnUaLlhD9250TD5T09dAg9a204EU434nlrY0K0jbWF6PTxFiXs5ktlIt+mWyVj4bqN PjQDdTY+8OPKkcEgT0OqmrMhOD6hNfqDlvAZzFiJZH+aGbpBK11Dc/a1HBYzEFswC5zy v4WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=CTz+Zb3nuM0Ml5tqTW0KFgwUKo8tuquiqWfmc9a7zWM=; b=IdDcvi1dS9uUFE0JJabVxf4RAUgaSzLC/N+IhkvQPSchlWb+EIjij51ief74KnuY6u KiTDaUU/LI3cuzdYtrvzgFRwp9ZdZeJptcBfP0z7hwApuGiy1dVdNZGDHppmSE6Wc8UH 9g9Xxh39exqgrbwia4P/Eq6Z8Kd2GZ28JOzRDbXgUhUc/iXemlQOnQq3yeDywE9KX0GI KYAYdfJ27JoUEGhjDXs8N+KaHmC5neDFbWkKcHBRQciIBxXa3WEKbR0KZtUxh89k8vj/ WXqqmDWcLwJk+91rNUv952TagGG+/7zNeMlmU6Yk9wh/eC9+vQ7AZRktlVzCS8CbiiKt Kiyg== X-Gm-Message-State: AOAM532tGYq4MofSWiH2uaTJsKKuPhZO4x2YN6+maaxuYrScmwkm6kpu hffhXb/COF8UuX5C6z7q+Pc= X-Google-Smtp-Source: ABdhPJxDzWOsRyxe5mSn3a/UD/9d3xuAuJSzJ2mUKRREPvxopLXuNZHxlSaDPRdLr3K3IPX05frTcg== X-Received: by 2002:a17:903:92:: with SMTP id o18mr33494314pld.62.1643862167534; Wed, 02 Feb 2022 20:22:47 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:46 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 1/7] tools: Clean up scandir memory allocations Date: Thu, 3 Feb 2022 14:51:28 +1030 Message-Id: <20220203042134.68425-2-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" The code copied from gpiofind didn't free the memory from scandir. Signed-off-by: Joel Stanley --- tools/tools-common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/tools-common.c b/tools/tools-common.c index 0dc3d52668d7..c83e68a2c1e4 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -190,12 +190,17 @@ struct gpiod_chip *chip_by_line_name(const char *name) die_perror("unable to open %s", entries[i]->d_name); } + free(entries[i]); offset = gpiod_chip_find_line(chip, name); - if (offset >= 0) + if (offset >= 0) { + free(entries); return chip; + } + gpiod_chip_unref(chip); } + free(entries); return NULL; } From patchwork Thu Feb 3 04:21:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=NXeNBpuY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5D35b5bz9s8q for ; Thu, 3 Feb 2022 15:24:35 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5D32BRrz2yN3 for ; Thu, 3 Feb 2022 15:24:35 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=NXeNBpuY; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::635; helo=mail-pl1-x635.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=NXeNBpuY; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5B50W7Jz3bcB for ; Thu, 3 Feb 2022 15:22:52 +1100 (AEDT) Received: by mail-pl1-x635.google.com with SMTP id d1so1115673plh.10 for ; Wed, 02 Feb 2022 20:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SnBAgxMF4MgLnVIaS9TWikI68gd/15PA6woV2819bEg=; b=NXeNBpuY04a8npxta5oEQmVE5smwM8KltFF6I5MAvm2qP2jA7mwH1Gb15SNX/W3+A8 czroPPf8HU9oUnK63ir0BFzuwoHArOebq+P0ow02ooMft6h2SL4OA9R9JC7sIM/OKFGn aMxpq4/hla5w8old/tZAY80Na7mdwQH+pxErTd/LraQZnTyJKLrORL83e7snhtavrFF5 em0ZgvqAuE7oaamVPZ1L4kVUhs2tPd9AdwYLm6BLwZVJRJ/OVG8clDPyHeQK90ea7GCX zbyvKFMLps1AwtUjeDjK36GvqJxOufhv4bocOqUnOAlhd9eJVYj1RCmcgpF+tiBpWjDt jJ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SnBAgxMF4MgLnVIaS9TWikI68gd/15PA6woV2819bEg=; b=ZcW6tb+yW/OBKyykvH0YZkpCXnbptHcgAyKrQAr5fNdIhZ9o1vqU/iSWNofolgdamT JtqrR22cMT8HnAxENpVNkqkG45HJPz1OWNCX7NfAT0R5ypvCuya0VA4mEXliNuXknzSI zO5f0MHrtfhnijQkGNlxU/iGu2hy+eFGEB+CZbE7ftprnEbK8A06EzMySH3m3g2mm2nm zwI0hiY0F7Hrt7cs/S8l0NfZ3KPqH9FirYkQvVwpXZ5kX+5O+wpuWCgc6EPM5o2wiByo 0Svv4aHJfOhspgE4yvvDogleiicqzaDHCyXxNBlcGhdp74/gCddOYk+HlJ8lA3v+QGvf RfEg== X-Gm-Message-State: AOAM533OoKPDZlaOGt6MfSr8tINEc9URH4tnvlJMSIbkDacFptf7/sb4 72NaXmIPXvXbktmHt2a6bb8= X-Google-Smtp-Source: ABdhPJxBUONJKszju+J0cZEdM//IG/OI20cjBPN1UeWhb2xMSAkZxBNCBdYvYpWI+K3DiX7532Bmaw== X-Received: by 2002:a17:90a:f485:: with SMTP id bx5mr11813812pjb.46.1643862170963; Wed, 02 Feb 2022 20:22:50 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:50 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 2/7] tools: Add line name to offset lookup helper Date: Thu, 3 Feb 2022 14:51:29 +1030 Message-Id: <20220203042134.68425-3-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" line_names_to_offsets to be used by tools that support --by-name. Signed-off-by: Joel Stanley --- tools/tools-common.c | 22 ++++++++++++++++++++++ tools/tools-common.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/tools/tools-common.c b/tools/tools-common.c index c83e68a2c1e4..958933ed6d51 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -204,3 +204,25 @@ struct gpiod_chip *chip_by_line_name(const char *name) return NULL; } +int line_names_to_offsets(struct gpiod_chip *chip, char **lines, + unsigned int *offsets, int num_lines) +{ + int i; + + for (i = 0; i < num_lines; i++) { + const char *line_name = lines[i]; + int offset; + + offset = gpiod_chip_find_line(chip, line_name); + + if (offset < 0) { + die("chip '%s' does not contain line '%s'", + gpiod_chip_get_name(chip), + line_name); + } + + offsets[i] = offset; + } + + return 0; +} diff --git a/tools/tools-common.h b/tools/tools-common.h index 5ed37dc05885..7affea436a60 100644 --- a/tools/tools-common.h +++ b/tools/tools-common.h @@ -32,5 +32,7 @@ int chip_dir_filter(const struct dirent *entry); struct gpiod_chip *chip_open_by_name(const char *name); struct gpiod_chip *chip_open_lookup(const char *device); struct gpiod_chip *chip_by_line_name(const char *name); +int line_names_to_offsets(struct gpiod_chip *chip, char **lines, + unsigned int *offsets, int num_lines); #endif /* __GPIOD_TOOLS_COMMON_H__ */ From patchwork Thu Feb 3 04:21:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=FadtJ/iF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5Dk6VlGz9s8q for ; Thu, 3 Feb 2022 15:25:10 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5Dk3Y76z3bYw for ; Thu, 3 Feb 2022 15:25:10 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=FadtJ/iF; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=FadtJ/iF; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5B82JQlz3bZX for ; Thu, 3 Feb 2022 15:22:56 +1100 (AEDT) Received: by mail-pj1-x1033.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso8866359pjv.1 for ; Wed, 02 Feb 2022 20:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5PVlIDuR32Yssny9V5o6RCbIPPLetL5jRcPV3axjBDM=; b=FadtJ/iFl9d1vXIsllvJHcQ+98hjYr/bfpo6nTZ7eZtoKfljaum6vBsyQAl/sgraaZ 6kzgx7Y1tN2gCRdM7x9yaqb8etk8fKN+g56y01l9hf5pGW6czQ3T4bPmWDprqPxl0vqg Z37aH4Nm5L6Iy4cOUClrl8NFp8RzsaCAeiQUTHqPqtdXF/esXUADKYDbBzeYiQwXHj5b vBICaihYReDmX0cJ3c5IW5bJUFS8dzDXSqYZ/TVYNxFRGXFpP8QLox6uaoDPsTo9qtBm 44uPxuL88TJVqxWFE/yP6T4F3zb6gvpgANWI4Wy8eAIXQDPtHgh0zsqNaIRVuFDYKkbR QQLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5PVlIDuR32Yssny9V5o6RCbIPPLetL5jRcPV3axjBDM=; b=QcFZ3JzULGqckKrRuh69E5Xn/CmCsbemfZ7ST3dA9WwxkSXyD2VlsR4GgI4BC/6ksT 9Zg30zq9xkQr4FGsaFmZrejLk9EGXMzVqr2N38Nj7w87Yg0MHP2LPFMwQNQAFlDEdaBx o8KWv+XY+OJ0fL6BC/a6o/tQpGSUp/K6a/bnZm19VPa6mjWRIalOcSGAYwdey5umI0RB l2w0aZFPKgW9qGsFsBxAqBvPQa1tjYCYwtQIvAw1G0wrE0yqD9Fi9CFWDQbFN1jm9qSe kushqAcOYYLbV49t++oWTq2HZ9X59/3wi2wWBrQICY8z/yMrWzc9zufZQwQVG64/lV/f QsTg== X-Gm-Message-State: AOAM533ua88q/qfcqnv4iXnZcLeA0ItFgVCGnijtJNKU9q6PHwHuVYI0 71/oUMfjQPvoJ41QCeb28GrkZNTdC6A= X-Google-Smtp-Source: ABdhPJzDyzOntRgxfZGjzfpNTZ4f1rNfATMaJydTkCGP7iQ/Vwud2/C3WFRnBoKj99iiR9Ih3/bXSA== X-Received: by 2002:a17:90b:3803:: with SMTP id mq3mr11608899pjb.95.1643862174155; Wed, 02 Feb 2022 20:22:54 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:53 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 3/7] tools: Add value support to line name lookup Date: Thu, 3 Feb 2022 14:51:30 +1030 Message-Id: <20220203042134.68425-4-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Add support for pasring the values as well as the name in line_names_to_offsets. Signed-off-by: Joel Stanley --- tools/tools-common.c | 51 ++++++++++++++++++++++++++++++++++++++++++-- tools/tools-common.h | 4 +++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tools/tools-common.c b/tools/tools-common.c index 958933ed6d51..586577566790 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -204,15 +204,57 @@ struct gpiod_chip *chip_by_line_name(const char *name) return NULL; } +char *split_line(const char *line_pair) +{ + char *name_end; + size_t name_len; + char *line_name; + + name_end = strchr(line_pair, '='); + if (!name_end) + die("invalid name/value '%s'", line_pair); + + name_len = name_end - line_pair; + + if (name_len > 32) + die("line name exceeds maximum length"); + + line_name = calloc(1, name_len + 1); + strncpy(line_name, line_pair, name_len); + + return line_name; +} + int line_names_to_offsets(struct gpiod_chip *chip, char **lines, - unsigned int *offsets, int num_lines) + unsigned int *offsets, + int *values, + int num_lines) { int i; for (i = 0; i < num_lines; i++) { - const char *line_name = lines[i]; + char *line_name; + int value; int offset; + if (values) { + const char *line_pair = lines[i]; + char *name_end; + int rv; + + line_name = split_line(line_pair); + name_end = strchr(line_pair, '='); + + rv = sscanf(name_end, "=%d", &value); + if (rv != 1) + die("invalid offset<->value mapping: %s", line_pair); + + if (value != 0 && value != 1) + die("value must be 0 or 1: %s", line_pair); + } else { + line_name = lines[i]; + } + offset = gpiod_chip_find_line(chip, line_name); if (offset < 0) { @@ -222,6 +264,11 @@ int line_names_to_offsets(struct gpiod_chip *chip, char **lines, } offsets[i] = offset; + + if (values) { + values[i] = value; + free(line_name); + } } return 0; diff --git a/tools/tools-common.h b/tools/tools-common.h index 7affea436a60..723999011733 100644 --- a/tools/tools-common.h +++ b/tools/tools-common.h @@ -33,6 +33,8 @@ struct gpiod_chip *chip_open_by_name(const char *name); struct gpiod_chip *chip_open_lookup(const char *device); struct gpiod_chip *chip_by_line_name(const char *name); int line_names_to_offsets(struct gpiod_chip *chip, char **lines, - unsigned int *offsets, int num_lines); + unsigned int *offsets, int *values, + int num_lines); +char *split_line(const char *line_pair); #endif /* __GPIOD_TOOLS_COMMON_H__ */ From patchwork Thu Feb 3 04:21:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=B90XMvr0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5FR0L5yz9s8q for ; Thu, 3 Feb 2022 15:25:47 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5FQ1zSfz3bbl for ; Thu, 3 Feb 2022 15:25:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=B90XMvr0; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::631; helo=mail-pl1-x631.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=B90XMvr0; dkim-atps=neutral Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5BC2zrfz3bZN for ; Thu, 3 Feb 2022 15:22:59 +1100 (AEDT) Received: by mail-pl1-x631.google.com with SMTP id z5so1125262plg.8 for ; Wed, 02 Feb 2022 20:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WtaAuNcUopoXBRdxvTZnjT3vtlEQbvUUGCW1xR+yS2o=; b=B90XMvr0DtNnqk/V7XkGXlRd3comtBJfKavES2DBwMG/aB3Qknk6rO9oQ/mL4+d0o5 fQB1eM1XPApumU1/LEG+Q8V7UtwWp3aFCtwpd1+0xw/Zn3Tx1+cVtpzTccfnR/C/X7ZR Z3bgO88LLIObp/Kon9vL1OkauKJ/sOUEYzrosSLXQU8TBiFoN1179meDBoyloQ5ELvE5 WJtq3mEWbRh5IuGC0552Jxq6SjxSN27RDcJ19EjBxWuKKWdz4qcMpwhaWlK/2mhXiiUC WFIFqC//Zm460Nj2ZaSST/yU0WM0DGeqtvUg0NCjbXf9x6Q7WdgeJe4U5NU9TXMYJVVA /YbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WtaAuNcUopoXBRdxvTZnjT3vtlEQbvUUGCW1xR+yS2o=; b=Py6aB3xvw/ToLB1+atJ6/W3fjHLaCx2HTN53k6CU10Ic1fHqCL34pQEk99TKtNkaUg qyYcH0QOeA/fbEFYO9SWJF9CpM5JNTSLB2OYJwnaTubO1IkxEVvoEoyVT3nbzu3pKhOz bwRJvqoGv0rYP+zuJx9zzsQCC9eG2hdClFlyzLS89GXdMKY3Fe4Bvah8TR6CjVneA0BJ bED+0DWq37EFKKTtu0k+HItqSOs0RHm/FajH6VeDmqS4bstga+K/3+OQ7zLI+KVof1RL nbJpgYs6lM2oxhQPzEx6ep7tloHGwXpMfp49L1X6/VIldra7AW12T210PjYdIeLxxRDD c9Og== X-Gm-Message-State: AOAM5333zxEiB3Q619vu/yxO8Yuw/8JIeHZsWGTCI/GyOWve7Bp3WqWU bPOCFGG2PTy2VKPEw2W5oxM= X-Google-Smtp-Source: ABdhPJyokYw2y2eVbQCJXQygo7XRqXrFFte1IP83fHh69z7HweMZUNAD5mbq3Ga7SQWljoZYaPNpeA== X-Received: by 2002:a17:902:6942:: with SMTP id k2mr33125240plt.133.1643862177366; Wed, 02 Feb 2022 20:22:57 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:56 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 4/7] tools: gpioget: Add by-name support Date: Thu, 3 Feb 2022 14:51:31 +1030 Message-Id: <20220203042134.68425-5-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Allow users to get the values of gpios by passing the gpio name. The gpipchip is not specified, instead it is discovered using the same method as gpiofind. $ gpioget --by-name switch-state 1 $ gpioget --by-name led-fault led-identify led-attention 1 0 1 Signed-off-by: Joel Stanley --- tools/gpioget.c | 57 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/tools/gpioget.c b/tools/gpioget.c index 51cecb6a18a9..9d2c82b0d64b 100644 --- a/tools/gpioget.c +++ b/tools/gpioget.c @@ -15,15 +15,18 @@ static const struct option longopts[] = { { "active-low", no_argument, NULL, 'l' }, { "dir-as-is", no_argument, NULL, 'n' }, { "bias", required_argument, NULL, 'B' }, + { "by-name", no_argument, NULL, 'N' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvlnB:"; +static const char *const shortopts = "+hvlnB:N"; static void print_help(void) { printf("Usage: %s [OPTIONS] ...\n", get_progname()); + printf(" %s [OPTIONS] -L ...\n", + get_progname()); printf("\n"); printf("Read line value(s) from a GPIO chip\n"); printf("\n"); @@ -34,6 +37,7 @@ static void print_help(void) printf(" -n, --dir-as-is:\tdon't force-reconfigure line direction\n"); printf(" -B, --bias=[as-is|disable|pull-down|pull-up] (defaults to 'as-is'):\n"); printf(" set the line bias\n"); + printf(" -N, --by-name:\tget line by name. All lines must be from the same gpiochip\n"); printf("\n"); print_bias_help(); } @@ -46,7 +50,8 @@ int main(int argc, char **argv) unsigned int *offsets, i, num_lines; struct gpiod_line_bulk *lines; struct gpiod_chip *chip; - char *device, *end; + bool by_name = false; + char *end; for (;;) { optc = getopt_long(argc, argv, shortopts, longopts, &opti); @@ -69,6 +74,9 @@ int main(int argc, char **argv) case 'B': flags |= bias_flags(optarg); break; + case 'N': + by_name = true; + break; case '?': die("try %s --help", get_progname()); default: @@ -79,30 +87,47 @@ int main(int argc, char **argv) argc -= optind; argv += optind; - if (argc < 1) - die("gpiochip must be specified"); + if (by_name) { + if (argc < 1) + die("at least one line name must be specified"); + + /* line0 line1 ... lineN */ + num_lines = argc; - if (argc < 2) - die("at least one GPIO line offset must be specified"); + chip = chip_by_line_name(argv[0]); + if (!chip) + die("unable to find gpiochip"); + } else { + /* gpiochip offset0 offset1 ... offsetN */ + if (argc < 1) + die("gpiochip must be specified"); - device = argv[0]; - num_lines = argc - 1; + if (argc < 2) + die("at least one GPIO line offset must be specified"); + + chip = chip_open_lookup(argv[0]); + if (!chip) + die_perror("unable to open %s", argv[0]); + + argv++; + num_lines = argc - 1; + } values = malloc(sizeof(*values) * num_lines); offsets = malloc(sizeof(*offsets) * num_lines); if (!values || !offsets) die("out of memory"); - for (i = 0; i < num_lines; i++) { - offsets[i] = strtoul(argv[i + 1], &end, 10); - if (*end != '\0' || offsets[i] > INT_MAX) - die("invalid GPIO offset: %s", argv[i + 1]); + if (by_name) { + line_names_to_offsets(chip, argv, offsets, NULL, num_lines); + } else { + for (i = 0; i < num_lines; i++) { + offsets[i] = strtoul(argv[i], &end, 10); + if (*end != '\0' || offsets[i] > INT_MAX) + die("invalid GPIO offset: %s", argv[i]); + } } - chip = chip_open_lookup(device); - if (!chip) - die_perror("unable to open %s", device); - lines = gpiod_chip_get_lines(chip, offsets, num_lines); if (!lines) die_perror("unable to retrieve GPIO lines from chip"); From patchwork Thu Feb 3 04:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587895 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=dy4/IL2f; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5G725JRz9s8q for ; Thu, 3 Feb 2022 15:26:23 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5G702Zdz3bZN for ; Thu, 3 Feb 2022 15:26:23 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=dy4/IL2f; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=dy4/IL2f; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5BG6TfPz3bc6 for ; Thu, 3 Feb 2022 15:23:02 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id i17so1145161pfq.13 for ; Wed, 02 Feb 2022 20:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pph8jDBQpM0nxeaoZ8APOI6SBLcJBTZ+vZr5mm8mwYw=; b=dy4/IL2fmcddqVj+HMDh28HQGkNx+1YYb+3yfo5caI1eM879OYAGX6t+xtDgAz4QGy qd8kr12ecwrgKAHICYYdfUow15HSFP10vrHimb+68E0EMr/KNRO8/PS36xRBWQ1Tkyer jKAy/UAngweagi1Bm3bCtJPwb+vW2tl6JkSPC3uMF2yflZYZgFKhfrlLNaKVGIkc6XpD t6K0b9C9n4i049e0/op1ZG7bXqjLvpjniHs3/oS692DrvzhQjKeCA4zmRsgDZiRdIFQZ ax6gqPE/KqCyIiGkQyOpsObHdzZdSihj8jQGOljogyJLZiMzgWyIvfagcPubjOP3iE/+ bXPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pph8jDBQpM0nxeaoZ8APOI6SBLcJBTZ+vZr5mm8mwYw=; b=dJE3wh/T1GXaeYxnSlKGW6hrWklCGkRExRvwoaxZmr0RkjcvGpn4TBTE2J6Wg7z2mZ AWRVPR6gp6o+ok2oyZQO8fbuI+KYpOTzInqhKo4lQUWHJIMV7jQJkklID1OjvM8qt6jo tHK0q1GWngh/sKRsVOaQAr/pMshfVyYtUK+Ywhj34dGJWPB7PW9OXZZOlC9hPnifeTZv dKzDUmMhhisDWO99OgVwjUm3FUu0e24gVrevixK7B3lMBryQgrmcLU8eYvE9f2efk/Pm OMKwOBRbLO6/ylrm6eN+jZCNbDdZyO8cvkg8KG2ScH3BJCYz/4mDFWEKwbSVZwpgFWWM +gRQ== X-Gm-Message-State: AOAM533G1LQsl2KVZ9v1bdExbg4nrAzYD2fCrlnc2GOD37GUkLmxlg80 b5unBd/ljbpVG0/a0ztCvIE= X-Google-Smtp-Source: ABdhPJwE91EI5exa8JWlsP2lShtbaHr73UJJKci59z7TjJ8EcfGXt+YaUmcUDFmquhY7aKQXCGhYsw== X-Received: by 2002:a05:6a00:1891:: with SMTP id x17mr32728622pfh.73.1643862180769; Wed, 02 Feb 2022 20:23:00 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:59 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 5/7] tools: gpioset: Add by-name support Date: Thu, 3 Feb 2022 14:51:32 +1030 Message-Id: <20220203042134.68425-6-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Allow users to set the values of gpios by passing the gpio name. The gpipchip is not specified, instead it is discovered using the same method as gpiofind. $ gpioset --mode=wait --by-name cfam-reset=1 Signed-off-by: Joel Stanley --- tools/gpioset.c | 68 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/tools/gpioset.c b/tools/gpioset.c index 7882b53bab41..fe3e1c246c89 100644 --- a/tools/gpioset.c +++ b/tools/gpioset.c @@ -23,15 +23,18 @@ static const struct option longopts[] = { { "sec", required_argument, NULL, 's' }, { "usec", required_argument, NULL, 'u' }, { "background", no_argument, NULL, 'b' }, + { "by-name", no_argument, NULL, 'N' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvlB:D:m:s:u:b"; +static const char *const shortopts = "+hvlB:D:m:s:u:bN"; static void print_help(void) { printf("Usage: %s [OPTIONS] = = ...\n", get_progname()); + printf(" %s [OPTIONS] -L ...\n", + get_progname()); printf("\n"); printf("Set GPIO line values of a GPIO chip and maintain the state until the process exits\n"); printf("\n"); @@ -48,6 +51,7 @@ static void print_help(void) printf(" -s, --sec=SEC:\tspecify the number of seconds to wait (only valid for --mode=time)\n"); printf(" -u, --usec=USEC:\tspecify the number of microseconds to wait (only valid for --mode=time)\n"); printf(" -b, --background:\tafter setting values: detach from the controlling terminal\n"); + printf(" -N, --by-name:\tset line by name. All lines must be from the same gpiochip\n"); printf("\n"); print_bias_help(); printf("\n"); @@ -195,7 +199,8 @@ int main(int argc, char **argv) struct gpiod_line_bulk *lines; struct callback_data cbdata; struct gpiod_chip *chip; - char *device, *end; + bool by_name = false; + char *end; memset(&cbdata, 0, sizeof(cbdata)); @@ -239,6 +244,9 @@ int main(int argc, char **argv) case 'b': cbdata.daemonize = true; break; + case 'N': + by_name = true; + break; case '?': die("try %s --help", get_progname()); default: @@ -257,37 +265,57 @@ int main(int argc, char **argv) cbdata.daemonize) die("can't daemonize in this mode"); - if (argc < 1) - die("gpiochip must be specified"); + if (by_name) { + char *line_name; + + if (argc < 1) + die("at least one line name must be specified"); + + line_name = split_line(argv[0]); + chip = chip_by_line_name(line_name); + if (!chip) + die("unable to find '%s' on a gpiochip", line_name); + + free(line_name); - if (argc < 2) - die("at least one GPIO line offset to value mapping must be specified"); + num_lines = argc; + } else { + if (argc < 1) + die("gpiochip must be specified"); - device = argv[0]; + if (argc < 2) + die("at least one GPIO line offset to value mapping must be specified"); - num_lines = argc - 1; + + chip = chip_open_lookup(argv[0]); + if (!chip) + die_perror("unable to open %s", argv[0]); + + num_lines = argc - 1; + argv++; + } offsets = malloc(sizeof(*offsets) * num_lines); values = malloc(sizeof(*values) * num_lines); if (!values || !offsets) die("out of memory"); - for (i = 0; i < num_lines; i++) { - rv = sscanf(argv[i + 1], "%u=%d", &offsets[i], &values[i]); - if (rv != 2) - die("invalid offset<->value mapping: %s", argv[i + 1]); + if (by_name) { + line_names_to_offsets(chip, argv, offsets, values, num_lines); + } else { + for (i = 0; i < num_lines; i++) { + rv = sscanf(argv[i], "%u=%d", &offsets[i], &values[i]); + if (rv != 2) + die("invalid offset<->value mapping: %s", argv[i + 1]); - if (values[i] != 0 && values[i] != 1) - die("value must be 0 or 1: %s", argv[i + 1]); + if (values[i] != 0 && values[i] != 1) + die("value must be 0 or 1: %s", argv[i]); - if (offsets[i] > INT_MAX) - die("invalid offset: %s", argv[i + 1]); + if (offsets[i] > INT_MAX) + die("invalid offset: %s", argv[i]); + } } - chip = chip_open_lookup(device); - if (!chip) - die_perror("unable to open %s", device); - lines = gpiod_chip_get_lines(chip, offsets, num_lines); if (!lines) die_perror("unable to retrieve GPIO lines from chip"); From patchwork Thu Feb 3 04:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ji2Crxf2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5HF2Jp9z9s8q for ; Thu, 3 Feb 2022 15:27:21 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5HD5nbCz3bZL for ; Thu, 3 Feb 2022 15:27:20 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ji2Crxf2; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1029; helo=mail-pj1-x1029.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=ji2Crxf2; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5BK6yjGz3cFX for ; Thu, 3 Feb 2022 15:23:05 +1100 (AEDT) Received: by mail-pj1-x1029.google.com with SMTP id o64so1309859pjo.2 for ; Wed, 02 Feb 2022 20:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EbHkElAxdxg7UeMWDYrSHAO+RpshB1hCDYOyLTuzLF8=; b=ji2Crxf29WymASA7SKUltPrwgBoYTSuYTAADN3qxQn8ZN6ViOuU7W2bz9XZsK3sbPw r4xd1UQ/LeW5qYjA/x1jjRyuOvSnvH++Zl2Y9aSySWLunUYvR2qqMuBkgg8B1l6gBLLI dpvjGeY7QffRc1aEqW81pH15562o5MxrQ1TCCjFbJG08kpvpc1aafjS53xir4En+zy+t vCXQoRxQeBkgQ7M2h75qYxNRMTymJigHLBr+8sr5F8vnQi7qMQnzBSuRf1JNDH/3bKW+ pNi7XdUQB6ayo72gxw+NLMKP4Ei3cCUT9JXBP/Dt1hWpFM63W6O+YekDe+nCJPRVio0S +MMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EbHkElAxdxg7UeMWDYrSHAO+RpshB1hCDYOyLTuzLF8=; b=uozW1Y8uzVBST3zqIDJ34q+D5XFkgCHwr4VWkme2eTrUIv9ZS9XEaksJi052tjBCrH YB70hKjspXSjwWYdzbuJVVDIDSVQDqaWnwDUor/OfNF8eGm0w0vYijllUzMo3bGpn0UM C1u5OKv6VZjWRplxWBlspBibFfPGi8TlbcbxoBV3s+K3pSAcmNLtNf+V70nOXlc4Gy0C zS3M9uSKLTkzNii071+wpPwe3zoO9/4ENUJYYG4zZFwwkaEvhV1GLDUveF8IRnYbK0yt m0UPH/nPeXXffKAiuT4/VPXBfK6Y2IM8U77GrXPEviyvwM9ZtBkeuZrfVtfxNLbm+5eb wtyg== X-Gm-Message-State: AOAM533+WbtZrKxCU/WxpjM8TedfhPgJ3Prj6xk85dGhORh6QIF3YZwS 4nlZRyBFKjWSq9kfwjvAY3koCQp9/vM= X-Google-Smtp-Source: ABdhPJzOoDrfzluWROAW59ZI8pGI551htVXlaz9j3xa9P2KCEJiIh5pFGwtavtaFXrECAUfozSkuoA== X-Received: by 2002:a17:903:18d:: with SMTP id z13mr33767848plg.113.1643862183946; Wed, 02 Feb 2022 20:23:03 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:23:03 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 6/7] gpio-tools-test: Add gpioset --by-name tests Date: Thu, 3 Feb 2022 14:51:33 +1030 Message-Id: <20220203042134.68425-7-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Signed-off-by: Joel Stanley --- tools/gpio-tools-test.bats | 111 +++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats index a5b97e1f98ee..a90c695fbc0f 100755 --- a/tools/gpio-tools-test.bats +++ b/tools/gpio-tools-test.bats @@ -670,6 +670,117 @@ teardown() { output_regex_match ".*unable to request lines.*" } +@test "gpioset: invalid value (by name)" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name gpio-mockup-A-0=foobar + + test "$status" -eq "1" + output_regex_match ".*invalid offset<->value mapping: gpio-mockup-A-0=foobar.*" +} + +@test "gpioset: invalid line syntax by name, missing =" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name gpio-mockup-A-0foobar + + test "$status" -eq "1" + output_regex_match ".*invalid name/value 'gpio-mockup-A-0foobar'*" +} + +@test "gpioset: invalid line syntax by name, leading =" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name =gpio-mockup-A-0foobar + + test "$status" -eq "1" + output_regex_match ".*unable to find '' on a gpiochip*" +} + +@test "gpioset: missing value (by name)" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name gpio-mockup-A-0= + + test "$status" -eq "1" + output_regex_match ".*invalid offset<->value mapping: gpio-mockup-A-0=*" +} + +@test "gpioset: invalid line name (from different gpiochip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name \ + gpio-mockup-A-0=1 \ + gpio-mockup-A-2=0 \ + gpio-mockup-B-3=1 + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'gpio-mockup-B-3'.*" +} + +@test "gpiogst: invalid line name (non existant line on a chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name \ + gpio-mockup-A-0=1 \ + missing=0 + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'missing'.*" +} + +@test "gpioset: invalid line name (non existant line, no chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name missing=1 + + test "$status" -eq "1" + output_regex_match ".*unable to find 'missing' on a gpiochip*" +} + +@test "gpioset: set lines by name and wait for SIGTERM" { + gpio_mockup_probe named-lines 2 2 8 + + coproc_run_tool gpioset --mode=signal --by-name \ + gpio-mockup-C-3=1 \ + gpio-mockup-C-6=1 \ + gpio-mockup-C-7=0 + + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 6 1 + gpio_mockup_check_value 2 7 0 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + +@test "gpioset: set lines by name using short option and wait for SIGTERM" { + gpio_mockup_probe named-lines 2 2 8 + + coproc_run_tool gpioset --mode=signal -N \ + gpio-mockup-C-3=1 \ + gpio-mockup-C-6=1 \ + gpio-mockup-C-7=0 + + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 6 1 + gpio_mockup_check_value 2 7 0 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + +@test "gpioset: no arguments (by name)" { + run_tool gpioset --by-name + + test "$status" -eq "1" + output_regex_match ".*at least one line name must be specified" +} + # # gpiomon test cases # From patchwork Thu Feb 3 04:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1587897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=aN0raUAZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jq5Hx26kLz9s8q for ; Thu, 3 Feb 2022 15:27:57 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jq5Hx04ntz3bbC for ; Thu, 3 Feb 2022 15:27:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=aN0raUAZ; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102a; helo=mail-pj1-x102a.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.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=aN0raUAZ; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Jq5BP2L8Dz3cDS for ; Thu, 3 Feb 2022 15:23:09 +1100 (AEDT) Received: by mail-pj1-x102a.google.com with SMTP id z14-20020a17090ab10e00b001b6175d4040so8900915pjq.0 for ; Wed, 02 Feb 2022 20:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N0qE6gevIlt5TZkcv2OZGPBrY66lgxFvcf9i3jBRUkY=; b=aN0raUAZo+oeseYZz27rcN64NYcG+L6yp0uoPK4vMhQN+eJ355BogSpIO1mzEF4Ni6 rDoY9TzMDTHLS73j3m+crNB9tMQVopJnFSEDmsBL4JJ+aZyu+cwxRYu01HEulZlu4PDz ICk96aSGhfNCtpw1BMMRoyoarHASsrtoU3bk0CM04rGFtd8EA5IN2T94NE7EI2eII9OT Ka0WiF4LEzJqYEnkbdKDwHSGbKFxNCUNUC9vgui3D3LlxJLHAo8/Hsu2m6XU3GIFnPcY O6YsKntlgniJmMyy/Rzk/FyzOs51nRdrBOR8UmMuQtlQUrfuVCGcPq/34vPPLzKRuG2w +M3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=N0qE6gevIlt5TZkcv2OZGPBrY66lgxFvcf9i3jBRUkY=; b=NIj7zk+MLDhBPACIsEYldYPDg4AUz6aZtioT5T/pT+K/QQ1KBmMegTFrUs4YbRUxXS e53Zosmu7Vvm4dbJKFAGR0FiOSH7dvpVKgFaHBKei5lB+oi18wIe/hby8W1PnPKH1Gne 6iwOqil0qepbE5F83v0S0vZK1pX0QNAHgn1zJyw2poFS3gNP4jcUQXwaiwA45UswALTc S8EmyeL+zgeJnczwwdV8SHboHo+Oh8HKtLWbz6AFoSR+BHdvn9ashVW/AYZowcaOOTeI HepUliGLXt1ZGO8rXwAOLtxo4m2QweX+Nhq0mdbN3QoDqTxZ6GAzi6/KqABouEOEOrHm Onjw== X-Gm-Message-State: AOAM5327cc2DwEIb09+Wo256a8VH//RoomAADpH2AXmfDgvV9rdgliCF 8uPFaAkj86AKyrE3OCLDr6Y= X-Google-Smtp-Source: ABdhPJz3EqLpyIF+ZZogMi9RyQMN7PEAmqnQjL4QV3g8bvqn3J7HCotzT0qVMpLUmhHcFI+qU/EVcA== X-Received: by 2002:a17:903:124e:: with SMTP id u14mr34604544plh.57.1643862187258; Wed, 02 Feb 2022 20:23:07 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:23:06 -0800 (PST) From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [libgpiod PATCH 7/7] gpio-tools-test: Add gpioget --by-name tests Date: Thu, 3 Feb 2022 14:51:34 +1030 Message-Id: <20220203042134.68425-8-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , openbmc@lists.ozlabs.org, Zev Weiss Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Signed-off-by: Joel Stanley --- tools/gpio-tools-test.bats | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats index a90c695fbc0f..068ade357a35 100755 --- a/tools/gpio-tools-test.bats +++ b/tools/gpio-tools-test.bats @@ -391,6 +391,79 @@ teardown() { output_regex_match ".*invalid bias.*" } +@test "gpioget: invalid line name (from different gpiochip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioget --by-name \ + gpio-mockup-A-0 \ + gpio-mockup-A-2 \ + gpio-mockup-B-3 + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'gpio-mockup-B-3'.*" +} + +@test "gpioget: invalid line name (non existant line on a chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioget --by-name \ + gpio-mockup-A-0 \ + missing + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'missing'.*" +} + +@test "gpioget: invalid line name (non existant line, no chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioget --by-name missing + + test "$status" -eq "1" + output_regex_match ".*unable to find gpiochip.*" +} + +@test "gpioget: read some lines by name" { + gpio_mockup_probe named-lines 8 8 8 + + gpio_mockup_set_pull 1 1 1 + gpio_mockup_set_pull 1 4 1 + gpio_mockup_set_pull 1 6 1 + + run_tool gpioget --by-name \ + gpio-mockup-B-0 \ + gpio-mockup-B-1 \ + gpio-mockup-B-4 \ + gpio-mockup-B-6 + + test "$status" -eq "0" + test "$output" = "0 1 1 1" +} + +@test "gpioget: no arguments (by name)" { + run_tool gpioget --by-name + + test "$status" -eq "1" + output_regex_match ".*at least one line name must be specified" +} + +@test "gpioget: read some lines by name using short option" { + gpio_mockup_probe named-lines 8 8 8 + + gpio_mockup_set_pull 1 1 1 + gpio_mockup_set_pull 1 4 1 + gpio_mockup_set_pull 1 6 1 + + run_tool gpioget -N \ + gpio-mockup-B-0 \ + gpio-mockup-B-1 \ + gpio-mockup-B-4 \ + gpio-mockup-B-6 + + test "$status" -eq "0" + test "$output" = "0 1 1 1" +} + # # gpioset test cases #