From patchwork Fri Sep 4 15:45:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03C98C433E2 for ; Fri, 4 Sep 2020 15:46:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1ABC2074D for ; Fri, 4 Sep 2020 15:46:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ZLU7hI+W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726658AbgIDPqo (ORCPT ); Fri, 4 Sep 2020 11:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbgIDPqf (ORCPT ); Fri, 4 Sep 2020 11:46:35 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5364FC061249 for ; Fri, 4 Sep 2020 08:46:33 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id v4so6494199wmj.5 for ; Fri, 04 Sep 2020 08:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wTtZyQw48avsFdpHOI98/RhzmvMtVCVcNE1bMjyUXUY=; b=ZLU7hI+Wc7S/0ExzQYekPR5nYEvn3dMLSQ8I8NS3mnZfZUiBd2hetNf19N4pAZv1rI DeIhjhpv+zGnVF6vXYiT19iDuA70MNhfyPFxDNolyuYpQ+WQPep3iMglPTEWxBqZ8+oT vn7MeRdaCfJsMgVjjhpN3lDMPfwPzYCL0KCjFoh5eY59T/BCH1Bxn2ZR0G+C07XuE7fp PRgjTuH/qNg773hmdRgtGTinUP9YvmZ93r3YGgQuXB0ok8/p1MuKgYPGwYMySRAwo/Gc bEsLyowk16QRwX7LiDALkhMvoMzY75po+CjvBg0ASsdV5yorNWtDBjqCllhBUMyDBWxM XjoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wTtZyQw48avsFdpHOI98/RhzmvMtVCVcNE1bMjyUXUY=; b=hDroEbf/VpEa9mYe63KgG0PYpVUzpH0pVr74CHR2pV3DirU8y4pMJQ9CltUX0JNbkm bwRVssHLX6xF835od9gEsHU4BRdRLsb21PF7iF2YqiDFRmbIWy6aiVV1Eve/qR6JgRzF mAqF39i5nJ+GDaRk3GwUtF9q1qALRaENDHDyi/JZvby0tezz5YD0mvhrTX8j65iwUz0k 0fXcHqyuDjI9XlR/IFXUQ/7NwSY4XA0/uKNVVIe8ojsmmbLHM1+sIhM2pqxSBEhVB2vs zAmJU945Uws6Dg0RbJ+M6YMa7x0q8Va+Ul+c4lloOw+hhQfqrp+U5ZQ3EfykMWKCVRGH UZgA== X-Gm-Message-State: AOAM530qadTJ9N/TasoCB2AW34emgkB4+tA1MCuC6CAb4hARCeWHzk2U 3wLV8YJ8NGD/vajWAWqfpf8xsQ== X-Google-Smtp-Source: ABdhPJzK1kWNGIgBMdYGgwQSUscLv8S6S2shXWsDOTyjh9QvJLrxo7r/bW7tLuw/15SUb2KbDSDOUQ== X-Received: by 2002:a05:600c:258:: with SMTP id 24mr8513082wmj.66.1599234391665; Fri, 04 Sep 2020 08:46:31 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:31 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 01/23] lib: cmdline: export next_arg() Date: Fri, 4 Sep 2020 17:45:25 +0200 Message-Id: <20200904154547.3836-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We want to use this helper in a module (gpio-mockup) for parsing user input when creating dummy devices. Let's export it. Signed-off-by: Bartosz Golaszewski --- lib/cmdline.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cmdline.c b/lib/cmdline.c index fbb9981a04a4..e194f76d546e 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -247,3 +247,4 @@ char *next_arg(char *args, char **param, char **val) /* Chew up trailing spaces. */ return skip_spaces(next); } +EXPORT_SYMBOL(next_arg); From patchwork Fri Sep 4 15:45:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B2DAC43461 for ; Fri, 4 Sep 2020 15:50:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE6E620791 for ; Fri, 4 Sep 2020 15:50:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="c4iemgVa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727780AbgIDPuy (ORCPT ); Fri, 4 Sep 2020 11:50:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbgIDPqj (ORCPT ); Fri, 4 Sep 2020 11:46:39 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC2B6C061251 for ; Fri, 4 Sep 2020 08:46:34 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u18so6483038wmc.3 for ; Fri, 04 Sep 2020 08:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vWT4LMe1jlQ5F4wTOV6aM7wzQxRaEROx7lvhEPCZV1g=; b=c4iemgVawDaHCECJORVkcx3F23o+ngLwd98jCO5TKSproRslYQQctVYTTM8UAJMpno 9OahHxJIeo5aYvZNRQPvh2jQni7929HthhKQDT5j1D4kwPLA1oL5+XlcMiOwPCZ706kw PnJg4bP95Tel8j4NTMYLFXvz80DER0vDH7VENrsFyr329Zym+rZ9HGUJ97VEu7DS47cl y7AfhrjHufDdd3ZXZ4+iD9HT9YTtKRt3c/qVr4Cr3W4FCxwVkxwX/GWNt5HJpqxW7O5E ku1RbS4J9HF/RsQr9ckv3YiIz2dhVM8llU2PTQ7jPwTbSIWYWa1IUIBiUSSt8RPUngM2 2Wbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vWT4LMe1jlQ5F4wTOV6aM7wzQxRaEROx7lvhEPCZV1g=; b=RFJzOIWcs5rkzG6HOwfXnywxL7GCHM0h2vmbtS3a9fe/K96ntKDGjDZVcf+Q1EPuNL YFKtUIaTNaIaeq1TZg3M3M/tkqJ/RYJU8/meQk5IeQ3PanL3+0vO6VNfOOqNm4xA6/Qk Olrwz5cmI44+P3fF1q67q7TrfS/jE/7doScYLX1Q5XG/msG3Ag4I46/im3RfFEQ6ZXQM DGro1zB9SpUch2jOqq4AHwVjfDmV5D3fOHAszhHBtACy31fXroSHT0AOzL/7i/Pjc2YP wXElsUJvKfiqjifXnzmFwbi5L8v8PgGGJ1/dvQcuFuUc77tzD2aSKcdszc+ZyA2KAIeV r7JQ== X-Gm-Message-State: AOAM530V0fwCWZ2g8ef17cFE/yligL5TFjRrkxGaQQcmvf9PFCh50tkZ GpiiNjIoYCOtHWOYOmfgNDjGHw== X-Google-Smtp-Source: ABdhPJzIHOojNgmX6R7Azvg1X7daJLCe748526/eTTIsYoMZCTXYG8GFpTts0cg6K3JXTDM7/wavuA== X-Received: by 2002:a7b:c1c3:: with SMTP id a3mr8883702wmj.68.1599234393322; Fri, 04 Sep 2020 08:46:33 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:32 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 02/23] lib: string_helpers: provide kfree_strarray() Date: Fri, 4 Sep 2020 17:45:26 +0200 Message-Id: <20200904154547.3836-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski There's a common pattern of dynamically allocating an array of char pointers and then also dynamically allocating each string in this array. Provide a helper for freeing such a string array with one call. Signed-off-by: Bartosz Golaszewski --- include/linux/string_helpers.h | 2 ++ lib/string_helpers.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 86f150c2a6b6..55b25120a1c6 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -94,4 +94,6 @@ char *kstrdup_quotable(const char *src, gfp_t gfp); char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); char *kstrdup_quotable_file(struct file *file, gfp_t gfp); +void kfree_strarray(char **str_array, size_t num_str); + #endif diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 963050c0283e..22505efc6aae 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -649,3 +649,25 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) return pathname; } EXPORT_SYMBOL_GPL(kstrdup_quotable_file); + +/** + * kfree_strarray - free a number of dynamically allocated strings contained + * in an array and the array itself + * + * @str_array: Dynamically allocated array of strings to free. If NULL - the + * function does nothing. + * @num_str: Number of strings (starting from the beginning of the array) to + * free. + */ +void kfree_strarray(char **str_array, size_t num_str) +{ + unsigned int i; + + if (!str_array) + return; + + for (i = 0; i < num_str; i++) + kfree(str_array[i]); + kfree(str_array); +} +EXPORT_SYMBOL_GPL(kfree_strarray); From patchwork Fri Sep 4 15:45:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39183C43461 for ; Fri, 4 Sep 2020 15:50:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03DBB2078E for ; Fri, 4 Sep 2020 15:50:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="s1xR3LsW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726369AbgIDPuh (ORCPT ); Fri, 4 Sep 2020 11:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgIDPql (ORCPT ); Fri, 4 Sep 2020 11:46:41 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CA16C061262 for ; Fri, 4 Sep 2020 08:46:36 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id w2so6506329wmi.1 for ; Fri, 04 Sep 2020 08:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G/17FBPXPIWM8suCIksrM34pviF3YRrgB9AFaEGMFdE=; b=s1xR3LsW3xC8wWHiTS17D3noApVypmQZqsrQfpiRs3PVIwAeFMZZbmrhd8Ci29gUPJ qeOOKIOcwVPtsmoJlPGUTae8LZaB1lpmP6r4EJ1NBihJlqmxiuHREKgewRXkyhcbElzS SS1a0rIr4TASNOM3hcJ3cZB11T75Gewkn/+XChRfGta6FMOWhPlpWi43w+qSn+26/cg3 pbuCojaEVkETdLTS/bA9q1uWIDfRtJyA3iW487kzDXs//zaJpMKiytj5yoUxgcrwimPG bUmkGN4uCR708R4v0zUpXw1XNhk53ufiFhyihcZ01PCTVRPSHlYYUYA4uWSsDCodiL31 v+fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G/17FBPXPIWM8suCIksrM34pviF3YRrgB9AFaEGMFdE=; b=TTEfnis/+NeVdp/GlMEZ25WqRptdfLyH3Q52ArIPm+tUxwev6Sbx7dH+jSSuEL0/h3 i9zZhYnsVaNQFXPvkmCdPWNK7bT464qoSG7XU4Vt2s75tC2J1PPX6auGQ8+Ub1xkLdZx kcmrqRlTQyeOjUERUiG2pRu7HwliDv7U8LW5X1XkMCq+OLxNTuwE5aKyCXODS3z2eq0Y Q288j9rEFJETpgZD/hqk0A3uz06a79WwBmFIjA3ZDRvE8iy6KzaAb8KIWb7VtvAFzeH2 79j8R7kBH8msYPVU0ayvdvOXBcqi5Lbq2FJGzOlkpiw24etYeu2ir6gjG7yRYriKF4FW 3gUg== X-Gm-Message-State: AOAM531tRXF2KPlPDViqXiUggbdABlsEjsKCmMoNwTAncgN0lKajkZQK ZxWxPih1RKDu1pO/SvxSzrbkpw== X-Google-Smtp-Source: ABdhPJz+8ARUs/kkukG0PPhJ3TJmui9hHStd+idsyDCLVB6+Ez/AJZiQ1EBjt7zRf0qJu3eKFFnoJg== X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr8050965wmg.164.1599234394881; Fri, 04 Sep 2020 08:46:34 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:34 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 03/23] lib: uaccess: provide getline_from_user() Date: Fri, 4 Sep 2020 17:45:27 +0200 Message-Id: <20200904154547.3836-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide a uaccess helper that allows callers to copy a single line from user memory. This is useful for debugfs write callbacks. Signed-off-by: Bartosz Golaszewski --- include/linux/uaccess.h | 3 +++ lib/usercopy.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 94b285411659..5aedd8ac5c31 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -333,6 +333,9 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, long count); long strnlen_user_nofault(const void __user *unsafe_addr, long count); +ssize_t getline_from_user(char *dst, size_t dst_size, + const char __user *src, size_t src_size); + /** * get_kernel_nofault(): safely attempt to read from a location * @val: read into this variable diff --git a/lib/usercopy.c b/lib/usercopy.c index b26509f112f9..55aaaf93d847 100644 --- a/lib/usercopy.c +++ b/lib/usercopy.c @@ -87,3 +87,40 @@ int check_zeroed_user(const void __user *from, size_t size) return -EFAULT; } EXPORT_SYMBOL(check_zeroed_user); + +/** + * getline_from_user - Copy a single line from user + * @dst: Where to copy the line to + * @dst_size: Size of the destination buffer + * @src: Where to copy the line from + * @src_size: Size of the source user buffer + * + * Copies a number of characters from given user buffer into the dst buffer. + * The number of bytes is limited to the lesser of the sizes of both buffers. + * If the copied string contains a newline, its first occurrence is replaced + * by a NULL byte in the destination buffer. Otherwise the function ensures + * the copied string is NULL-terminated. + * + * Returns the number of copied bytes or a negative error number on failure. + */ + +ssize_t getline_from_user(char *dst, size_t dst_size, + const char __user *src, size_t src_size) +{ + size_t size = min_t(size_t, dst_size, src_size); + char *c; + int ret; + + ret = copy_from_user(dst, src, size); + if (ret) + return -EFAULT; + + dst[size - 1] = '\0'; + + c = strchrnul(dst, '\n'); + if (*c) + *c = '\0'; + + return c - dst; +} +EXPORT_SYMBOL(getline_from_user); From patchwork Fri Sep 4 15:45:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA7E2C433E2 for ; Fri, 4 Sep 2020 15:50:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B75682074D for ; Fri, 4 Sep 2020 15:50:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="cvyMcRXD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726637AbgIDPuQ (ORCPT ); Fri, 4 Sep 2020 11:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbgIDPqo (ORCPT ); Fri, 4 Sep 2020 11:46:44 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4565AC06121A for ; Fri, 4 Sep 2020 08:46:37 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id z1so7244025wrt.3 for ; Fri, 04 Sep 2020 08:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cb3cnGs7j5WS2IcngwK5TKfzy31yqveiACoeOQ6PNok=; b=cvyMcRXDXhXJQxnzLheQiagZqk91Hq3/DSe9O6FVYKHP/1Z0rIZBkBb06Hc1ZOsmKC BJLw9+MREkwONtKQHHVg0Zm+VK+NwCmqrAtyqndwca00OEQJzmAH691WJ4BwomrC/lDi ueqFD5Xez3f5fWi8k6HnlpPnQcWdfbvIob4B7zrpeCwjM2jgfOb1nzFyOwbfHBV3uEok utKIZVZ1tu4QhZRdeHawOCIhgmXIbtxZfbIEhf8Sm9mHmscVLOsTww4QkVJrZeT8woTV AAn0VAiAYSyj/MEGJzBQvAE/pU/teeVk9dprJLAhzo9hik115rydBc26fBE5iuQHznMt WpSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cb3cnGs7j5WS2IcngwK5TKfzy31yqveiACoeOQ6PNok=; b=WfnjCZIOx2ulBvKmYKhTgBp6TiaQpMm2jLQ5fTddlsGPmH65t626inriQD7NldLyPS r9gIDgwuzBIpupOwTEi88zTnWXJ6pzG91EFxzMNxBoJH8nAg4gqN1Ifzsl9T1wPtGPDT ROF5R0mj6qa/UD5Ju93xZUygQ74kPeTyeS0bvaYEa3jyyxGSGTkTXizvz9NBSVWrvkAl p3hxHO++TZMGLhCYkwBHr6Djiuv3B4Ihou0KWiPwdBGHAE14rEVqpIbB5t2oC4XOy1/O Lama58tfJev92K5EpUP34AFy7ATnNM1MHbm/4fdyo0yD0ZhIc0nuJlgytUQoL3XLPkKE 2BAQ== X-Gm-Message-State: AOAM531dLSq1jQPV9lOeG+qm6Cxz9tlEYbf3jFiXeLdywxb43Dl7BaFk J+mDpReuG6zgfIiX6k1d/jfQPg== X-Google-Smtp-Source: ABdhPJyCwJJId2FBp9EzeFlUcmTzo35MIF3b1AJLQnqt3x7RSOA5HXIN8vSfohQcUDDXbopw85qnBw== X-Received: by 2002:adf:fc43:: with SMTP id e3mr7909391wrs.28.1599234395939; Fri, 04 Sep 2020 08:46:35 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:35 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 04/23] gpiolib: generalize devprop_gpiochip_set_names() for device properties Date: Fri, 4 Sep 2020 17:45:28 +0200 Message-Id: <20200904154547.3836-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski devprop_gpiochip_set_names() is overly complicated with taking the fwnode argument (which requires using dev_fwnode() & of_fwnode_handle() in ACPI and OF GPIO code respectively). Let's just switch to using the generic device properties. This allows us to pull the code setting line names directly into gpiochip_add_data_with_key() instead of handling it separately for ACPI and OF. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-acpi.c | 3 --- drivers/gpio/gpiolib-devprop.c | 19 ++++++++++--------- drivers/gpio/gpiolib-of.c | 5 ----- drivers/gpio/gpiolib.c | 8 ++++---- include/linux/gpio/driver.h | 3 +-- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 54ca3c18b291..834a12f3219e 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -1221,9 +1221,6 @@ void acpi_gpiochip_add(struct gpio_chip *chip) return; } - if (!chip->names) - devprop_gpiochip_set_names(chip, dev_fwnode(chip->parent)); - acpi_gpiochip_request_regions(acpi_gpio); acpi_gpiochip_scan_gpios(acpi_gpio); acpi_walk_dep_device_list(handle); diff --git a/drivers/gpio/gpiolib-devprop.c b/drivers/gpio/gpiolib-devprop.c index 26741032fa9e..a28659b4f9c9 100644 --- a/drivers/gpio/gpiolib-devprop.c +++ b/drivers/gpio/gpiolib-devprop.c @@ -17,25 +17,24 @@ /** * devprop_gpiochip_set_names - Set GPIO line names using device properties * @chip: GPIO chip whose lines should be named, if possible - * @fwnode: Property Node containing the gpio-line-names property * * Looks for device property "gpio-line-names" and if it exists assigns * GPIO line names for the chip. The memory allocated for the assigned - * names belong to the underlying firmware node and should not be released + * names belong to the underlying software node and should not be released * by the caller. */ -void devprop_gpiochip_set_names(struct gpio_chip *chip, - const struct fwnode_handle *fwnode) +int devprop_gpiochip_set_names(struct gpio_chip *chip) { struct gpio_device *gdev = chip->gpiodev; + struct device *dev = chip->parent; const char **names; int ret, i; int count; - count = fwnode_property_read_string_array(fwnode, "gpio-line-names", + count = device_property_read_string_array(dev, "gpio-line-names", NULL, 0); if (count < 0) - return; + return 0; if (count > gdev->ngpio) { dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", @@ -45,19 +44,21 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip, names = kcalloc(count, sizeof(*names), GFP_KERNEL); if (!names) - return; + return -ENOMEM; - ret = fwnode_property_read_string_array(fwnode, "gpio-line-names", + ret = device_property_read_string_array(dev, "gpio-line-names", names, count); if (ret < 0) { dev_warn(&gdev->dev, "failed to read GPIO line names\n"); kfree(names); - return; + return ret; } for (i = 0; i < count; i++) gdev->descs[i].name = names[i]; kfree(names); + + return 0; } EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names); diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index bd31dd3b6a75..2f895a2b8411 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -1026,11 +1026,6 @@ int of_gpiochip_add(struct gpio_chip *chip) if (ret) return ret; - /* If the chip defines names itself, these take precedence */ - if (!chip->names) - devprop_gpiochip_set_names(chip, - of_fwnode_handle(chip->of_node)); - of_node_get(chip->of_node); ret = of_gpiochip_scan_gpios(chip); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 80137c1b3cdc..0d390f0ec32c 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -340,9 +340,6 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) struct gpio_device *gdev = gc->gpiodev; int i; - if (!gc->names) - return 0; - /* First check all names if they are unique */ for (i = 0; i != gc->ngpio; ++i) { struct gpio_desc *gpio; @@ -621,7 +618,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, INIT_LIST_HEAD(&gdev->pin_ranges); #endif - ret = gpiochip_set_desc_names(gc); + if (gc->names) + ret = gpiochip_set_desc_names(gc); + else + ret = devprop_gpiochip_set_names(gc); if (ret) goto err_remove_from_list; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index d1cef5c2715c..56485a040b82 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -756,8 +756,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, enum gpiod_flags dflags); void gpiochip_free_own_desc(struct gpio_desc *desc); -void devprop_gpiochip_set_names(struct gpio_chip *gc, - const struct fwnode_handle *fwnode); +int devprop_gpiochip_set_names(struct gpio_chip *gc); #ifdef CONFIG_GPIOLIB From patchwork Fri Sep 4 15:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D358C2BB84 for ; Fri, 4 Sep 2020 15:49:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28370206E7 for ; Fri, 4 Sep 2020 15:49:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="p6+ozsPx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726948AbgIDPq6 (ORCPT ); Fri, 4 Sep 2020 11:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgIDPqq (ORCPT ); Fri, 4 Sep 2020 11:46:46 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77D8CC061234 for ; Fri, 4 Sep 2020 08:46:38 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id z4so7213405wrr.4 for ; Fri, 04 Sep 2020 08:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U1nBCcNL8BeNxadPopc6bEehAwgvXwIu9mXvHzCgK8I=; b=p6+ozsPxwsblRZBCpVmBP7qVN0c1CSrx+fQWcqeSx2ykc5J0fyO83akiBJSKb4fObd yQkluWfXAW1xUpE/a/FmkvipuYuJFIXeBRQN6YHlrGEDwcxjGUjCifUpGQn+Z9PSKHB9 tZ/AGLgg2kq+Hz2boTAN8B2I18BtR2A4vZ+P6IvHlxuVzx6IB+fPjeFu7Xh74RXA5AVm Un7a6R2xmZSajmcdaTmP9wx0IbBq3KvVxsT+swGdZAFNxWtBAmPcFm+pJx10udDTzex/ LXUL3Kajpvv8vIpFGU0V2hdjPyqhZi0a0RY5fZOQYG8J9WZL4wcTCe2btth/wOeXwmQ6 gL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U1nBCcNL8BeNxadPopc6bEehAwgvXwIu9mXvHzCgK8I=; b=r4E5/kZvGnO97/d4cMvy4NVp9/13uVyNzYiLuyR7pJetChNz7r01d75K5xl1SEh6zA yUBSkSxDT4pl1swyui1ltixEarqiZ4FFHR8nzVsIq2eXhDg1Ytg3UV7eFn2xzbXrnpYk mLTmWMdTkoO7e11bHZQRdI+CDcC15TLkb/x1eO5hUQDEcHkCRDTk+zhMlB10PRDZbM91 zRI8kF7L1H2fdMbwFWPd7jBr6dpxXACOsWFbyA+uQu3R9rLPKXkEvwWC6gdvsXClgFIs IJXDfpTP00+xxveHZhqyD6XO+SqtND5hUYiR9da6/3TzACnrlRj9DXmBCMi4s+Si0mOJ H4HQ== X-Gm-Message-State: AOAM5322pQEPH+6aEwgc24Htwy2rSOdB6VoF+wc3iggBOREv5lceKr4K XILVPQGSQps+mlDdK33jDPcrRA== X-Google-Smtp-Source: ABdhPJxKPO93ctBJ7Ow4MExd8CKDovERdU03BsC4lwZGsWCoWTY7HZN7SxfvjywlGty5Qr0fODTzVw== X-Received: by 2002:adf:e391:: with SMTP id e17mr7982842wrm.289.1599234397164; Fri, 04 Sep 2020 08:46:37 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:36 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 05/23] gpiolib: unexport devprop_gpiochip_set_names() Date: Fri, 4 Sep 2020 17:45:29 +0200 Message-Id: <20200904154547.3836-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Now that devprop_gpiochip_set_names() is only used in a single place inside drivers/gpio/gpiolib.c, there's no need anymore for it to be exported or to even live in its own source file. Pull this function into the core source file for gpiolib. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/Makefile | 1 - drivers/gpio/gpiolib-devprop.c | 64 ---------------------------------- drivers/gpio/gpiolib.c | 48 +++++++++++++++++++++++++ include/linux/gpio/driver.h | 2 -- 4 files changed, 48 insertions(+), 67 deletions(-) delete mode 100644 drivers/gpio/gpiolib-devprop.c diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 4f9abff4f2dc..639275eb4e4d 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -6,7 +6,6 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIOLIB) += gpiolib.o obj-$(CONFIG_GPIOLIB) += gpiolib-devres.o obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o -obj-$(CONFIG_GPIOLIB) += gpiolib-devprop.o obj-$(CONFIG_GPIOLIB) += gpiolib-cdev.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.o obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o diff --git a/drivers/gpio/gpiolib-devprop.c b/drivers/gpio/gpiolib-devprop.c deleted file mode 100644 index a28659b4f9c9..000000000000 --- a/drivers/gpio/gpiolib-devprop.c +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Device property helpers for GPIO chips. - * - * Copyright (C) 2016, Intel Corporation - * Author: Mika Westerberg - */ - -#include -#include -#include -#include -#include - -#include "gpiolib.h" - -/** - * devprop_gpiochip_set_names - Set GPIO line names using device properties - * @chip: GPIO chip whose lines should be named, if possible - * - * Looks for device property "gpio-line-names" and if it exists assigns - * GPIO line names for the chip. The memory allocated for the assigned - * names belong to the underlying software node and should not be released - * by the caller. - */ -int devprop_gpiochip_set_names(struct gpio_chip *chip) -{ - struct gpio_device *gdev = chip->gpiodev; - struct device *dev = chip->parent; - const char **names; - int ret, i; - int count; - - count = device_property_read_string_array(dev, "gpio-line-names", - NULL, 0); - if (count < 0) - return 0; - - if (count > gdev->ngpio) { - dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", - count, gdev->ngpio); - count = gdev->ngpio; - } - - names = kcalloc(count, sizeof(*names), GFP_KERNEL); - if (!names) - return -ENOMEM; - - ret = device_property_read_string_array(dev, "gpio-line-names", - names, count); - if (ret < 0) { - dev_warn(&gdev->dev, "failed to read GPIO line names\n"); - kfree(names); - return ret; - } - - for (i = 0; i < count; i++) - gdev->descs[i].name = names[i]; - - kfree(names); - - return 0; -} -EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0d390f0ec32c..15c99cf560ee 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -358,6 +358,54 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) return 0; } +/* + * devprop_gpiochip_set_names - Set GPIO line names using device properties + * @chip: GPIO chip whose lines should be named, if possible + * + * Looks for device property "gpio-line-names" and if it exists assigns + * GPIO line names for the chip. The memory allocated for the assigned + * names belong to the underlying software node and should not be released + * by the caller. + */ +static int devprop_gpiochip_set_names(struct gpio_chip *chip) +{ + struct gpio_device *gdev = chip->gpiodev; + struct device *dev = chip->parent; + const char **names; + int ret, i; + int count; + + count = device_property_read_string_array(dev, "gpio-line-names", + NULL, 0); + if (count < 0) + return 0; + + if (count > gdev->ngpio) { + dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", + count, gdev->ngpio); + count = gdev->ngpio; + } + + names = kcalloc(count, sizeof(*names), GFP_KERNEL); + if (!names) + return -ENOMEM; + + ret = device_property_read_string_array(dev, "gpio-line-names", + names, count); + if (ret < 0) { + dev_warn(&gdev->dev, "failed to read GPIO line names\n"); + kfree(names); + return ret; + } + + for (i = 0; i < count; i++) + gdev->descs[i].name = names[i]; + + kfree(names); + + return 0; +} + static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) { unsigned long *p; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 56485a040b82..4a7e295c3640 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -756,8 +756,6 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, enum gpiod_flags dflags); void gpiochip_free_own_desc(struct gpio_desc *desc); -int devprop_gpiochip_set_names(struct gpio_chip *gc); - #ifdef CONFIG_GPIOLIB /* lock/unlock as IRQ */ From patchwork Fri Sep 4 15:45:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7E66C433E2 for ; Fri, 4 Sep 2020 15:50:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C6B120770 for ; Fri, 4 Sep 2020 15:50:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="OSJLrqQl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727937AbgIDPuB (ORCPT ); Fri, 4 Sep 2020 11:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbgIDPqq (ORCPT ); Fri, 4 Sep 2020 11:46:46 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BEBAC06123A for ; Fri, 4 Sep 2020 08:46:39 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id a17so7191312wrn.6 for ; Fri, 04 Sep 2020 08:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DcRR0cvj/PHR5JcTPOP5KmS/Yg2MBZu1qA5qfQNGk0A=; b=OSJLrqQlcETqpO5qPErz470rrP4H38PM0Pt8IMETO0NAQJtD9YhqhPpbnjVgO6z5Pc zFTnWa4ltyNBOIYyvM+4tgoe3kWJWGZqE++V+EWXWa7BQTeJRGUXB+RdjUucwaB8vcA8 a87JibEI+hux9ZIBnOWbmMRMtjtepM2P3EDk7RX7CdRquBDpTnwVnZks1Czho5gigPzO ZBW5pug6/6n5xkuc53cIUj/ofUMQo9ZoeuLagXDiIzxELjsil7e+coJ8Ky5yYDlrwcXU cOpD7DsDHXxX3RQEoBjI4dZ0NGVoglP+yauppUuvEEQIuJHNgVPXVtwRoCNu/iQqYXLn CGxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DcRR0cvj/PHR5JcTPOP5KmS/Yg2MBZu1qA5qfQNGk0A=; b=ofb4/tZYkXQBBZUC7w7WaF8Cx6IamwFo8Vw6r0kEEkmCP4iPFNjt/ngipwo5ZJIYlf VE91gdqd9xsgB1zWK0EDPPBoLNRy0Z5UFYxRezdEJunihQSQXSCwz4zixSmi9cLIKQuL FmbeaGXY63RVKBlRik8NdXnk1jOVkJ+2vWkHOqt3jCVboFYjRfgFVom2tGARYOeR0QfO RuTa88GTVRS1J4Xhpliqr+p2Kk2AZajbZ/t3c+6dB/daiwwlPPRjm7pk7rzUmskeMk+W 9wnt1122xK4xWMv7Ebb8e9f/xBlaIZWK6Ek3i5Lk5M0vGH61zSShB0+YYAQ7py+CTm3y 9UFg== X-Gm-Message-State: AOAM531ZV00TGBdGZeXywenQTTLjeFQ946V0OKdEJQ7BI/2uZPFJlBr8 4k7a2+krfXWAt4Ym14gE3g3eUA== X-Google-Smtp-Source: ABdhPJzydKpw4Z5FsNZ+t0aMz2hV1ayLaJITUh07WUEGRLKoHkz5Fpef/XIauwVmwQp52xf/HGURHw== X-Received: by 2002:adf:9d44:: with SMTP id o4mr8314372wre.361.1599234398291; Fri, 04 Sep 2020 08:46:38 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:37 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 06/23] gpiolib: switch to simpler IDA interface Date: Fri, 4 Sep 2020 17:45:30 +0200 Message-Id: <20200904154547.3836-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We don't need to specify any ranges when allocating IDs so we can switch to ida_alloc() and ida_free() instead of the ida_simple_ counterparts. ida_simple_get(ida, 0, 0, gfp) is equivalent to ida_alloc_range(ida, 0, UINT_MAX, gfp) which is equivalent to ida_alloc(ida, gfp). Note: IDR will never actually allocate an ID larger than INT_MAX. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 15c99cf560ee..591777bc2285 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -471,7 +471,7 @@ static void gpiodevice_release(struct device *dev) struct gpio_device *gdev = dev_get_drvdata(dev); list_del(&gdev->list); - ida_simple_remove(&gpio_ida, gdev->id); + ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); kfree(gdev->descs); kfree(gdev); @@ -582,7 +582,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, gc->of_node = gdev->dev.of_node; #endif - gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); + gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); if (gdev->id < 0) { ret = gdev->id; goto err_free_gdev; @@ -753,7 +753,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, err_free_descs: kfree(gdev->descs); err_free_ida: - ida_simple_remove(&gpio_ida, gdev->id); + ida_free(&gpio_ida, gdev->id); err_free_gdev: /* failures here can mean systems won't boot... */ pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__, From patchwork Fri Sep 4 15:45:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C941C433E2 for ; Fri, 4 Sep 2020 15:47:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F1EB206E7 for ; Fri, 4 Sep 2020 15:47:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ZEDEcIxO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbgIDPrA (ORCPT ); Fri, 4 Sep 2020 11:47:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726833AbgIDPqr (ORCPT ); Fri, 4 Sep 2020 11:46:47 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAB01C06123C for ; Fri, 4 Sep 2020 08:46:40 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id e16so7227174wrm.2 for ; Fri, 04 Sep 2020 08:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=21luy6X7MDo33702JiSjX8+ptN78cMUdDvCAknmXlNw=; b=ZEDEcIxOclm9rkbYpejxrNIf2E5BaNtltbEx7kL2MmvTjXkaO6NcxogFQaPWUTVU90 RQCLCwd/0LeBvBHib8CSLZ6t0N3QMb9pIjEGew+/3FUx7nmAv9U1jw1QGsifrgj7RZz/ BvxCb7fT6vR8yVfjeZ1cK4bgxVds+FqqAq0SqwC1YeYbevfwSlBCI23wJCoMB61VVWI+ OMMY4pKIa6QlNrAheHEoiU+ozpVA1RJj07hzk4oeA+31wZzEmN0aoQgAip9RFc0XjC7l wZbRPvzHN5/YFjUV8Y9Q9UX0mrRaDx5MfQwrYwVOKbAIytZjQyAsHR3o/g0JEjUNHJNG x79Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=21luy6X7MDo33702JiSjX8+ptN78cMUdDvCAknmXlNw=; b=CfUu7BfDyQ0v9ebTYZuDRqbvq8U4/0d3awB7Jzwu8eVNEa4GxIVoEA1XmdoxSyFQBv 0GWIOC++BXPrAqZmqapfFt6RtJxIsgcnSwpcFEuaswlaWrR52jfK7mBWF0Aa1I+5+iuz dWCqJMMI8i1xaY5goCzCho37noyC0DIDB+R9l47YWYgC89B4LtGXpPaZAnLj37Y3JHwM dPjwfySliPRogPWP2D6PB45WkMO53I8cPyBC5DcTQkuZCLi2IPBV/ilr8zLMCH4+eMiT +2ugkVQsBVZX52T2eBwxZckDL32+9hmtURgpfEe5c7oglihnN/imi0DeVyJZqjykVqnk aRPQ== X-Gm-Message-State: AOAM533bfK4tStP6DeQltIbugcd2RdSsvwoViTeFsFriNBFFHvmw8JIw BmINhD1XUMoD07dh4VrVUk4Q9g== X-Google-Smtp-Source: ABdhPJwCyK6EASQNgZuAXwqjHkJs+DAdmBTT0auSRhh6ETOzmG9L8g4BM5hkjVixy9irlGFHNaRE7A== X-Received: by 2002:adf:e8ce:: with SMTP id k14mr8773344wrn.394.1599234399347; Fri, 04 Sep 2020 08:46:39 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:38 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 07/23] gpio: mockup: drop unneeded includes Date: Fri, 4 Sep 2020 17:45:31 +0200 Message-Id: <20200904154547.3836-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This module doesn't need gpio/consumer.h - it's a provider. It also doesn't use any symbols from init.h so let's remove both includes. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index bc345185db26..349782cdb4d7 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -8,9 +8,7 @@ */ #include -#include #include -#include #include #include #include From patchwork Fri Sep 4 15:45:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C7F1C43461 for ; Fri, 4 Sep 2020 15:50:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CED2E2074D for ; Fri, 4 Sep 2020 15:50:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Oy+MLb0I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726109AbgIDPuA (ORCPT ); Fri, 4 Sep 2020 11:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbgIDPqt (ORCPT ); Fri, 4 Sep 2020 11:46:49 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 644D7C06123E for ; Fri, 4 Sep 2020 08:46:42 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id z4so7213578wrr.4 for ; Fri, 04 Sep 2020 08:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1aSHEiYdSd1JWJ6Q0fBo+4tu4psdYuKAXtqnRnr2Its=; b=Oy+MLb0IWTb6ZupRszNfTziNTh0ywTx6FlKIT8t2tD8VQIQ/8ByFDmVlrdZpD4yaU6 31IH6N59+zZpkrotpOwib9cdA0vB5eqHldy11Ogy0Yj9baMhJvEpTHWD66X16BARRyUo 9oi+Y4JnSREtrRFEf82FblZFb2kcA1dZ/2jowhVHZvBBCnXsaY3ry6kqVkI+8N6U83hg +diQ8BySNCXwAfRIv8tEoNm2a/IjEg2BkxnJ4Ul5x0593RtKim/vaEzmKuPTJiqPrQR3 MYGE9bZtTv8LADfAzsTI9QLyI3COyQ/nt7ZEbNmYBgw7S/vTTttx/NMyKWGN9CVXIiCI YLSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1aSHEiYdSd1JWJ6Q0fBo+4tu4psdYuKAXtqnRnr2Its=; b=kZBOiRG2mmHXzVA9Eo+oGQ5N38kcS9ltlDy6uiFVwzXaQaxVNZLJJ8rvb0ABF+KfkL NTHHjzWNJkPeJPNvjCV4iGsWvVWoFka+MP9GXXxSJAVvedz2C6fkDfwAgK2Iw/6F7FVz mXoIV/2Hjwn4VxpCYsnwducXBIiuNeWDbfhYxWEBOuTmAcB+0Dz0Z+edTjq+TqqJJshB HHBiakoHUbms6nUE6Zv5EWTwR6aT7l6zXbRoI9ALX56dBsZ0Tk+2rfAqCQ0fFd6BskwU fpfR7Ja42++1WD0cNvOL7FyAKRwkUkuti8e4FkEEVp7/9GzChRSh3+fPNPr+bLW7ffTR 7ziA== X-Gm-Message-State: AOAM5326EKK6LNSqjq2qH0Wy7/mUBPqpti0A8Uustyy9E0Oa228J3j4x rOJsXOmVuyE9EktSWiitSKZwYw== X-Google-Smtp-Source: ABdhPJx0xcvEJZJYZh6Boev229NGkoHO5q22dnKA1Z9y/c/DRCXfxt6f5JdAAP6bdUbwd3hUT6ZhlA== X-Received: by 2002:adf:fa02:: with SMTP id m2mr8219192wrr.273.1599234401059; Fri, 04 Sep 2020 08:46:41 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:39 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 08/23] gpio: mockup: use pr_fmt() Date: Fri, 4 Sep 2020 17:45:32 +0200 Message-Id: <20200904154547.3836-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We don't need a custom logging helper. Let's use the standard pr_fmt() macro which allows us to use all pr_*() routines with custom format. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 349782cdb4d7..73cd51459c2a 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -21,6 +21,9 @@ #include "gpiolib.h" +#undef pr_fmt +#define pr_fmt(fmt) GPIO_MOCKUP_NAME ": " fmt + #define GPIO_MOCKUP_NAME "gpio-mockup" #define GPIO_MOCKUP_MAX_GC 10 /* @@ -31,8 +34,6 @@ /* Maximum of three properties + the sentinel. */ #define GPIO_MOCKUP_MAX_PROP 4 -#define gpio_mockup_err(...) pr_err(GPIO_MOCKUP_NAME ": " __VA_ARGS__) - /* * struct gpio_pin_status - structure describing a GPIO status * @dir: Configures direction of gpio as "in" or "out" @@ -549,7 +550,7 @@ static int __init gpio_mockup_init(void) err = platform_driver_register(&gpio_mockup_driver); if (err) { - gpio_mockup_err("error registering platform driver\n"); + pr_err("error registering platform driver\n"); return err; } @@ -577,7 +578,7 @@ static int __init gpio_mockup_init(void) pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { - gpio_mockup_err("error registering device"); + pr_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver); gpio_mockup_unregister_pdevs(); return PTR_ERR(pdev); From patchwork Fri Sep 4 15:45:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0396EC433E2 for ; Fri, 4 Sep 2020 15:49:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCDFC2074D for ; Fri, 4 Sep 2020 15:49:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="uPvmch86" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726914AbgIDPty (ORCPT ); Fri, 4 Sep 2020 11:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726922AbgIDPqx (ORCPT ); Fri, 4 Sep 2020 11:46:53 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EE8CC0611E2 for ; Fri, 4 Sep 2020 08:46:43 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id a65so6472775wme.5 for ; Fri, 04 Sep 2020 08:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j/oJst/31Ve7sN2p8SCKacvVyyAcOuKLg7HZEv9T1Bg=; b=uPvmch86FehCHUzRin+H5CXUohTvqZcGHApZczW8eq9lu/MJzFf9k2ReFbXCNCKyKp QAnbVmcbSwdGJkgvs9p8KOl0pQFjMwybe/CpY7Hh8XOol4HEQj390odpGv/D8NzqLzMQ AvpKvNqhVW5l5nuN1vqDrYMGBJRpIjjleROe9WsZdIidLQSeFxFz28InaQK6FDuGaHh5 abODV06AGHy0/63WGITnhu2uh99JLKd0WdxfAiAeP2mKsEWCMrGiumxY/dt5qdEeKyOV cuO2DAPfpRJIBrUcEDpHpmxvfKAlccqkdA/9Vos4EFtb0JOtN0HxFexJBPe9MvVF5WWw hEzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j/oJst/31Ve7sN2p8SCKacvVyyAcOuKLg7HZEv9T1Bg=; b=Ze/SQI2eGXp0NwosiYUd0XnEPt2ly/Gkya1JDxbRcuWRr4jtokt/tY/XTV6Ketmse3 dgvZ7IED7aL1cH7QSFy9YuJl+dLhP0+Tfm6qLqTkosWnwmgIYS7QVBxRUWAdcrk2UbK6 pqH59V4wGz2ziftEnHHlDnlba3HswHE8wk2LAZD7/nCrRjtxQBO7AeoCvdWH6wqbkuzK vIkQ8st0+Ff3SuId4NFvWdPniWepTvc8aiG6MGJXc/FKZsb86gQiWwPVQVKJeavhirn3 FO+VeeNgB1Za5GmgSpBlCbKG3viaiRAf7esYZcshGMo9fsMAllOu2HYumlM26h7ocfs9 q7PA== X-Gm-Message-State: AOAM531nMLS7Ir8DrswwDiJ++FpDPVOd1Dq49IeQE+Q+wgBG0S/671xQ tY4had+UuVRapUA3IaJvbERkiA== X-Google-Smtp-Source: ABdhPJxeZd3+cr0IB9roZ5GLjIlStXJyf7rbMppNX/92diAh72W08u+6KqmM8T0vs4cn4upk6ZXE0Q== X-Received: by 2002:a1c:4d14:: with SMTP id o20mr7896110wmh.115.1599234402232; Fri, 04 Sep 2020 08:46:42 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:41 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 09/23] gpio: mockup: use KBUILD_MODNAME Date: Fri, 4 Sep 2020 17:45:33 +0200 Message-Id: <20200904154547.3836-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Drop the definition for the driver name. Let's use KBUILD_MODNAME for the log format and use the "gpio-mockup" value directly in the only place where it's relevant: in the name of the device. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 73cd51459c2a..78c97f7b6893 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -22,9 +22,8 @@ #include "gpiolib.h" #undef pr_fmt -#define pr_fmt(fmt) GPIO_MOCKUP_NAME ": " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#define GPIO_MOCKUP_NAME "gpio-mockup" #define GPIO_MOCKUP_MAX_GC 10 /* * We're storing two values per chip: the GPIO base and the number @@ -501,7 +500,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) static struct platform_driver gpio_mockup_driver = { .driver = { - .name = GPIO_MOCKUP_NAME, + .name = "gpio-mockup", }, .probe = gpio_mockup_probe, }; @@ -572,7 +571,7 @@ static int __init gpio_mockup_init(void) properties[prop++] = PROPERTY_ENTRY_BOOL( "named-gpio-lines"); - pdevinfo.name = GPIO_MOCKUP_NAME; + pdevinfo.name = "gpio-mockup"; pdevinfo.id = i; pdevinfo.properties = properties; From patchwork Fri Sep 4 15:45:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33BF5C43461 for ; Fri, 4 Sep 2020 15:50:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 087212074D for ; Fri, 4 Sep 2020 15:50:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="DHwiLfdY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726922AbgIDPty (ORCPT ); Fri, 4 Sep 2020 11:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726900AbgIDPqw (ORCPT ); Fri, 4 Sep 2020 11:46:52 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E555C061258 for ; Fri, 4 Sep 2020 08:46:44 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id c19so7778072wmd.1 for ; Fri, 04 Sep 2020 08:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+YZpX0q+mO37+kQBR4DVC/6zJd6Q2vMMFs8yeO9lM6k=; b=DHwiLfdYkiuvwGGyuQJVAWH5TI6urmfg9xYzHsNJZRaq+W2VOEzGuDZHADH8b43f72 IdWm7NgZqeHyUMOex7xd1L+sKPbyTQU6bkDGKC+laJrmoA7AkcOWL7irwhKLtGgT8Sqf F8QMnwZ2j3f3Ev1NBQFKglsSE0ukhsx0DeGQmvPfA7s4XdmrdEBZCJLsDuZdy2py60av 7ddrLxRGhrc5nQk/J7X0Rd3701tAIqugtMXJWgIrCfExr2MwqBB6KT7fKNh50zVYZgFr KhutLsEsf7K3xZSOrPpo6OUVFbEEAZGhgmuf6GDrIPY3Qah5PrJ+GtBed+JpjV2iCFmm akIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+YZpX0q+mO37+kQBR4DVC/6zJd6Q2vMMFs8yeO9lM6k=; b=EQNOgRndyADkoIvtuQcdvtAUy2NqNUR8nLyy2DII1igDzZYusN44pSatdoTJt9EMzA VCN9Di1RNFEKGpOF8E7t/1BRre98GYO+lxFCL+8XR/gngfxfHq6ZNrK2rFDWm3QjB7h5 g/Szeh8QQIo2lQ6tCLyVLqk02M0ZEA+2GvNwhCliI734Up0K217mJcERQmN6d2VlwT7t Q5OjssVEXqtu6Yjodo/Ko6w8Eko9YZIx4gVq+WFe4w+7NDM2qvrcX1nM0dqvQahqv3Fm H6FfKRquRsV/KUlVKdsonpeLAt14knsQYtWl7ZtHK+N1HxqBCfcu8mt21LgIt2ulVA8T 1FfQ== X-Gm-Message-State: AOAM532dF0uIp60aBPXt9uG+/dmoXbyPNsdGgRvwcPyaLoTztKIpLC5t tyuMGBM0hvhNGOV1NwGoIhpxKA== X-Google-Smtp-Source: ABdhPJxcZNGnXPvX9i5H6bEC8G5YKnDdSyG1Hc0LLO25M6dxNysSMjIVg6JhStAhJl/uVlArUPCUtg== X-Received: by 2002:a1c:f018:: with SMTP id a24mr7818256wmb.7.1599234403325; Fri, 04 Sep 2020 08:46:43 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:42 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 10/23] gpio: mockup: fix resource leak in error path Date: Fri, 4 Sep 2020 17:45:34 +0200 Message-Id: <20200904154547.3836-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski If the module init function fails after creating the debugs directory, it's never removed. Add proper cleanup calls to avoid this resource leak. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 78c97f7b6893..19c092f814fd 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -550,6 +550,7 @@ static int __init gpio_mockup_init(void) err = platform_driver_register(&gpio_mockup_driver); if (err) { pr_err("error registering platform driver\n"); + debugfs_remove_recursive(gpio_mockup_dbg_dir); return err; } @@ -580,6 +581,7 @@ static int __init gpio_mockup_init(void) pr_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver); gpio_mockup_unregister_pdevs(); + debugfs_remove_recursive(gpio_mockup_dbg_dir); return PTR_ERR(pdev); } From patchwork Fri Sep 4 15:45:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293548 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43513C2BB84 for ; Fri, 4 Sep 2020 15:49:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14762206E7 for ; Fri, 4 Sep 2020 15:49:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="W5igfhsJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbgIDPtg (ORCPT ); Fri, 4 Sep 2020 11:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726722AbgIDPq4 (ORCPT ); Fri, 4 Sep 2020 11:46:56 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAB46C06125E for ; Fri, 4 Sep 2020 08:46:45 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id z1so7244426wrt.3 for ; Fri, 04 Sep 2020 08:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YwQjX4axi1OAM1Fql28FiCukUb0sTZUG4ARXSE9mD5M=; b=W5igfhsJBABdupfuJeKs8ZFBc1NM6C1W6FgO9n8jRfloEFZuHfxm40QAS/h0T+mdla GxyRPVVnObFB5k5pT6P7LzWkxPcP/MWzPisHbMilF4BtXGUxAQrmAkLC2SYa0ju3givG KiDdwKVX7TmcUC0CDNP1LOrZJIVzrN6tcy2SQs/cRHBk9SBGF0OnzDbEHmReLwI8YbG5 curcoJCjYPuMzo5FLZ6jFnrkMlNHbYkNDhaAR9TyFHkFsgDKgsoKwNFbjc2NMsKI1R6k W1rLSx82J/qPz/AUX5iCXYPb5sjOPuUGwZzOSxdHC2Yc2zVz0qy+R7vGvyvw8faAPsBr sboA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YwQjX4axi1OAM1Fql28FiCukUb0sTZUG4ARXSE9mD5M=; b=uWn3ApCxN2j1ZpzgiaCLikYC4ZxUHufO3JCyKjehz5Jh7YtWHanvr/vOSWF3wIsNoZ Z1F2GEuhNKV0vj/iTRNyrX3xnaMUzn/89JvPXwTHcXYVOT63GtqVAAJYAfi7n0VBoq+Z JqSj+qKr/05sVCTZT1P1Rwrg2fKuraficCPVzpJYyf/0XqH5mQ2/9Kttc48G0IXsaJiO Fjic8V//W6yRTfrjkTdYlAtZU8r5v8akEf1ciLhBlF9NtofdunQl8Ki1lkVtvvlwZyJq Xl6FZLJSip+FFcu4MsuuMhA6dy3VBjkAP+jW5Ja5mCOxCw0o5yVL6LOJsqvc7DdV6jVG cD4Q== X-Gm-Message-State: AOAM5310OjtyElBoaJaPf/VeyqwwAzQEtpWsp5xui/qPWIp2nYZLVkLy CCcGkTZUg9NQ4XKU7yzDxIR28A== X-Google-Smtp-Source: ABdhPJzGE6+N2EUSel1NKTUZ8lWtVuw8qctovGj3qxe1uNDtwPtrgatR9NUrM3Nh2Oj68SMpkZq+Bg== X-Received: by 2002:a5d:69c2:: with SMTP id s2mr8226288wrw.389.1599234404374; Fri, 04 Sep 2020 08:46:44 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:43 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 11/23] gpio: mockup: remove the limit on number of dummy chips Date: Fri, 4 Sep 2020 17:45:35 +0200 Message-Id: <20200904154547.3836-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski As a preparation for implementing dynamically created dummy GPIO chips: drop the limit on the number of chips. Let's use a linked list to store the chip context structures. Let's rename gpio_mockup_unregister_pdevs() to gpio_mockup_unregister_devices() as we're now handling structures in which struct platform_device is embedded instead of operating on platform devices directly. Note: this does not remove the limit on the number of ranges passed as a module parameter. For now nothing changes in how the module works for user-space. This patch will however allow us to create a higher number of chips once we can do this dynamically. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 59 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 19c092f814fd..801fba6496a4 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -24,12 +25,11 @@ #undef pr_fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#define GPIO_MOCKUP_MAX_GC 10 /* * We're storing two values per chip: the GPIO base and the number * of GPIO lines. */ -#define GPIO_MOCKUP_MAX_RANGES (GPIO_MOCKUP_MAX_GC * 2) +#define GPIO_MOCKUP_MAX_RANGES (10 * 2) /* Maximum of three properties + the sentinel. */ #define GPIO_MOCKUP_MAX_PROP 4 @@ -505,27 +505,37 @@ static struct platform_driver gpio_mockup_driver = { .probe = gpio_mockup_probe, }; -static struct platform_device *gpio_mockup_pdevs[GPIO_MOCKUP_MAX_GC]; +struct gpio_mockup_device { + struct list_head list; + struct platform_device *pdev; +}; -static void gpio_mockup_unregister_pdevs(void) +static LIST_HEAD(gpio_mockup_devices); + +static void gpio_mockup_unregister_one_device(struct gpio_mockup_device *dev) { - struct platform_device *pdev; - int i; + list_del(&dev->list); + platform_device_unregister(dev->pdev); + kfree(dev); +} - for (i = 0; i < GPIO_MOCKUP_MAX_GC; i++) { - pdev = gpio_mockup_pdevs[i]; +static void gpio_mockup_unregister_devices(void) +{ + struct gpio_mockup_device *mockup_dev; + struct list_head *curr, *next; - if (pdev) - platform_device_unregister(pdev); + list_for_each_safe(curr, next, &gpio_mockup_devices) { + mockup_dev = list_entry(curr, struct gpio_mockup_device, list); + gpio_mockup_unregister_one_device(mockup_dev); } } static int __init gpio_mockup_init(void) { struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + struct gpio_mockup_device *mockup_dev; int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; - struct platform_device *pdev; u16 ngpio; if ((gpio_mockup_num_ranges < 2) || @@ -576,26 +586,37 @@ static int __init gpio_mockup_init(void) pdevinfo.id = i; pdevinfo.properties = properties; - pdev = platform_device_register_full(&pdevinfo); - if (IS_ERR(pdev)) { + mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); + if (!mockup_dev) { + err = -ENOMEM; + goto err_out; + } + + mockup_dev->pdev = platform_device_register_full(&pdevinfo); + if (IS_ERR(mockup_dev->pdev)) { pr_err("error registering device"); - platform_driver_unregister(&gpio_mockup_driver); - gpio_mockup_unregister_pdevs(); - debugfs_remove_recursive(gpio_mockup_dbg_dir); - return PTR_ERR(pdev); + kfree(mockup_dev); + err = PTR_ERR(mockup_dev->pdev); + goto err_out; } - gpio_mockup_pdevs[i] = pdev; + list_add(&mockup_dev->list, &gpio_mockup_devices); } return 0; + +err_out: + platform_driver_unregister(&gpio_mockup_driver); + gpio_mockup_unregister_devices(); + debugfs_remove_recursive(gpio_mockup_dbg_dir); + return err; } static void __exit gpio_mockup_exit(void) { debugfs_remove_recursive(gpio_mockup_dbg_dir); platform_driver_unregister(&gpio_mockup_driver); - gpio_mockup_unregister_pdevs(); + gpio_mockup_unregister_devices(); } module_init(gpio_mockup_init); From patchwork Fri Sep 4 15:45:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02FAEC433E2 for ; Fri, 4 Sep 2020 15:49:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDA232074D for ; Fri, 4 Sep 2020 15:49:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="DWSFeeLR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbgIDPtf (ORCPT ); Fri, 4 Sep 2020 11:49:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726941AbgIDPq5 (ORCPT ); Fri, 4 Sep 2020 11:46:57 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFCF7C061260 for ; Fri, 4 Sep 2020 08:46:46 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id e16so7227471wrm.2 for ; Fri, 04 Sep 2020 08:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/FOPTskD02+rqmTy1Q+lvepWRalQafDGjAwi3K9HfYU=; b=DWSFeeLRu39HrwTsgIJnFObS4Eo0vIUxkcPBLAQ8iMkew4JxxJi2HeGJEwHFlAzsSC V4nymy+PcpCDVaRs1xvaygnoO+ldD8YU2XK9eLt5FRlZOI3wYRcprZQ7u0nHSojZmi94 J6tKrqYyKczLhXpI/uxNrYUoFv129bNqR7YAXvmIq+RP/NU7cK0nUX6Fgw98DTzmsGkN OUBuerym7ms3eO6VilqR+cBH+FVtnJZ3cGCpmkzMc3e+F/SDdlMcOPxZi7D0wzC1gYPs CrL5Mb1Bqwd4ozdqBulR2kAIQQ2V2cv5mN44+Kac1+HItigj9IaT5KWXHVJcsq/QfAOI pTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/FOPTskD02+rqmTy1Q+lvepWRalQafDGjAwi3K9HfYU=; b=XGBFaHxldrbxULA9A4rJrvJxKy3ZOnwijVHlxYhz9yN3KTRwIDGAA2QEn13ZwQ7EJG 3cXv0I209KVz57D98ZLzXceK3t9sicA4YBTHsAnhOuP5/U5sPsE11gRM1OhHnBDOq8Sb 4x9ZNhySntlczBnIeurO8IwbM2z3IaL1Ax4/7MG41Ks5tA6uXVnUX2j2R+I5zQfxyvhB d8W9eOf2ov5Gpz8KmiaglkPCHRhZtGq4yq0ZAkyhXQDmZwz+vwr6VWt76UzXg0yDkdE1 G0Tnqi8v0oBvZEQE0NrcCJSBKfRGQOx4jUgbzLoXDQxlspUnHZmcOTK4TMMaW1fiSvYP LG7g== X-Gm-Message-State: AOAM533SpzPW93McsTID/4ZQzv5rtrOf+T8JX0KWZ08vpDTf1bLz1PbD AxncOig3FJqoQjqKggvxQ3PBqQ== X-Google-Smtp-Source: ABdhPJw/DYVsfbaGxg5IdpYA3yk8QnzF9jmg3mpJzGx7H7H6XBFu4ZqlmzQ4gBrGlTt8uzkbc4SHKQ== X-Received: by 2002:a5d:61c2:: with SMTP id q2mr8972511wrv.25.1599234405459; Fri, 04 Sep 2020 08:46:45 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:45 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 12/23] gpio: mockup: define a constant for chip label size Date: Fri, 4 Sep 2020 17:45:36 +0200 Message-Id: <20200904154547.3836-13-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We'll be using this value in many places in this driver soon so define a constant to avoid using magic values. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 801fba6496a4..e8a19a28ed13 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -32,6 +32,7 @@ #define GPIO_MOCKUP_MAX_RANGES (10 * 2) /* Maximum of three properties + the sentinel. */ #define GPIO_MOCKUP_MAX_PROP 4 +#define GPIO_MOCKUP_LABEL_SIZE 32 /* * struct gpio_pin_status - structure describing a GPIO status From patchwork Fri Sep 4 15:45:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF166C433E2 for ; Fri, 4 Sep 2020 15:49:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2224206E7 for ; Fri, 4 Sep 2020 15:49:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="BmXQtsk/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbgIDPtA (ORCPT ); Fri, 4 Sep 2020 11:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgIDPrF (ORCPT ); Fri, 4 Sep 2020 11:47:05 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1603AC061263 for ; Fri, 4 Sep 2020 08:46:48 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id z1so7244543wrt.3 for ; Fri, 04 Sep 2020 08:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BFcXvT/mBks59Nbsnk6JiwVK+tMFpXxn+PeH1sXkPcs=; b=BmXQtsk/lNSK1NhzOpnVddLfxGsT8P0H9ClEgPxJpE8hkw4Ul/zwqczzS70BALZS8n vUW5AfqeO8+ikYrSu/35Ybp7/e/CjukugK16RO2+ZRrxjWbQ+6bTdhe0MJedMJxCczcx 87b+KiHycu6GRF+fkYgMryzrI/mI+X58xNIT8iWekGrHZrpJ5hLX9OnjMr4cj4t3eUxX wSZUpjgrh5l+Uhnbt4iDGr0J5la/xLfUcYhiu+0lj8jj61KujeIQqqZRmaS/rdRnkhUi 77/rijdpdD7LjPcI3LBVuEcAx0/sSZUJi07rSLSpvBU48UQsIdpK7sjEORTMAhaUC1ZA 29Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFcXvT/mBks59Nbsnk6JiwVK+tMFpXxn+PeH1sXkPcs=; b=FNq3KRrdGUaCaJzgVR+QBB2BGSaF3lpXqq1vgmNZInoNmIgw/a02bOzGBAlXzje2ve y4YI9Cj0omKEGjWvOdYNBL9dLJQPb7eAMZMrpitxcAZUICMGL3fDKY1oiizguVbvBtTZ TT4WA5reN5yj9AsNr+EBT95x6L2FDqdBapuACypk5cpnKYYAoFtGW9z8s8IKLJqIwKBz UwLkUojUg80y+cFxIrT6jTrfX+oYd5pbVw90N7YdFmDGPD0L4U4APTIhHH5v0QifiSEb ZlD3/qwCjcsW3MF4uGdDI5SAyQdCif+qOxe7faew268vZBakCfcTqa1/rt7w4LXqbcnV 9CAA== X-Gm-Message-State: AOAM531wQUbWYM4pBYVs6S9JtnjjPBcg53Eo0e8qiUkyqpeGJiGNCAtC wDeoApMl3zJJNMkWtSLxAGKzeQ== X-Google-Smtp-Source: ABdhPJxqVtqimUn/AOziI4okr5k6W+CeptUTEmSCRZWc/9G1FoORHyIyNXxgkGRVZJUKwoP2mlGlAw== X-Received: by 2002:adf:9ed4:: with SMTP id b20mr8360307wrf.206.1599234406494; Fri, 04 Sep 2020 08:46:46 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:46 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 13/23] gpio: mockup: pass the chip label as device property Date: Fri, 4 Sep 2020 17:45:37 +0200 Message-Id: <20200904154547.3836-14-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski While we do check the "chip-name" property in probe(), we never actually use it. Let's pass the chip label to the driver using device properties as we'll want to allow users to define their own once dynamically created chips are supported. The property is renamed to "chip-label" to not cause any confusion with the actual chip name which is of the form: "gpiochipX". If the "chip-label" property is missing, let's do what most devices in drivers/gpio/ do and use dev_name(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index e8a19a28ed13..ce83f1df1933 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -433,21 +433,14 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (rv) return rv; - rv = device_property_read_string(dev, "chip-name", &name); + rv = device_property_read_string(dev, "chip-label", &name); if (rv) - name = NULL; + name = dev_name(dev); chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - if (!name) { - name = devm_kasprintf(dev, GFP_KERNEL, - "%s-%c", pdev->name, pdev->id + 'A'); - if (!name) - return -ENOMEM; - } - mutex_init(&chip->lock); gc = &chip->gc; @@ -534,6 +527,7 @@ static void gpio_mockup_unregister_devices(void) static int __init gpio_mockup_init(void) { struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + char chip_label[GPIO_MOCKUP_LABEL_SIZE]; struct gpio_mockup_device *mockup_dev; int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; @@ -570,6 +564,11 @@ static int __init gpio_mockup_init(void) memset(&pdevinfo, 0, sizeof(pdevinfo)); prop = 0; + snprintf(chip_label, sizeof(chip_label), + "gpio-mockup-%c", i + 'A'); + properties[prop++] = PROPERTY_ENTRY_STRING("chip-label", + chip_label); + base = gpio_mockup_range_base(i); if (base >= 0) properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", From patchwork Fri Sep 4 15:45:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 388C0C433E2 for ; Fri, 4 Sep 2020 15:47:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A71020770 for ; Fri, 4 Sep 2020 15:47:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="kAyUu5S4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbgIDPrb (ORCPT ); Fri, 4 Sep 2020 11:47:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbgIDPrG (ORCPT ); Fri, 4 Sep 2020 11:47:06 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25294C0619C8 for ; Fri, 4 Sep 2020 08:46:49 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id x14so7168887wrl.12 for ; Fri, 04 Sep 2020 08:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PIlCfY52QBAW0QciXTZrA2LEScpvUt4DRPmsiC/uEZE=; b=kAyUu5S4J7u5PlMhXeERMKYijow5Uvf1vPja4sMCKpKoqg1hWx6dKZnZ/RK1/SPZL0 ShdgcMAKyIlUyaaawlpACApsdJEU9Md54uEqjYZVNnziiwX3GSZK7HTG7sRNd+i38HTH ZbL4kHdZ4gdnIFby9G8JkznCdrrjXsLk97q+STs6HDZ+JMgQJvLpIFZL/wFag4h3uo/A 9aHWpE6j5E9xny7wjYFiPcwiZX4Bpo4aaPbd6AIcpdti97HzajyZMSE0d4pMOPAFvXW4 yDiILL2k08sdQyEtXASc2pmHHINCz0ouQpMf3SaQvWo3GU1CGb4HNcpCvpcnduXDhPUp umng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PIlCfY52QBAW0QciXTZrA2LEScpvUt4DRPmsiC/uEZE=; b=LFvYt4aFV4Yi3cu/TtwHi3QAedE1gVUjpI8Z8A5kGBh9nkzSJ7/Tzrom3zsuKij5xu L8FoMGSOQ/RDyXXDlkD3SIAoKAdvb9QRWSOhgemJ/N1zqkYpKvTuJCUN7xoW8p9RwP+r cjore2fEK/VMn1XbbsSFOTctxg9SfnjkistOQ+YWdk2wguVBXQxAj+DD1Q/NhW4j5y4b T21XqZMhi2Vd+PipdJcbkiq7Mf3+WWhO7IwsHjzTQFealUa93FobVv9cWg9uSeDVObUc fpiEYMTr0iUHADqcKHEwV/warLNTCR+gdMgywN4mo7DdRLfAmv+/G4pwmtoh/E8WTEfx 9+gw== X-Gm-Message-State: AOAM530Ds9g4P5GA93ddxx4AymKvsi5Um0aw8Qmcunx/TV1llTw0t3BE sN3bGBXFFpQm7TbqSCji0iLV+jyW1zxGcQ== X-Google-Smtp-Source: ABdhPJzViJgklFpsKr9s/TzyGNKVym3EXiIR7NoW1xlL8zZyDomQRh8eo9NSw71P/nbQ3slOTg815w== X-Received: by 2002:adf:eecb:: with SMTP id a11mr8386100wrp.356.1599234407810; Fri, 04 Sep 2020 08:46:47 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:47 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 14/23] gpio: mockup: use the generic 'gpio-line-names' property Date: Fri, 4 Sep 2020 17:45:38 +0200 Message-Id: <20200904154547.3836-15-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski GPIO line names are currently created by the driver from the chip label. We'll want to support custom formats for line names (for instance: to name all lines the same) for user-space tests so create them in the module init function and pass them to the driver using the standard 'gpio-line-names' property. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 70 +++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index ce83f1df1933..96976ba66598 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "gpiolib.h" @@ -378,29 +379,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev, return; } -static int gpio_mockup_name_lines(struct device *dev, - struct gpio_mockup_chip *chip) -{ - struct gpio_chip *gc = &chip->gc; - char **names; - int i; - - names = devm_kcalloc(dev, gc->ngpio, sizeof(char *), GFP_KERNEL); - if (!names) - return -ENOMEM; - - for (i = 0; i < gc->ngpio; i++) { - names[i] = devm_kasprintf(dev, GFP_KERNEL, - "%s-%d", gc->label, i); - if (!names[i]) - return -ENOMEM; - } - - gc->names = (const char *const *)names; - - return 0; -} - static void gpio_mockup_dispose_mappings(void *data) { struct gpio_mockup_chip *chip = data; @@ -468,12 +446,6 @@ static int gpio_mockup_probe(struct platform_device *pdev) for (i = 0; i < gc->ngpio; i++) chip->lines[i].dir = GPIO_LINE_DIRECTION_IN; - if (device_property_read_bool(dev, "named-gpio-lines")) { - rv = gpio_mockup_name_lines(dev, chip); - if (rv) - return rv; - } - chip->irq_sim_domain = devm_irq_domain_create_sim(dev, NULL, gc->ngpio); if (IS_ERR(chip->irq_sim_domain)) @@ -524,6 +496,27 @@ static void gpio_mockup_unregister_devices(void) } } +static __init char **gpio_mockup_make_line_names(const char *label, + unsigned int num_lines) +{ + unsigned int i; + char **names; + + names = kcalloc(num_lines + 1, sizeof(char *), GFP_KERNEL); + if (!names) + return NULL; + + for (i = 0; i < num_lines; i++) { + names[i] = kasprintf(GFP_KERNEL, "%s-%u", label, i); + if (!names[i]) { + kfree_strarray(names, i); + return NULL; + } + } + + return names; +} + static int __init gpio_mockup_init(void) { struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; @@ -531,6 +524,7 @@ static int __init gpio_mockup_init(void) struct gpio_mockup_device *mockup_dev; int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; + char **line_names; u16 ngpio; if ((gpio_mockup_num_ranges < 2) || @@ -563,6 +557,7 @@ static int __init gpio_mockup_init(void) memset(properties, 0, sizeof(properties)); memset(&pdevinfo, 0, sizeof(pdevinfo)); prop = 0; + line_names = NULL; snprintf(chip_label, sizeof(chip_label), "gpio-mockup-%c", i + 'A'); @@ -578,9 +573,18 @@ static int __init gpio_mockup_init(void) : gpio_mockup_range_ngpio(i) - base; properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); - if (gpio_mockup_named_lines) - properties[prop++] = PROPERTY_ENTRY_BOOL( - "named-gpio-lines"); + if (gpio_mockup_named_lines) { + line_names = gpio_mockup_make_line_names(chip_label, + ngpio); + if (!line_names) { + err = -ENOMEM; + goto err_out; + } + + properties[prop++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( + "gpio-line-names", + line_names, ngpio); + } pdevinfo.name = "gpio-mockup"; pdevinfo.id = i; @@ -588,11 +592,13 @@ static int __init gpio_mockup_init(void) mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); if (!mockup_dev) { + kfree_strarray(line_names, ngpio); err = -ENOMEM; goto err_out; } mockup_dev->pdev = platform_device_register_full(&pdevinfo); + kfree_strarray(line_names, ngpio); if (IS_ERR(mockup_dev->pdev)) { pr_err("error registering device"); kfree(mockup_dev); From patchwork Fri Sep 4 15:45:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF87C43461 for ; Fri, 4 Sep 2020 15:47:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0B1D2074D for ; Fri, 4 Sep 2020 15:47:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="RrJg++r4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbgIDPr3 (ORCPT ); Fri, 4 Sep 2020 11:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbgIDPrK (ORCPT ); Fri, 4 Sep 2020 11:47:10 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47202C0619C9 for ; Fri, 4 Sep 2020 08:46:50 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id v4so6495072wmj.5 for ; Fri, 04 Sep 2020 08:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=RrJg++r4d2sHRcNO3FHpdXscTwZC2S1z6mTa4gXaNzK1juMkhcaKgspDfWpLneE8ew tHNr9Istt1yOiqL4bpXNH0QTSrkeP/0+Sm0lWzrBSnNzA8Ipt1xnsSsJLqMRrfXfgPdL ByP89m21osn8Id9E+Wyld2kuBz/37527FByOq0o3H71SYeQv7QKjZwhPK8OLk7ZZ1+ln E6BINQjI5QOfdhbly6Mg+N5QR3sey2pYn/ItHPnMoSmlC2iJkFNPzpvM5K7zwL6RYcjj gqdPy1/YiAdUWwlNY/7Qrbz14NPumdr00luxiTymMknoqxMZo8w0KTk1eN2juH0xrC0s 99hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=e8kMoiG3wteOHILZrurR9LHpU4M5axlL/hij/4XDMJPphb8iLeKCtNzHhfcWgaFYUr gPeqZAfnXa23oCPoQZgCnAEGVXn4eNElJCrlil70ihc7Li6okqh/Z7udI+Dg9XKphHH/ JuI/xrfe+ZXZ04LQi53ccun8MV8V8OVD4a5zq+S0sDGWE8izwc4HiAbvnznluYGDsAbh OEkdkEVXr7pcexcVXmP9zx+phvSeONoYGQ5RsHvdok4wSirDVUA9GQFyGJWF/QhdGEd9 rdCNOR0ErnuapR01VE9kU0ABAvuKFlpQi9ssXYylfO8I2tSx5eXTr8SN+dXBSUnrvHrD 2/vA== X-Gm-Message-State: AOAM532D++CYJpFBeMygXhjtFjPdPbZkJKKO0/VBvR9Djv9HcITV8bW8 XIh1CuxvMWlpXTnTFrvfPspJOA== X-Google-Smtp-Source: ABdhPJxbT8FJfkefQNct8r1fnLwo5GotdwatKA46ZNCj44Ghck2jGtAw2L6A6tWWrFk0Rc/2fDW1Jg== X-Received: by 2002:a7b:c056:: with SMTP id u22mr8253559wmc.188.1599234408930; Fri, 04 Sep 2020 08:46:48 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:48 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 15/23] gpio: mockup: use dynamic device IDs Date: Fri, 4 Sep 2020 17:45:39 +0200 Message-Id: <20200904154547.3836-16-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We're currently creating chips at module init time only so using a static index for dummy devices is fine. We want to support dynamically created chips however so we need to switch to dynamic device IDs. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 96976ba66598..995e37fef9c5 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,8 @@ module_param_named(gpio_mockup_named_lines, static struct dentry *gpio_mockup_dbg_dir; +static DEFINE_IDA(gpio_mockup_ida); + static int gpio_mockup_range_base(unsigned int index) { return gpio_mockup_ranges[index * 2]; @@ -480,8 +483,12 @@ static LIST_HEAD(gpio_mockup_devices); static void gpio_mockup_unregister_one_device(struct gpio_mockup_device *dev) { + int id; + list_del(&dev->list); + id = dev->pdev->id; platform_device_unregister(dev->pdev); + ida_free(&gpio_mockup_ida, id); kfree(dev); } @@ -587,12 +594,19 @@ static int __init gpio_mockup_init(void) } pdevinfo.name = "gpio-mockup"; - pdevinfo.id = i; pdevinfo.properties = properties; + pdevinfo.id = ida_alloc(&gpio_mockup_ida, GFP_KERNEL); + if (pdevinfo.id < 0) { + kfree_strarray(line_names, ngpio); + err = pdevinfo.id; + goto err_out; + } + mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); if (!mockup_dev) { kfree_strarray(line_names, ngpio); + ida_free(&gpio_mockup_ida, pdevinfo.id); err = -ENOMEM; goto err_out; } @@ -601,6 +615,7 @@ static int __init gpio_mockup_init(void) kfree_strarray(line_names, ngpio); if (IS_ERR(mockup_dev->pdev)) { pr_err("error registering device"); + ida_free(&gpio_mockup_ida, pdevinfo.id); kfree(mockup_dev); err = PTR_ERR(mockup_dev->pdev); goto err_out; From patchwork Fri Sep 4 15:45:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9CC0C433E2 for ; Fri, 4 Sep 2020 15:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82F3220770 for ; Fri, 4 Sep 2020 15:47:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="XDPUd88f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgIDPr0 (ORCPT ); Fri, 4 Sep 2020 11:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727041AbgIDPrK (ORCPT ); Fri, 4 Sep 2020 11:47:10 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B799C0619CC for ; Fri, 4 Sep 2020 08:46:51 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id w5so7207810wrp.8 for ; Fri, 04 Sep 2020 08:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WyjmVjhpnGXquX37FrO09soycBHp0c7Voe0C2epUSlY=; b=XDPUd88fmww602TEmlb1AFnsBF7aMaMMz01k+ffuXxprMalJqR6eyMNzsTRxZEfwAA 1ox2ek9rTQm5/aptSk9xqkCU96Ac7wp2wnDnezd49Eea/HzZ6JRt7B+Ri7EHpSHOzlLu PtyNqnUehKdFIFiSa9SD0TYYewXOLoRs9KBte+t/qX8FbK+8z8uw1BTgZm99d6R4VQte gqx2WRLW9Legr8TXPHfiCtaw9kZGji9PlCnFvCOIgEZFC4RS/BiVgpoO1N5vfbTkd+W6 WGYVVm/uZuL0eyDZWC0EXmMnvzv0oNbN4YJRPr1LSrOUlwzCrgHx/by+VM8VzJXFvA9Z wYng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WyjmVjhpnGXquX37FrO09soycBHp0c7Voe0C2epUSlY=; b=CxH8tUOMlwWPIvC7GDH+V73BbmwcS6c9AtLSOL3sG1TcwmGYR2zru377GdCHtZxbVj pykwahUr+ECSAPilmgJDrtXuoE5iFzopvCVHIQJ0jk0Nd7a/icfx0cLISIQXrcunBHKk I4usW7pFGcBvHQRWX35ofZ7RaOLbm2qJFsj9RkIhfyJUsTjFVRlsg/Xn3YZeKkT7tkXW 511U/NZ7H3T7hYy3LbfrU6VKaHW6PIy2sVDOTlMsdYFOiZbqFuXhiFI8bE3hBKOJ9/Ye N7R4AnFYxg0fDeLTX7b6DX4ozM1XfMucNjYmD9OnQR9dKjQiBHL2ZcR38Ec2PqyrkVo4 l06w== X-Gm-Message-State: AOAM530NqH0vEDZbF1CIFuJI1Ko0+TAk+2YZb1Hn13ZEGZul5NGcTj55 KMmmoE2RIGJtm2dwmnSl16Y+9g== X-Google-Smtp-Source: ABdhPJwRZP17TzqitYdLKGr/J+BkXLEmQHMeFZF4HdwgXX1c+JFwPa7Dg8g7z+8i2CrZFVQjF1jEtQ== X-Received: by 2002:adf:cc8c:: with SMTP id p12mr8628829wrj.92.1599234410024; Fri, 04 Sep 2020 08:46:50 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:49 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 16/23] gpio: mockup: refactor the module init function Date: Fri, 4 Sep 2020 17:45:40 +0200 Message-Id: <20200904154547.3836-17-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This is in preparation for dynamically created chips. Let's split out the code that can be reused when creating chips at run-time. Let's also move the code preparing the device properties into a separate routine. This has the advantage of simplifying the error handling. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 165 ++++++++++++++++++++----------------- 1 file changed, 90 insertions(+), 75 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 995e37fef9c5..eb94ddac5fee 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -524,16 +524,78 @@ static __init char **gpio_mockup_make_line_names(const char *label, return names; } -static int __init gpio_mockup_init(void) +static int __init gpio_mockup_register_device(struct property_entry *properties) { - struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; - char chip_label[GPIO_MOCKUP_LABEL_SIZE]; struct gpio_mockup_device *mockup_dev; - int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; - char **line_names; + + memset(&pdevinfo, 0, sizeof(pdevinfo)); + + mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); + if (!mockup_dev) + return -ENOMEM; + + pdevinfo.name = "gpio-mockup"; + pdevinfo.properties = properties; + + pdevinfo.id = ida_alloc(&gpio_mockup_ida, GFP_KERNEL); + if (pdevinfo.id < 0) { + kfree(mockup_dev); + return pdevinfo.id; + } + + mockup_dev->pdev = platform_device_register_full(&pdevinfo); + if (IS_ERR(mockup_dev->pdev)) { + ida_free(&gpio_mockup_ida, pdevinfo.id); + kfree(mockup_dev); + return PTR_ERR(mockup_dev->pdev); + } + + list_add(&mockup_dev->list, &gpio_mockup_devices); + + return 0; +} + +static int __init gpio_mockup_register_one_chip_from_params(int idx) +{ + char chip_label[GPIO_MOCKUP_LABEL_SIZE], **line_names = NULL; + struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + int prop = 0, base, ret; u16 ngpio; + memset(properties, 0, sizeof(properties)); + + snprintf(chip_label, sizeof(chip_label), "gpio-mockup-%c", idx + 'A'); + properties[prop++] = PROPERTY_ENTRY_STRING("chip-label", + chip_label); + + base = gpio_mockup_range_base(idx); + if (base >= 0) + properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", + base); + + ngpio = base < 0 ? gpio_mockup_range_ngpio(idx) + : gpio_mockup_range_ngpio(idx) - base; + properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); + + if (gpio_mockup_named_lines) { + line_names = gpio_mockup_make_line_names(chip_label, ngpio); + if (!line_names) + return -ENOMEM; + + properties[prop++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( + "gpio-line-names", line_names, ngpio); + } + + ret = gpio_mockup_register_device(properties); + kfree_strarray(line_names, ngpio); + return ret; +} + +static int __init gpio_mockup_register_chips_from_params(void) +{ + int num_chips, i, ret; + if ((gpio_mockup_num_ranges < 2) || (gpio_mockup_num_ranges % 2) || (gpio_mockup_num_ranges > GPIO_MOCKUP_MAX_RANGES)) @@ -551,86 +613,39 @@ static int __init gpio_mockup_init(void) return -EINVAL; } - gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); - - err = platform_driver_register(&gpio_mockup_driver); - if (err) { - pr_err("error registering platform driver\n"); - debugfs_remove_recursive(gpio_mockup_dbg_dir); - return err; - } - for (i = 0; i < num_chips; i++) { - memset(properties, 0, sizeof(properties)); - memset(&pdevinfo, 0, sizeof(pdevinfo)); - prop = 0; - line_names = NULL; - - snprintf(chip_label, sizeof(chip_label), - "gpio-mockup-%c", i + 'A'); - properties[prop++] = PROPERTY_ENTRY_STRING("chip-label", - chip_label); - - base = gpio_mockup_range_base(i); - if (base >= 0) - properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", - base); - - ngpio = base < 0 ? gpio_mockup_range_ngpio(i) - : gpio_mockup_range_ngpio(i) - base; - properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); - - if (gpio_mockup_named_lines) { - line_names = gpio_mockup_make_line_names(chip_label, - ngpio); - if (!line_names) { - err = -ENOMEM; - goto err_out; - } - - properties[prop++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( - "gpio-line-names", - line_names, ngpio); + ret = gpio_mockup_register_one_chip_from_params(i); + if (ret) { + gpio_mockup_unregister_devices(); + return ret; } + } - pdevinfo.name = "gpio-mockup"; - pdevinfo.properties = properties; + return 0; +} - pdevinfo.id = ida_alloc(&gpio_mockup_ida, GFP_KERNEL); - if (pdevinfo.id < 0) { - kfree_strarray(line_names, ngpio); - err = pdevinfo.id; - goto err_out; - } +static int __init gpio_mockup_init(void) +{ + int ret; - mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); - if (!mockup_dev) { - kfree_strarray(line_names, ngpio); - ida_free(&gpio_mockup_ida, pdevinfo.id); - err = -ENOMEM; - goto err_out; - } + gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); - mockup_dev->pdev = platform_device_register_full(&pdevinfo); - kfree_strarray(line_names, ngpio); - if (IS_ERR(mockup_dev->pdev)) { - pr_err("error registering device"); - ida_free(&gpio_mockup_ida, pdevinfo.id); - kfree(mockup_dev); - err = PTR_ERR(mockup_dev->pdev); - goto err_out; - } + ret = platform_driver_register(&gpio_mockup_driver); + if (ret) { + pr_err("error registering platform driver\n"); + debugfs_remove_recursive(gpio_mockup_dbg_dir); + return ret; + } - list_add(&mockup_dev->list, &gpio_mockup_devices); + ret = gpio_mockup_register_chips_from_params(); + if (ret) { + pr_err("error registering device"); + debugfs_remove_recursive(gpio_mockup_dbg_dir); + platform_driver_unregister(&gpio_mockup_driver); + return ret; } return 0; - -err_out: - platform_driver_unregister(&gpio_mockup_driver); - gpio_mockup_unregister_devices(); - debugfs_remove_recursive(gpio_mockup_dbg_dir); - return err; } static void __exit gpio_mockup_exit(void) From patchwork Fri Sep 4 15:45:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98564C2D0A7 for ; Fri, 4 Sep 2020 15:48:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70B6720772 for ; Fri, 4 Sep 2020 15:48:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="DVTGoZ9/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726441AbgIDPsj (ORCPT ); Fri, 4 Sep 2020 11:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbgIDPrM (ORCPT ); Fri, 4 Sep 2020 11:47:12 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 808D5C061265 for ; Fri, 4 Sep 2020 08:46:52 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id a9so6523351wmm.2 for ; Fri, 04 Sep 2020 08:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fqNzmK12nk8xdy0PepsxrcJPk3kdW/zWD0as5Np++IA=; b=DVTGoZ9/IcG51yNk5wt6AIfbpjjgClmzQ/sB+JyYMzA1scB60f3klAUXpqyjXur7cU ceecqoA7dym9XyBOoc0KJdnwhnHizDo3L+PRneh2SVhNd3RWGVlxNWp4fb0qHEB16MUY UZZ981+PbDw/shKPxNe44u2DhQhUUonkKpnwrrBH3up1tBSsARpNhbqB1KQ0qdn4YGQv XVsC4P/nVvaAO/z3RO/B93144s06ZfVD1aZ6utVH8mAT1UxThVC9fl3XLywTHrk2F3Pb WRQ2oVF2yJ8i9/JXYBH6uosFBiLxHCTqBSgossd5IqX6hMJ4D3zpFtL5ugLmJe9Q8xrE 2QvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fqNzmK12nk8xdy0PepsxrcJPk3kdW/zWD0as5Np++IA=; b=Hcc2/HdmPy6o3NOEn+ue9lj/X75NgMSFp+qTVx9sGsBJ0Wt6svo2Sfl0vMhY/rph+g mJS6IwMMfsa/lMRy4gO3pbgDsK9Z/A7yP9CWnYVSVgn3uamMvp2D1jC565ts5e6jIAR/ 4J8ub/9CpyFzwDJKsVLkerQZSkFK2z8fL0LlNXVX3KoKo/9fyNG6m+vJ5xXOw668hRBU 2qp/x3ybiPxoC/QVTz1Yav8NKxHDsvVL72f+XxEGHujc805I/k7tmLRFh22Uf+WcRnM4 HQa/zJee9LGzYUg68X3TaH6E4w0bxGSQ/tsQoc1zxTyQ+tKHgLp/48snmLTJIp1JgHXf IFVw== X-Gm-Message-State: AOAM5329uHJ75Cb1SL2tZ6GOxZx4VbmG5Z7iw9r8SwgH+gLbbpE8/BKt rW01Hk1mIkFqG5jLOC9gy/jupA== X-Google-Smtp-Source: ABdhPJxttLkSDVoDRXzlpcTjTpigx62xH5t4We6CkvNvgq/knQn3QcMipzht5x/6b+Rm8h9SpKU0dQ== X-Received: by 2002:a1c:f402:: with SMTP id z2mr7915668wma.87.1599234411169; Fri, 04 Sep 2020 08:46:51 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:50 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 17/23] gpio: mockup: rename and move around debugfs callbacks Date: Fri, 4 Sep 2020 17:45:41 +0200 Message-Id: <20200904154547.3836-18-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We will soon introduce new debugfs attributes for dynamically created chips. We'll reuse the gpio_mockup_debugfs_open() helper for them but the relevant write callbacks will of course be different. Let's rename gpio_mockup_debugfs_write() to gpio_mockup_debugfs_pull_write() to avoid confusion with new write callbacks and move gpio_mockup_debugfs_open() higher up in the code to separate it from the pull/value attribute which will no longer be the only user. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index eb94ddac5fee..29fbf007ab26 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -262,9 +262,14 @@ static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset) __gpio_mockup_set(chip, offset, chip->lines[offset].pull); } -static ssize_t gpio_mockup_debugfs_read(struct file *file, - char __user *usr_buf, - size_t size, loff_t *ppos) +static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, NULL, inode->i_private); +} + +static ssize_t gpio_mockup_debugfs_value_read(struct file *file, + char __user *usr_buf, + size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; struct gpio_mockup_chip *chip; @@ -287,9 +292,9 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file, return simple_read_from_buffer(usr_buf, size, ppos, buf, cnt); } -static ssize_t gpio_mockup_debugfs_write(struct file *file, - const char __user *usr_buf, - size_t size, loff_t *ppos) +static ssize_t gpio_mockup_debugfs_pull_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; int rv, val; @@ -313,11 +318,6 @@ static ssize_t gpio_mockup_debugfs_write(struct file *file, return size; } -static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) -{ - return single_open(file, NULL, inode->i_private); -} - /* * Each mockup chip is represented by a directory named after the chip's device * name under /sys/kernel/debug/gpio-mockup/. Each line is represented by @@ -342,8 +342,8 @@ static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) static const struct file_operations gpio_mockup_debugfs_ops = { .owner = THIS_MODULE, .open = gpio_mockup_debugfs_open, - .read = gpio_mockup_debugfs_read, - .write = gpio_mockup_debugfs_write, + .read = gpio_mockup_debugfs_value_read, + .write = gpio_mockup_debugfs_pull_write, .llseek = no_llseek, .release = single_release, }; From patchwork Fri Sep 4 15:45:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04622C2BB84 for ; Fri, 4 Sep 2020 15:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB8742074D for ; Fri, 4 Sep 2020 15:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="HCiTFjtP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbgIDPrl (ORCPT ); Fri, 4 Sep 2020 11:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbgIDPrP (ORCPT ); Fri, 4 Sep 2020 11:47:15 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AD78C0619CF for ; Fri, 4 Sep 2020 08:46:53 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id q9so6498761wmj.2 for ; Fri, 04 Sep 2020 08:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=df1vNsIBtzMz3XaBeJ8Q2j/QYEAOiM6PlNqlmnkxGzE=; b=HCiTFjtPaoDptruE52sxg0PIrYN0fw4LxlnqDp18boSboMkoVyxeNy/lnftW/3B1VN St/clTzUXKDOHSQA056HKj7PuXF/g2RLwdgdIjLG4XG1olSqBHJaH7BtKBIH3CrBfDLT imWJKTRh52/m5EJlYTrb+CO3+4IWSd8rNuEeFqLMp3U8My502joushgdUehq4pMigYFC AOP5Kf5CVb4VXX4Kw1t81IoEzl31OBdvYQYB7fmnrbnAvsvNNTf6HUl/3korYBFLK59T FU4pltRDJrrAPTGx79VWKrY+5RNLNCdo1SqBKIuIwpwB5jdvB/+p+j5Z49o1MfvnBpS9 J0Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=df1vNsIBtzMz3XaBeJ8Q2j/QYEAOiM6PlNqlmnkxGzE=; b=imEMK7kdqiYKOwHJ1kMdszrm/b2eu7dH3t84dn6x9jrnMmBY8v7DE1jlmmLEJIBk6z nHBB9mM7BkMfpnlekZPn9fdcKguOrZEF2k+d8IIrIU9kus5OUiCSKlaps52r9zrIn2fj gOx1lCeSjPoMLFQRRNC8Dlx30LRi8JgNW491aOoXDpcbe+XTlXMQ85MnKw+MkIIePFyp VCUEyY1YKnnT7FoaPkix1P6TSqDnw7TKEjzdz6EPb5N2mYVxULEphdP1jcLcEScYl+G3 8EPHwEgAxLdyyAD4Xi3HHsT7o79PmagEedGgz72NTwu8LqLvCmgd6rv1lYV1PtOenN9J 9NLw== X-Gm-Message-State: AOAM5333HOYGZ9Om4TJEWnCOTGvR3b1eUgoFAdH+OyqtCfZOO/VK1sqN VF89e6B9f4iJ4DHyv1P2QmlcEA== X-Google-Smtp-Source: ABdhPJwDF5h6MoCuJSLVRYN6V3SUPCfPtMhU02JacL8LUejcHJkWG2C2FBuxEHO5GQ0TLz1u4jgkzg== X-Received: by 2002:a05:600c:2146:: with SMTP id v6mr8004415wml.159.1599234412250; Fri, 04 Sep 2020 08:46:52 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:51 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 18/23] gpio: mockup: require debugfs to build Date: Fri, 4 Sep 2020 17:45:42 +0200 Message-Id: <20200904154547.3836-19-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Debugfs has become the standard way of interfacing with gpio-mockup to the point where the module is not very useful without it anymore. Let's make it a hard requirement to build gpio-mockup. Let's also add error checks whenever calling debugfs routines as we now don't expect them to fail. The device sub-directories must now be removed when the device is detached to correctly support dynamically created chips. The call to debugfs_remove_recursive() in module exit must be moved to the bottom or we'd risk to remove the root directory before devices can unregister their own sub-directories. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-mockup.c | 41 ++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 8030fd91a3cc..515f345757d8 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1567,6 +1567,7 @@ config GPIO_AGGREGATOR config GPIO_MOCKUP tristate "GPIO Testing Driver" + depends on DEBUG_FS select IRQ_SIM help This enables GPIO Testing driver, which provides a way to test GPIO diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 29fbf007ab26..7df990662c17 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -348,38 +348,55 @@ static const struct file_operations gpio_mockup_debugfs_ops = { .release = single_release, }; -static void gpio_mockup_debugfs_setup(struct device *dev, - struct gpio_mockup_chip *chip) +static void gpio_mockup_remove_chip_debugfs_entry(void *data) +{ + struct dentry *entry = data; + + debugfs_remove_recursive(entry); +} + +static int gpio_mockup_debugfs_setup(struct device *dev, + struct gpio_mockup_chip *chip) { struct gpio_mockup_dbgfs_private *priv; struct gpio_chip *gc; + struct dentry *attr; const char *devname; char *name; - int i; + int i, ret; gc = &chip->gc; devname = dev_name(&gc->gpiodev->dev); chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir); + if (IS_ERR(chip->dbg_dir)) + return PTR_ERR(chip->dbg_dir); + + ret = devm_add_action_or_reset(dev, + gpio_mockup_remove_chip_debugfs_entry, chip->dbg_dir); + if (ret) + return ret; for (i = 0; i < gc->ngpio; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); if (!name) - return; + return -ENOMEM; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) - return; + return -ENOMEM; priv->chip = chip; priv->offset = i; priv->desc = &gc->gpiodev->descs[i]; - debugfs_create_file(name, 0200, chip->dbg_dir, priv, - &gpio_mockup_debugfs_ops); + attr = debugfs_create_file(name, 0200, chip->dbg_dir, priv, + &gpio_mockup_debugfs_ops); + if (IS_ERR(attr)) + return PTR_ERR(attr); } - return; + return 0; } static void gpio_mockup_dispose_mappings(void *data) @@ -462,7 +479,9 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (rv) return rv; - gpio_mockup_debugfs_setup(dev, chip); + rv = gpio_mockup_debugfs_setup(dev, chip); + if (rv) + return rv; return 0; } @@ -629,6 +648,8 @@ static int __init gpio_mockup_init(void) int ret; gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); + if (IS_ERR(gpio_mockup_dbg_dir)) + return PTR_ERR(gpio_mockup_dbg_dir); ret = platform_driver_register(&gpio_mockup_driver); if (ret) { @@ -650,9 +671,9 @@ static int __init gpio_mockup_init(void) static void __exit gpio_mockup_exit(void) { - debugfs_remove_recursive(gpio_mockup_dbg_dir); platform_driver_unregister(&gpio_mockup_driver); gpio_mockup_unregister_devices(); + debugfs_remove_recursive(gpio_mockup_dbg_dir); } module_init(gpio_mockup_init); From patchwork Fri Sep 4 15:45:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293550 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A79AC43461 for ; Fri, 4 Sep 2020 15:48:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5275B206E7 for ; Fri, 4 Sep 2020 15:48:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Pph0ChKq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgIDPsY (ORCPT ); Fri, 4 Sep 2020 11:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbgIDPrT (ORCPT ); Fri, 4 Sep 2020 11:47:19 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5578C0619E4 for ; Fri, 4 Sep 2020 08:46:54 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id w5so7207972wrp.8 for ; Fri, 04 Sep 2020 08:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RT9K0p4g9wsam9mtLvU8jWCbdg1QlHE5npCSk6GRJVM=; b=Pph0ChKqHgqs9PaK7532rJDYq8CCuzL49IHbUNNh8wkzPBANz7SFZRVpe8XZ6089Dv w6hesKYtcpQT4Xn0LXDDkAAwnHY8SkZfl97hmrjQg1ejNa/IDYgWLvxD72t0bCCu1ihU Kia91DKj1cbhCQ054PEtqNZgjWU4xEvuzZbzThXH6fhadPW3xJHoOT4GOeXDsdpt4B6Q w8yhwq243s79jSf7dIZgRnGMtn09vLqHQF/2Gw1s+Xxbhg4FS7Q6bC3r5oFPgFrePT8H Rkc0q0bYUHSe+Yf2WE7b+liCRpH0L24hIZ43cjEjsbBKorpi1qb4JDcLyq2SkhHPkXug aKKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RT9K0p4g9wsam9mtLvU8jWCbdg1QlHE5npCSk6GRJVM=; b=DsG1hOCtzA9edsOm1nM3yygt8Q2Up8Q5lO5E7nE8Y/Gj5Z6i1Dga4cARHi/GAjzpOY 0Ab+BEAt7f/GpRPhXc9o+UvayF2dsqM7hhjqNqv4sTvWec4cpn0gR2MNPSQm0+Bl/WqI jtQRxEMw+LlBmqb/eCiOMRHSPJK6sXk+lYwyqGxcC8ksvZg7Q0anJPzBSlV607wraIfx +6Ee2mOOXvKKv2UDinkZkIQ0H2rX4MbyRBMwMqxYi5nBWjowBM/zahM5WKDiwCKhyG3w jwGv+lzLyLVVhW/vtQudqPIHDXphwWFgbUtFQL0Cwcq1n57FJOWm/lCqvFnwI9AJEXjn iStw== X-Gm-Message-State: AOAM5312uvOiHJMrFRXODCx+Zj60UZPbqz8ZwLNsrpHKFMkwgKQuu/7/ Krk8g77rcI2v2A1oOYyn98430A== X-Google-Smtp-Source: ABdhPJzwm1LPWjidY+W2eWt031GEhqfqEZ4XCSVhfjqUt9KC+wqwPvwzW1Xvz1lIpyZuwTS8CeLJLw== X-Received: by 2002:adf:9d44:: with SMTP id o4mr8315397wre.361.1599234413434; Fri, 04 Sep 2020 08:46:53 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:52 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 19/23] gpio: mockup: add a symlink for the per-chip debugfs directory Date: Fri, 4 Sep 2020 17:45:43 +0200 Message-Id: <20200904154547.3836-20-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We used to have a symlink named after the chip's label linking to the per-chip directory named after the chip's name. This was removed by commit d51ee07a8de7 ("gpio: mockup: don't create the debugfs link named after the label") because there were no users of it. This changeset proposes to reintroduce debugfs symlinks but inverted: the link named after the device name points to the directory named after the label. This way user-space can dynamically create a chip (once that functionality is available), detect its creation over uevent and match the device name to the label by resolving the link. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 7df990662c17..bc4609e047ef 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -52,6 +52,7 @@ struct gpio_mockup_chip { struct gpio_mockup_line_status *lines; struct irq_domain *irq_sim_domain; struct dentry *dbg_dir; + struct dentry *dbg_link; struct mutex lock; }; @@ -355,6 +356,13 @@ static void gpio_mockup_remove_chip_debugfs_entry(void *data) debugfs_remove_recursive(entry); } +static void gpio_mockup_remove_chip_debugfs_link(void *data) +{ + struct dentry *link = data; + + debugfs_remove(link); +} + static int gpio_mockup_debugfs_setup(struct device *dev, struct gpio_mockup_chip *chip) { @@ -368,7 +376,7 @@ static int gpio_mockup_debugfs_setup(struct device *dev, gc = &chip->gc; devname = dev_name(&gc->gpiodev->dev); - chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir); + chip->dbg_dir = debugfs_create_dir(gc->label, gpio_mockup_dbg_dir); if (IS_ERR(chip->dbg_dir)) return PTR_ERR(chip->dbg_dir); @@ -377,6 +385,16 @@ static int gpio_mockup_debugfs_setup(struct device *dev, if (ret) return ret; + chip->dbg_link = debugfs_create_symlink(devname, gpio_mockup_dbg_dir, + gc->label); + if (IS_ERR(chip->dbg_link)) + return PTR_ERR(chip->dbg_link); + + ret = devm_add_action_or_reset(dev, + gpio_mockup_remove_chip_debugfs_link, chip->dbg_link); + if (ret) + return ret; + for (i = 0; i < gc->ngpio; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); if (!name) From patchwork Fri Sep 4 15:45:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 207A0C43461 for ; Fri, 4 Sep 2020 15:48:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8E6D2074D for ; Fri, 4 Sep 2020 15:48:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="v5An7xgo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbgIDPsK (ORCPT ); Fri, 4 Sep 2020 11:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727114AbgIDPrW (ORCPT ); Fri, 4 Sep 2020 11:47:22 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF7AC0619E6 for ; Fri, 4 Sep 2020 08:46:55 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id a17so7192084wrn.6 for ; Fri, 04 Sep 2020 08:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tgjkBfCojYl8siMBzz1X6XLsrb4li1UKkVtYrxRpS88=; b=v5An7xgobEzUsXohY/9CcZLrbXYebSARl253UlqT4OjDvpHs0nlnxnvVFgF6WcLkJS xra4c5MT5F+bQ0Sdeb+WScl0S9QrtaP9RpDAKh3mJDHWFk33bq9NV0v8Ytnt5G8bJaoM OvAxPx4OI31i2vwJMOX+Tg8jqlFX5asZiIFC1Y4O8bKM+sYbd3EZ0czWSDTgAtJrLHNB MtQebZdcQwqp6H5y+8v8Y05PiwEQkAAhifAogt1PAgV4XK/XBEpRu2totaKRwM+U/wFj X2js1Lpmq31ut70bi4SWrIjyzKhKpzyfIqYSNF823NrjP3k5wlRwA262C9vq4fEAfR9e jCUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tgjkBfCojYl8siMBzz1X6XLsrb4li1UKkVtYrxRpS88=; b=a8fOxfzpgtwC1voDwB5wdGbONaK6b7/DTJ7aQl3KISvZNaPSNViWkwUZ9Br9GDvyBL K0zDCFkLgavMpjkhx7tlzyCtfbcIs2G96w97kMHehCu9uKUSibcdtc1tinrc3/3nt/a5 +f/q00+HWoxkVX+fx2Z/C2IKttVe8iwhUmlM6WKLsUINh2zmgOuAuB8ZaAekKHHk5XRA IGWjqCoOLneUsq/ZSh42X62/XEOKgLWWRjWwVLIcOk6nJmTKxrozPf7nbCYXkEkwoVws BP6ZacZ6FLnKLROR0KxEfBqjhcQ6JOSDvPSaxKoAKXTido4MNZnlMGSiPzwfHrdwH7N+ LIbw== X-Gm-Message-State: AOAM5301l7QpksLy1MrbK8O7rbK4U3YDWidgnmsVdNxzDK51o4rJ4v4Y 4D3KglxFpTe16qCSbD6JtRcQog== X-Google-Smtp-Source: ABdhPJxoEZmE7Lp6gNfO9fs5XvWgmx2zMirJWKxaSR6g8MfJUjKjK4YQqTkezGJLvB2fzJSBJYuHnQ== X-Received: by 2002:a5d:6a45:: with SMTP id t5mr8954332wrw.58.1599234414568; Fri, 04 Sep 2020 08:46:54 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:54 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 20/23] gpio: mockup: add a lock for dummy device list Date: Fri, 4 Sep 2020 17:45:44 +0200 Message-Id: <20200904154547.3836-21-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We'll soon add the possibility to create chips dynamically over debugfs attributes. Since multiple threads will be able to create devices at once: add a mutex to protect the device list. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index bc4609e047ef..1353239dc315 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -517,6 +517,7 @@ struct gpio_mockup_device { }; static LIST_HEAD(gpio_mockup_devices); +static DEFINE_MUTEX(gpio_mockup_devices_lock); static void gpio_mockup_unregister_one_device(struct gpio_mockup_device *dev) { @@ -534,10 +535,14 @@ static void gpio_mockup_unregister_devices(void) struct gpio_mockup_device *mockup_dev; struct list_head *curr, *next; + mutex_lock(&gpio_mockup_devices_lock); + list_for_each_safe(curr, next, &gpio_mockup_devices) { mockup_dev = list_entry(curr, struct gpio_mockup_device, list); gpio_mockup_unregister_one_device(mockup_dev); } + + mutex_unlock(&gpio_mockup_devices_lock); } static __init char **gpio_mockup_make_line_names(const char *label, @@ -588,7 +593,9 @@ static int __init gpio_mockup_register_device(struct property_entry *properties) return PTR_ERR(mockup_dev->pdev); } + mutex_lock(&gpio_mockup_devices_lock); list_add(&mockup_dev->list, &gpio_mockup_devices); + mutex_unlock(&gpio_mockup_devices_lock); return 0; } From patchwork Fri Sep 4 15:45:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1A99C2D0A7 for ; Fri, 4 Sep 2020 15:48:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C319D206E7 for ; Fri, 4 Sep 2020 15:48:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="T29hggUB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727857AbgIDPsJ (ORCPT ); Fri, 4 Sep 2020 11:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727776AbgIDPrd (ORCPT ); Fri, 4 Sep 2020 11:47:33 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13875C0619E8 for ; Fri, 4 Sep 2020 08:46:57 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id c15so7167613wrs.11 for ; Fri, 04 Sep 2020 08:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=grMpfwJBPKz8x8JwdVkKa3ogOmUgQ5L3HbriAAtXMOE=; b=T29hggUBZSkRV9pQbFKSYoyB5ydrOKR+eklkTQqELriqTYpxPUnHKrAQ5JKk0Op74Q DCxlFEGrV8egWnu5H/c03dcSHHYXjjtqm8rjAsFcvt8PJHS4qak+49XcjgQgBcjgMiI8 qIDpYQbwqZE2cgT0bB0aDZPqm12ei0JuBbnIxH43DhRDxfoh/lX2p3N0pYHOzXJyZ1Q/ Q4s6DClwAfE/qxdvNwJgGGMk1CJwX6CFhO4oRx/5G5B4T22zAxPoaWisGxGE1YFintKM ACUm9cOFgKwYlDa0KUtbdHlwxYdxWEiIki7K6drA8WjMT3VnCj12hhleiJbWcgTF2y0N lMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=grMpfwJBPKz8x8JwdVkKa3ogOmUgQ5L3HbriAAtXMOE=; b=pUwFV8+HgQoQr6pBVLHk3kj7mAC5QXNRvxvrq2Q7TOEM+6WE8WsAhc+uv46qiuiCc1 24uaHwMauZq2yIqEt3cAZFtU6JZqTrXtfnJSWoW9Bhz6qk51GBodEsbSWDgtQmA+B/fM Ed7a7P4E72OoudhGxWo3uI1zVmbNi4rRPCUYtpaJs14vc4lY0n8tPXzq3s+0gziN1j2/ 6SLvQCt5W60SUa7Yk57BIC9BKUVeXPNMx1tMI4j0ERp+THhEeffUCk2LYAn+8jRbiX4x V7xPgjxekBS/HV9OYgYRs6DQEC1dI6ZSRH50aTnWwVxDhvgjpyR3RHKRUug0sGwumy97 5rGA== X-Gm-Message-State: AOAM533zBK00DqqKiS/fXA6dlcoRTlVSOqb7gEBsF+fp8yPA2rhMUWn+ Gn5htOg1y/JFHRW4sjn8ivzbgA== X-Google-Smtp-Source: ABdhPJwF/TdbSD80yVhLNOeAq70EYhl8a4L44K/4AYYY/Rbp36+YEs1GetDpBBcfGubtwwMDMcnZNA== X-Received: by 2002:adf:ed12:: with SMTP id a18mr8803147wro.178.1599234415760; Fri, 04 Sep 2020 08:46:55 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:55 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 21/23] gpio: mockup: provide a way to delete dummy chips Date: Fri, 4 Sep 2020 17:45:45 +0200 Message-Id: <20200904154547.3836-22-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Add a new debugfs attribute 'delete_device' to which the chip label can be written to dynamically remove the associated dummy device. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 70 +++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 1353239dc315..9d2de78a45c2 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -668,14 +669,81 @@ static int __init gpio_mockup_register_chips_from_params(void) return 0; } -static int __init gpio_mockup_init(void) +static ssize_t gpio_mockup_debugfs_delete_device_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) { + struct gpio_mockup_device *mockup_dev; + char label[GPIO_MOCKUP_LABEL_SIZE]; + struct list_head *curr; + struct device *dev; + const char *prop; int ret; + if (*ppos != 0) + return -EINVAL; + + ret = getline_from_user(label, sizeof(label), usr_buf, size); + if (ret < 0) + return ret; + + mutex_lock(&gpio_mockup_devices_lock); + + list_for_each(curr, &gpio_mockup_devices) { + mockup_dev = list_entry(curr, struct gpio_mockup_device, list); + dev = &mockup_dev->pdev->dev; + + ret = device_property_read_string(dev, "chip-label", &prop); + if (ret) { + mutex_unlock(&gpio_mockup_devices_lock); + return ret; + } + + if (sysfs_streq(label, prop)) { + gpio_mockup_unregister_one_device(mockup_dev); + mutex_unlock(&gpio_mockup_devices_lock); + return size; + } + } + + mutex_unlock(&gpio_mockup_devices_lock); + return -ENODEV; +} + +static const struct file_operations gpio_mockup_debugfs_delete_device_ops = { + .owner = THIS_MODULE, + .open = gpio_mockup_debugfs_open, + .write = gpio_mockup_debugfs_delete_device_write, + .llseek = no_llseek, + .release = single_release, +}; + +static int __init gpio_mockup_debugfs_init(void) +{ + struct dentry *entry; + gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); if (IS_ERR(gpio_mockup_dbg_dir)) return PTR_ERR(gpio_mockup_dbg_dir); + entry = debugfs_create_file("delete_device", 0200, gpio_mockup_dbg_dir, + NULL, &gpio_mockup_debugfs_delete_device_ops); + if (IS_ERR(entry)) { + debugfs_remove_recursive(gpio_mockup_dbg_dir); + return PTR_ERR(entry); + } + + return 0; +} + +static int __init gpio_mockup_init(void) +{ + int ret; + + ret = gpio_mockup_debugfs_init(); + if (ret) + return ret; + ret = platform_driver_register(&gpio_mockup_driver); if (ret) { pr_err("error registering platform driver\n"); From patchwork Fri Sep 4 15:45:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3787BC2D0E0 for ; Fri, 4 Sep 2020 15:48:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0440B206E7 for ; Fri, 4 Sep 2020 15:48:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="CZAvReeu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726927AbgIDPsI (ORCPT ); Fri, 4 Sep 2020 11:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727780AbgIDPre (ORCPT ); Fri, 4 Sep 2020 11:47:34 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 620CDC061237 for ; Fri, 4 Sep 2020 08:46:58 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id o21so6538430wmc.0 for ; Fri, 04 Sep 2020 08:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3aWcm+3JDeJZmE6xtJBDfj0eVLxqNfoBKt8HcdF/1EE=; b=CZAvReeuXtd9ZK1t6qgNO75jV6xJlnEXljI4/mnHXpsbq7PxgUPsIC86O2hC0U6rgr HGHHIc7tvF/BzZmibkMHYfVKfSiGyR7I0RPNsAB1PY0GSy55ZcCS0Z57NQoFapTJ4LSY eafgxUJWblDraafe/Vzru3THELlnIIlm9wJltqiYWF7zS8/ZdjgdqhJ3UI2LPXHNtjQC ReTu3FLqRuYrH1XJk5i5MP4EwGTp9sBq+5edDyShrTWEcPqUJ8ItX+22ARKmIoDZksfD qHa5OwNLhRuLopdaxi4K7dPnWataLNsZBy3/HbfxRTZVHevoU8J84X38CmWddi3Tsz5P eqMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3aWcm+3JDeJZmE6xtJBDfj0eVLxqNfoBKt8HcdF/1EE=; b=MEeOoVEfjR07at8gzYyU99ilW005XXu8ajDVlUbYNq19DL3M9rVFkpprTOM7tZWo26 7a9szZV95Slein/wuOyDuDn85OWv4UzyiHB9vCUeLcvvsJijOdPmb7cOnjtibf0E/qhj 5nIyCVyUz3UwbpPQf4RAy/odBTZ/LFh/iolb3gYL4X4sKKq/eOiYd0yfc6wjBcrIj7pO BE6oAlT5sHYE1VrPhC84iwMdkjD2xukiNCaW1q+EUiEYIk7/HpsueduLH7cou+7bTe+s USKmn2vKyRhc2NyefFMYQqULmKQF8CrEl11tcOHZWbRjrhODK2O06zN7F+GOuexq/u1I Mfmw== X-Gm-Message-State: AOAM533KIrHPzn/Jfg+1daM1WTzx05Rj3HlWoDPEnYk1y39GIIpqG+Im RaC7U9a4PL8+9i95b5cEfrxxG9IfWj3b1w== X-Google-Smtp-Source: ABdhPJxw9xJK0XTZm5xxkM2ONzghwfamibziq3gwrnxN4MBR3VhmxObh/FITueCXATZQmz5tZAHJWg== X-Received: by 2002:a7b:c00c:: with SMTP id c12mr8800011wmb.54.1599234416977; Fri, 04 Sep 2020 08:46:56 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:56 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 22/23] gpio: mockup: provide a way to create new dummy chips Date: Fri, 4 Sep 2020 17:45:46 +0200 Message-Id: <20200904154547.3836-23-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Add a new debugfs attribute 'new_device' that allows to dynamically create new dummy chips according to specification. New chips are created by writing a number of supported parameters to the new attribute of which 'label' and 'num_lines' are mandatory. The new attribute is designed to be easily exstensible with new parameters. For now we simply provide the same functionality that the module params expose but with the intention of introducing new options (such as custom line name formats). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 231 +++++++++++++++++++++++++++++++++++-- 1 file changed, 220 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 9d2de78a45c2..6577d18671df 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -5,6 +5,7 @@ * Copyright (C) 2014 Kamlakant Patel * Copyright (C) 2015-2016 Bamvor Jian Zhang * Copyright (C) 2017 Bartosz Golaszewski + * Copyright (C) 2020 Bartosz Golaszewski */ #include @@ -14,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -546,8 +548,8 @@ static void gpio_mockup_unregister_devices(void) mutex_unlock(&gpio_mockup_devices_lock); } -static __init char **gpio_mockup_make_line_names(const char *label, - unsigned int num_lines) +static char **gpio_mockup_make_line_names(const char *label, + unsigned int num_lines) { unsigned int i; char **names; @@ -567,7 +569,7 @@ static __init char **gpio_mockup_make_line_names(const char *label, return names; } -static int __init gpio_mockup_register_device(struct property_entry *properties) +static int gpio_mockup_register_device(struct property_entry *properties) { struct gpio_mockup_device *mockup_dev; struct platform_device_info pdevinfo; @@ -641,8 +643,7 @@ static int __init gpio_mockup_register_chips_from_params(void) { int num_chips, i, ret; - if ((gpio_mockup_num_ranges < 2) || - (gpio_mockup_num_ranges % 2) || + if ((gpio_mockup_num_ranges % 2) || (gpio_mockup_num_ranges > GPIO_MOCKUP_MAX_RANGES)) return -EINVAL; @@ -669,6 +670,205 @@ static int __init gpio_mockup_register_chips_from_params(void) return 0; } +/* + * We store all data associated with device properties in this structure. It's + * only needed until we register the platform device at which point the driver + * core makes a deep copy of all property data (even the string arrays). + * + * The reason to keep them bunched up is simple: we can have a single function + * to free all resources which simplifies error handling. + */ +struct gpio_mockup_prop_data { + char chip_label[GPIO_MOCKUP_LABEL_SIZE]; + u16 ngpio; + bool named_lines; + char **line_names; +}; + +/* We don't free the structure itself - it's expected to live on the stack. */ +static void +gpio_mockup_free_property_data(struct gpio_mockup_prop_data *prop_data) +{ + kfree_strarray(prop_data->line_names, prop_data->ngpio); +} + +/* + * Each supported option is parsed by a separate callback - this way the + * 'new_device' attribute is easily exstensible. + */ +struct gpio_mockup_new_device_opt { + char *name; + int (*func)(const char *val, struct gpio_mockup_prop_data *prop_data, + struct property_entry *properties, int *prop_idx); + bool has_val; +}; + +static int +gpio_mockup_parse_label(const char *val, + struct gpio_mockup_prop_data *prop_data, + struct property_entry *properties, int *prop_idx) +{ + snprintf(prop_data->chip_label, sizeof(prop_data->chip_label), val); + properties[(*prop_idx)++] = + PROPERTY_ENTRY_STRING("chip-label", prop_data->chip_label); + + return 0; +} + +static int gpio_mockup_parse_num_lines(const char *val, + struct gpio_mockup_prop_data *prop_data, + struct property_entry *properties, int *prop_idx) +{ + int ret; + + ret = kstrtou16(val, 10, &prop_data->ngpio); + if (ret) { + pr_err("invalid new_lines format: %s\n", val); + return ret; + } + + properties[(*prop_idx)++] = PROPERTY_ENTRY_U16("nr-gpios", + prop_data->ngpio); + + return 0; +} + +static int gpio_mockup_parse_named_lines(const char *val, + struct gpio_mockup_prop_data *prop_data, + struct property_entry *properties, int *prop_idx) +{ + prop_data->named_lines = true; + + return 0; +} + +static struct gpio_mockup_new_device_opt gpio_mockup_new_device_opts[] = { + { + .name = "label", + .func = gpio_mockup_parse_label, + .has_val = true, + }, + { + .name = "num_lines", + .func = gpio_mockup_parse_num_lines, + .has_val = true, + }, + { + .name = "named_lines", + .func = gpio_mockup_parse_named_lines, + .has_val = false, + }, +}; + +static int +gpio_mockup_parse_one_opt(const char *key, const char *val, + struct gpio_mockup_prop_data *prop_data, + struct property_entry *properties, int *prop_idx) +{ + struct gpio_mockup_new_device_opt *opt; + int i; + + for (i = 0; i < ARRAY_SIZE(gpio_mockup_new_device_opts); i++) { + opt = &gpio_mockup_new_device_opts[i]; + + if (strcmp(key, opt->name) == 0) { + if (opt->has_val && !val) { + pr_err("%s option requires an argument\n", + opt->name); + return -EINVAL; + } + + if (!opt->has_val && val) { + pr_err("%s option doesn't take any arguments\n", + opt->name); + return -EINVAL; + } + + return opt->func(val, prop_data, properties, prop_idx); + } + } + + return -EOPNOTSUPP; +} + +static int +gpio_mockup_new_device_from_opts(char *opts, + struct gpio_mockup_prop_data *prop_data) +{ + struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + int prop_idx = 0, ret; + char *key, *val; + + memset(properties, 0, sizeof(properties)); + + while (*opts) { + if (prop_idx >= GPIO_MOCKUP_MAX_PROP) + return -EINVAL; + + opts = next_arg(opts, &key, &val); + + ret = gpio_mockup_parse_one_opt(key, val, prop_data, + properties, &prop_idx); + if (ret) + return ret; + } + + /* This is the only mandatory property. */ + if (!prop_data->ngpio) { + pr_err("number of lines must be specified\n"); + return -EINVAL; + } + + /* + * Line names must be created at the end - once we know how + * many GPIOs there are. + */ + if (prop_data->named_lines) { + prop_data->line_names = gpio_mockup_make_line_names( + prop_data->chip_label, + prop_data->ngpio); + if (!prop_data->line_names) + return -ENOMEM; + + properties[prop_idx++] = + PROPERTY_ENTRY_STRING_ARRAY_LEN("gpio-line-names", + prop_data->line_names, + prop_data->ngpio); + } + + return gpio_mockup_register_device(properties); +} + +static ssize_t gpio_mockup_debugfs_new_device_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) +{ + struct gpio_mockup_prop_data prop_data; + char opts[128]; + int ret; + + if (*ppos != 0 || size > sizeof(opts)) + return -EINVAL; + + ret = getline_from_user(opts, sizeof(opts), usr_buf, size); + if (ret < 0) + return ret; + + memset(&prop_data, 0, sizeof(prop_data)); + + ret = gpio_mockup_new_device_from_opts(opts, &prop_data); + gpio_mockup_free_property_data(&prop_data); + return ret < 0 ? ret : size; +} + +static const struct file_operations gpio_mockup_debugfs_new_device_ops = { + .owner = THIS_MODULE, + .open = gpio_mockup_debugfs_open, + .write = gpio_mockup_debugfs_new_device_write, + .llseek = no_llseek, + .release = single_release, +}; + static ssize_t gpio_mockup_debugfs_delete_device_write(struct file *file, const char __user *usr_buf, size_t size, loff_t *ppos) @@ -726,6 +926,13 @@ static int __init gpio_mockup_debugfs_init(void) if (IS_ERR(gpio_mockup_dbg_dir)) return PTR_ERR(gpio_mockup_dbg_dir); + entry = debugfs_create_file("new_device", 0200, gpio_mockup_dbg_dir, + NULL, &gpio_mockup_debugfs_new_device_ops); + if (IS_ERR(entry)) { + debugfs_remove_recursive(gpio_mockup_dbg_dir); + return PTR_ERR(entry); + } + entry = debugfs_create_file("delete_device", 0200, gpio_mockup_dbg_dir, NULL, &gpio_mockup_debugfs_delete_device_ops); if (IS_ERR(entry)) { @@ -751,12 +958,14 @@ static int __init gpio_mockup_init(void) return ret; } - ret = gpio_mockup_register_chips_from_params(); - if (ret) { - pr_err("error registering device"); - debugfs_remove_recursive(gpio_mockup_dbg_dir); - platform_driver_unregister(&gpio_mockup_driver); - return ret; + if (gpio_mockup_ranges > 0) { + ret = gpio_mockup_register_chips_from_params(); + if (ret) { + pr_err("error registering device"); + debugfs_remove_recursive(gpio_mockup_dbg_dir); + platform_driver_unregister(&gpio_mockup_driver); + return ret; + } } return 0; From patchwork Fri Sep 4 15:45:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 293552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 566AEC433E2 for ; Fri, 4 Sep 2020 15:47:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29474206E7 for ; Fri, 4 Sep 2020 15:47:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="iirBcZw4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727792AbgIDPr4 (ORCPT ); Fri, 4 Sep 2020 11:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727790AbgIDPrg (ORCPT ); Fri, 4 Sep 2020 11:47:36 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936C4C061246 for ; Fri, 4 Sep 2020 08:46:59 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id w2so6507364wmi.1 for ; Fri, 04 Sep 2020 08:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+T4nqXaC8fjBrWkDJbcI/m89Hs0Il9eeYVZ91EUv4bE=; b=iirBcZw4EgxyAFB9yrfqfHzrbIqBRMnGr84pnWLTSHWiDS/j7p4d7c1IpfTuH6U0yE kqQ+3Cup4oeN2ka7rRGBWA1VgzzhuxJJja+zLHmjZw2eXRU3Yosp3+5A4U7XPXJ5vbVj B0EwMLnRv8Z1xZQRMOZVAeXAcgdCFJ6591m6BtMaR7vygL5ntSU++35wP4FwhLKD8mki n4OL3b5QGP86X4QLHPRhSu46PuWJoc+QP4LeR4B2yVVJitaWtbOymwB3MJF/uM5Vx81y RLijD9+Rt/EUhWQrtLvqh/+1KBK6+11K8JaHcwSvMvX79X8NocXKzJGbiecv0fBZjslV A7vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+T4nqXaC8fjBrWkDJbcI/m89Hs0Il9eeYVZ91EUv4bE=; b=GBSRAaS1i0yGNkRfXQ46ONAF6WSmW/FqLNhN+6CUb4lUFD4YKrUWLl0tE47QTVHHeY PTGKPosRmGAXLIM8Fvt4fJWBfCTcWViY0+bscDtSgbffAI8QaE1B1GrdFbMnOsYjqjzw b7XKvAAsCt8Zaxg+tpjhKAsT1gACq/gNjqApQywumjw5YnoOLQuX0mFEkSe7lAKt4P6y zwyUj5LMokmelN1DanEFncPnL4KN/E//ZJcuqlZmWCbvTIBFudL1xPIwiYfLH/7oh2zX OYYdkV8GQdVxSHPMw3XLEzWR5yhhIJi6369QBdstE8gfwbgE2UI39c8gP8FplVtYSF91 zhZw== X-Gm-Message-State: AOAM533qXiOD0fTApcZHHGPr0/Va2K+oYaq0Ad2uzrOCWMCatV1xQNLc aA3Vly5V9XQBgnP7I7Hp+5lrpg== X-Google-Smtp-Source: ABdhPJyjc2MlVjuY6G3UNUTfVft9wTllA8VYq1OpvEDtNds22hkn1ilbEsjGyby0vTpaSIVU2cgT8Q== X-Received: by 2002:a7b:cb0d:: with SMTP id u13mr8555846wmj.144.1599234418241; Fri, 04 Sep 2020 08:46:58 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:57 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 23/23] Documentation: gpio: add documentation for gpio-mockup Date: Fri, 4 Sep 2020 17:45:47 +0200 Message-Id: <20200904154547.3836-24-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski There's some documentation for gpio-mockup's debugfs interface in the driver's source but it's not much. Add proper documentation for this testing module. Signed-off-by: Bartosz Golaszewski --- .../admin-guide/gpio/gpio-mockup.rst | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-mockup.rst diff --git a/Documentation/admin-guide/gpio/gpio-mockup.rst b/Documentation/admin-guide/gpio/gpio-mockup.rst new file mode 100644 index 000000000000..1d452ee55f8d --- /dev/null +++ b/Documentation/admin-guide/gpio/gpio-mockup.rst @@ -0,0 +1,87 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +GPIO Testing Driver +=================== + +The GPIO Testing Driver (gpio-mockup) provides a way to create simulated GPIO +chips for testing purposes. There are two ways of configuring the chips exposed +by the module. The lines can be accessed using the standard GPIO character +device interface as well as manipulated using the dedicated debugfs directory +structure. + +Creating simulated chips using debugfs +-------------------------------------- + +When the gpio-mockup module is loaded (or builtin) it creates its own directory +in debugfs. Assuming debugfs is mounted at /sys/kernel/debug/, the directory +will be located at /sys/kernel/debug/gpio-mockup/. Inside this directory there +are two attributes: new_device and delete_device. + +New chips can be created by writing a single line containing a number of +options to "new_device". For example: + +.. code-block:: sh + + $ echo "label=my-mockup num_lines=4 named_lines" > /sys/kernel/debug/gpio-mockup/new_device + +Supported options: + + num_lines= - number of GPIO lines to expose + + label=