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: 11757933 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C366292C for ; Fri, 4 Sep 2020 15:50:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A819A20791 for ; Fri, 4 Sep 2020 15:50: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="ZLU7hI+W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbgIDPu4 (ORCPT ); Fri, 4 Sep 2020 11:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbgIDPqe (ORCPT ); Fri, 4 Sep 2020 11:46:34 -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 35FDDC061246 for ; Fri, 4 Sep 2020 08:46:32 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id s13so6472590wmh.4 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=uJU9PlFS+RqGkREIYGejAS03DXk4c1bZ7uQKtvb+QyQSNs6RF/5NH1UaMACCHFSg71 1ij2XUArAOTngVXgPHawctBxu3ms8ORshW9GeTx3zFIoQO5X7oWnRaqHLtgrMK6ztrBk OHgmOPAjWdR0SkgImSFO3oOAj0mmUeIj8+VZ0B9gIV9xad+dppEFZjT4hQDxvHEjekbg K1zovH++SAzSp/gkcT+4L/qkO511GXN7a36HNxRU/Up5AQSQCZYEu+Oh64pXqBVh22cI M/uK0tRacq5IoNbSX068fzGCr1yqCpvgSMCwCDJ0iQvbslchV5AmeerEr8t5RrE9xkht 9xAA== X-Gm-Message-State: AOAM530YNy9XEcYykDDBR775W648k9XFW3Ni+gnmomrCFaowQwY6R5/U cI0/hEJF4+JyLWnm6RlOnfVyGg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757929 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9210214EB for ; Fri, 4 Sep 2020 15:50:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7595F20791 for ; Fri, 4 Sep 2020 15:50: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="c4iemgVa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726559AbgIDPuj (ORCPT ); Fri, 4 Sep 2020 11:50:39 -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 S1726530AbgIDPqj (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 DCC29C06125C for ; Fri, 4 Sep 2020 08:46:34 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l9so6512583wme.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=eGFnn/PtsYZl5EXZwOEmQ3aQL4gnV+hxUYhoKD2+Jk7kq7m4SWQCyP50JBqFNJ5obm Y3JDh+pWkHDa3ZVq8tmwZgAYwO5M3vjs2WvzQIimlwGRv4NySVZQX50/1WCbYh0a/mY6 j4SWtAIMYA6AVMcj4iNHvQTqKhG/leteQVNetXHhZL7ELFEZFkFgvABaBDwOssRSYFf0 klGYV/nE7BIW6//o+S6N1NQcux/4ego9S+PTXwImysE1+HJbh4R+gEKqcJBQP296U+AF 6zdZmnuHtMhOluDlAFeV2SP9MxABMhv2/epb02zcYlSf9F05OnXVnlKO9t71Zu9pR7Hp H+iw== X-Gm-Message-State: AOAM533knJzlXIcIm9800Pf3nI7zUNbHVvSMoep/chG5KTwHHayugDoe CzNkofqvfvqIHaiaad+Cbw7Ytg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757931 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A17592C for ; Fri, 4 Sep 2020 15:50:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BC3620791 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="s1xR3LsW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbgIDPuh (ORCPT ); Fri, 4 Sep 2020 11:50:37 -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 S1726615AbgIDPql (ORCPT ); Fri, 4 Sep 2020 11:46:41 -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 3262CC061263 for ; Fri, 4 Sep 2020 08:46:36 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id v4so6494371wmj.5 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=LLEqQetJSkHa1qQ2vKaNMIRJTctU8FleCFr0JVsoNpWXrOmRPV6t0Rzvyo8TtWJk5u 2JWj/5f0iIB07DmmarcAO2XakDtas8iIT2Oo53atV5Il4hUxq9VjbH0nDBRvm7TW9GLG 4XF1By0RPTOry+EeW5qSPqfA8iB0LTSUy9n5C4bTn5FF9K845vC2kab+erm2QlNBGtPO gVkyo5aSOGaKjZnmXac+CPsBE15ZNegVznjkj6fM3MWSPDk1fowRag3HXZhFUrQwvXiM kH8oyYMtqOblIFcEaegzQ/F/6f/QPK06833w07q4COELx5TTx00g30dDCqOhwPKMOwOz SDjA== X-Gm-Message-State: AOAM531vGTVqLJG5f0S7tYdCZgLZ4kj/+mPS0gG2zyKoyEEQfAATgWmF 4Cg+myVG6aLfLbPoMPKCSomo2w== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65C3192C for ; Fri, 4 Sep 2020 15:46:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C7AC20772 for ; Fri, 4 Sep 2020 15:46:56 +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 S1726154AbgIDPqv (ORCPT ); Fri, 4 Sep 2020 11:46:51 -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 S1726667AbgIDPqo (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 48263C061232 for ; Fri, 4 Sep 2020 08:46:37 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id z4so7213350wrr.4 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=d4Hkr1S4uXjjiAj6C5GxrQ4BrQyxj+BPZqMYB0SGmx2QlOwnam72CJul4heWYkJVlM NzvlrLSjV7H65NVnaKkNhxQi5BHvVunV0NKACC8steC0IhXOLyHFH/5U3uNBbi3kPV4Z CmRwGC6jb+4AiFhMhJBcd3cSn5GQvNNtmabjDFAIAFb1c3Io78G175N8Bc58lrsUJKLg z4YjH036dNqGRFoInR8bqwjUzEgG1hsI51BxuJLlk/0Lq6oO/IpuzXlHLvR3+Zzpaxo4 w3bMJrseKVsUBtrkvO4r3oEbngi074TCZglhsc+7VaICEZGKo11fzg9qRImEqNqh8rT2 0eFA== X-Gm-Message-State: AOAM533vPGTmTsbjoI/2affIoIVatOq2V2ALS5KScUuXYr5MT6ZUtQcq 6sX/ZCwS/OzXZN7JUKZcVkyFAg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1246A14EB for ; Fri, 4 Sep 2020 15:50:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E91A12087C for ; Fri, 4 Sep 2020 15:50:16 +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 S1727789AbgIDPuP (ORCPT ); Fri, 4 Sep 2020 11:50:15 -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 S1726742AbgIDPqp (ORCPT ); Fri, 4 Sep 2020 11:46:45 -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 7C21AC061235 for ; Fri, 4 Sep 2020 08:46:38 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id c15so7166649wrs.11 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=f/0/GRefyT7NzaSGviIPs8d1Jj5RWvci7F/ib9BjetC0oo4IRza6jYkcoJyM/LZeyt t9U+cKUqPWVSEDG2OkTNYUgyJf4Ra5x2k6QE/SyHZVQzrox6zoQGc2mXUcUkjb4tyHuc x72JUG6cdeQ7VOLLfOsMn7kik3F32gNOHCfrNjkRRM2zNGsCaPYSq+yqtyKOiPqWrrVF U5agfLM5j5gbTwCA9v6nMg0VFdYQKaSLbPgltgpe5WgPEs+zEP51pDRMAzqGDMKKUVPJ J+cbnhLFOatnWNTQwwXoB0VtXwVBvDB7myIlbEgLVK46XZciJXtfmHxVOlL9COFC6pwY uS3Q== X-Gm-Message-State: AOAM533XbUtpW1POHjDATqdtzowHRRdakuAMjcFUqPXpdmd4Hbj21LQe jJr+spteuftBEo/5+jUR+ksnK7fU942Xrg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07BDE92C for ; Fri, 4 Sep 2020 15:49:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E436520772 for ; Fri, 4 Sep 2020 15:49:33 +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 S1726947AbgIDPq6 (ORCPT ); Fri, 4 Sep 2020 11:46:58 -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 S1726800AbgIDPqq (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 87367C061237 for ; Fri, 4 Sep 2020 08:46:39 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id c18so7183464wrm.9 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=jtcblQTqD2sZ5fzEfrTHC0YsAZnmJBJONi2eqSYncXQrAk3CiAzQ0ZdVNXJaq3w2/u arKoV0pzDqOY1IoFiM0o8XKbBEWuozsn3CYqH1An10l0NLc8laUqrRjEGk1q9JTWSf21 CBHpDVtST31ngxHStIJgQ8BoNr17lv83V6Qj+3G+V5WzQCIL5Uv49FVWHg+IWjP45/Zr D1PGZqfLPcMuiJE41xrd5LKLzPRwPEd+RFXERDMZBGxf7C/B9F7zKBrBAtO8GDEpWR1C 8I47ThXXbfh+qCFdF4sXEwTAIAw1lpugHsX+r657mySWHO3CQhqHFWkeH7RfQzGh7ySh UCzQ== X-Gm-Message-State: AOAM530Kj8yS3idS4XH7k8siWDVxB4ysR/10/lkrY+zoCxcv62GlSHKk iukwkq+LjI90uUmI2RexDP4v3A== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757923 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 275D992C for ; Fri, 4 Sep 2020 15:50:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F73320770 for ; Fri, 4 Sep 2020 15:50:06 +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 S1727935AbgIDPuB (ORCPT ); Fri, 4 Sep 2020 11:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726855AbgIDPqr (ORCPT ); Fri, 4 Sep 2020 11:46:47 -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 B1670C06123D for ; Fri, 4 Sep 2020 08:46:40 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c15so7166770wrs.11 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=mmULIyyugcIWqprFVqyzKCwZEiaPLpLb+JTENA3johrIAvxnieeOPYzVSLDwygAr1b Idp46g294pCj3N4gvFkk9QIp8bp3FM3YQ/fvCAtUG2aVB33OJP8j+59DkynfDuSN8017 05az0uotEAVMa2SQqfFsnBY1dTv22txr4Lg97tS3bdQmt46EPOwNTO79dusdlPEJRpTs SnrjWcYzG1NljnEbTuJ09Xq5OIzLsTwMfQc8uau9LvvA1pt7rFgB4DelkvtXlkqG2+rx IV7zlz+vexlaKjf0YNbrix4lYl5baSYI8K3YcjsS6X04l4iS/3FuZeKohJIvoD3/DjTn 7/lQ== X-Gm-Message-State: AOAM530umksko2v1chTUc37zHDd+lc2Ol2G3spCxScl6RwMqEOIZs+2h diQkhs75nM74VKy4EOIKQtPoKg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21D3292C for ; Fri, 4 Sep 2020 15:49:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0851020772 for ; Fri, 4 Sep 2020 15:49:57 +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 S1726900AbgIDPtz (ORCPT ); Fri, 4 Sep 2020 11:49:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbgIDPqv (ORCPT ); Fri, 4 Sep 2020 11:46:51 -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 6703DC06123F for ; Fri, 4 Sep 2020 08:46:42 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id w5so7207339wrp.8 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=gDLXqEENhHPAeQSWxfhJYG5zmvbZ/i8HN0mqMis0wMq1jRQ3M2/IRXKfBI9+49QlzM TtmEtvMbRJV7RR4bT0XMKDj+ZoTe4VrEx1PLjVMCKmdkLN0QbP2JloUb5WpMCezi2Blu tR9sM4K05aR8H05vkTTMLvY7M4BMY675Pd2EB/GXmnUQP4zIRyiYGhNYgMFO6CH1nyj5 Fi+awOphmNLqHYY6WLOMbwImKJGPdV/iP3E8NDQJZE+8WG1EzNYb4QJlnOc6xJ/wadRA veq3DXCB7ZW1JowBIRG0hPy+cQsUSGW/p21KH0DNewYKwt+X/RiKzX9nmycuBQJaPPn2 kUvw== X-Gm-Message-State: AOAM532dxtvt5oQlMGb0p01OjIJ3DPoXYm7a2QtogONKsQvCiVHezkv7 TxBnvYudV8gDMhtoZ2IhAFIV8g== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEE7E14EB for ; Fri, 4 Sep 2020 15:50:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2F3B207EA for ; Fri, 4 Sep 2020 15:50:01 +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 S1726892AbgIDPuA (ORCPT ); Fri, 4 Sep 2020 11:50: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 S1726109AbgIDPqu (ORCPT ); Fri, 4 Sep 2020 11:46:50 -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 7D082C06124F for ; Fri, 4 Sep 2020 08:46:43 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u18so6483429wmc.3 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=j4jMLsIVC4nzDgzI1WaoCeAaCEKs6LfAu4L7U7O7WOmaE5p5zXQhPHkYWISdbFbNGJ SJz0gQvlwSiaCqF9LyYIOysywv/254PvuIFx1aAYGBfJWIKu4QtOxT/bYFbJRCoWyQj9 O1UF2v3plEvLmLQIoWNyxvzqoeZzOGY1DZJvxKoO8bHwNbOCcX4ZRAxbkYWvLlEk5PVK Rykmdu4ibilm7y5HweF40OojVv2mpRo3NuRxEFUmJeZ8zbLFA69twwvuE8ieOxc1l99x BCF2SntGZUdYu2epAQbcijCTKxAYvnhR82bvdW0ZxyM7n7cEWFlmPD8oop5JnyB4rSaI QZ6w== X-Gm-Message-State: AOAM5307mFHPNIXOiZMnhhX+wISQ6PQ7Q/v0ZzQEVauBqGK4MwLEl6hY dbHDwGlZWsbEgT+1p1VYRMkiTw== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B75BD92C for ; Fri, 4 Sep 2020 15:49:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D9C620770 for ; Fri, 4 Sep 2020 15:49:47 +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 S1726726AbgIDPtg (ORCPT ); Fri, 4 Sep 2020 11:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726621AbgIDPqz (ORCPT ); Fri, 4 Sep 2020 11:46:55 -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 95295C0619C0 for ; Fri, 4 Sep 2020 08:46:44 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id s13so6473072wmh.4 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=T8id/yvYT6A5HDyKi+TS6aC4V7WfApnGYUh7aDdOZCoOnHy5hBh3QAVVAap6IK8Qxu xhE4lUlynxLuxz/IMMgyWk+M1rtCy9MTn6EJcCl8GBr9CB+brN4OOLcido/39vMzE/A7 sMB7wjpPo/pf+AYbS/0O1TjAQw+FQHlCyPFc0reiO6iIdgsVJhSHsn/k62LcaP+VqJ1G q9W20pl1vhVoBrVqepVSugL5V7ZYxHWLURJa/70kWQBA/DybX56RVrm+JQNwXeMMZXz8 bwFU2HdTXPpK8lpF32M14QQLv506w0b6i2Jyhahl3bxobrbh44ga7xWIrdkB/gfc9aGH j9mw== X-Gm-Message-State: AOAM533XlH421ena65YTY4AEYOam8PLvvqf24HEg7hLYrUtGYzo5cikZ QWDofWJmG6iDZMO21f659vwDfw== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 915C492C for ; Fri, 4 Sep 2020 15:49:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79B242074D for ; Fri, 4 Sep 2020 15:49:36 +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 S1726286AbgIDPtf (ORCPT ); Fri, 4 Sep 2020 11:49:35 -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 S1726937AbgIDPq5 (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 BC6C0C06125F for ; Fri, 4 Sep 2020 08:46:45 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id w5so7207526wrp.8 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=m19x2uwEdaNgOssY9oXVv9tWpVbgxeopgncf5bcr248/80g3PzCWx3ZuwIAyqfqLeB 5Z7gRH91vUwABYRaNX95XYs2Nokyhhf6VGrnWmHXjswBJDH/eEce8W2l/7L0sFYmZJ4C oJBmm0zQHwc+WZaVG/ZNm4UY1qlkBwg6mO3yAM9yCltdsywfjQogqPiiS00Lf/mXCXgF XgddhqVXiEVfqK2Yaa1vtd0Po7Z4Yjgzu4EEn3y6WWV01vb0DfctdIsmMEIl3y0mFwqt 1eSR00jcAuotEf/8t22FTachKrFIyhR5Z+NOPU27dS2ivhXPglTnwqEjn8UNxcWhSdgY AQWQ== X-Gm-Message-State: AOAM533akqAzfEamr1jwha+tsM6v8cNrhyMDSGezMwVr5H9qInciRrJ7 6mi7WW922O5utFgLkeSuk36Sgw== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757909 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1A3115AB for ; Fri, 4 Sep 2020 15:49:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB00120772 for ; Fri, 4 Sep 2020 15:49:18 +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 S1726063AbgIDPtR (ORCPT ); Fri, 4 Sep 2020 11:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgIDPq7 (ORCPT ); Fri, 4 Sep 2020 11:46:59 -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 B5F7EC0619C4 for ; Fri, 4 Sep 2020 08:46:46 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id o5so7155363wrn.13 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=XWKEsR1EwwvWL9h7i2/6iSvU0o43xS3VRMBsEdZD367Df3Qrbg7KtPayd/GEuvxSGv 3cof+fEDKPiOe1R4Lo8RCXAlsgEeA7nklLf3If6dDE/jFJGdIERCgRzYOxfZtqpmmd4b CQbXAOiRmg2NXV6vQBfL3fT7LmjSNH4SQIca29XcMVOtm22TdaxdolEP+1ZRSe5QLHLJ FT0KF8vFa6Ofx3zftt/b5iPdobldVA1cZDCPcaDRX+xIW0pBjsjz/D7KOZx9pDT5dSJg 5rIqwzL/qnu2lz+XuFJb7XOOf/vNfgqOLkhxCdeNcoqLt4cwsMx2BlcmY/slvBKDMJuS 8kfw== X-Gm-Message-State: AOAM533ocsCfb2VjhV8/pK76EDo/A+0zy0m1XpwCQXE7gg4KVEEuSbvB 0z8hctBT6oDT/rWlZS/EuFCPmg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 853EF92C for ; Fri, 4 Sep 2020 15:49:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 663F02074D for ; Fri, 4 Sep 2020 15:49:18 +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 S1727923AbgIDPtR (ORCPT ); Fri, 4 Sep 2020 11:49:17 -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 S1727004AbgIDPrD (ORCPT ); Fri, 4 Sep 2020 11:47:03 -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 1BCAFC0619C5 for ; Fri, 4 Sep 2020 08:46:48 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c15so7167154wrs.11 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=jPrsNffbQ5kWDczlO0E2B5FAL2xjT6StWnjUcFxsxGEtUSOSoFQSbxKmzbu5edryB5 QahDqBCP3Q4hdCK31wnOl0942EQIUGygZ4C2n5LAabLhWw4+F+6rbAiZTrSWGPDoVI0j UJljYfZwQ+SBF+7U7M8AaGbkFgUFgLnNYCPXgkQv40yhQ4xjYH+r+lec7N/4ez33EAg1 VIqL2yzm/Ps8/JlToo42jubOrxRK+zzgQ3+8j7fZPTNNg+Wua2SIBXNbbFfuXdqXSAhv mNumDqTkgHXwAsBm/Lnt5PXOJjAyxwLgt54tTklzTubzrdUXZTFW4zF+tecXQz5sA2eJ pU/A== X-Gm-Message-State: AOAM5311RnckSmJhh65RVnoENs2fAClfGbI/X2ghANT57Hho4XtNqdT+ AzfislA/rl+ohKn2giXAcTq41Q== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757905 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7157414EB for ; Fri, 4 Sep 2020 15:49:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E69C20772 for ; Fri, 4 Sep 2020 15:49:17 +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 S1727020AbgIDPtN (ORCPT ); Fri, 4 Sep 2020 11:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbgIDPrE (ORCPT ); Fri, 4 Sep 2020 11:47:04 -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 1DA31C061264 for ; Fri, 4 Sep 2020 08:46:49 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id o5so7155474wrn.13 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=aK2dUFfQpkDnGkWPow5KL746cpnNAqqrj+8449WCaYqtv9Lc08PNZa0wB+AfTqu8b9 gFy2rYmaruhBa94davq/51tO6OFllL3BFRGKDn0WJT4Jgu45Y+NsolyGU7sfR55qquZa vclTFfOYso14J6BNaouMY/EpSNFvnkGlBvGW3siWO8gjLmDBQ1mXbifTDwx7y8qBjleT zbWSlLJHmApik80LKyF+efL5VEP9ytIGsvgK8eo8ntRwE356rzO5erG+4O62ZHEUbXXU Rz3n2xj+rbpiyR/HzkmHFNiYAQQiyhNTX+fcDt2isF+n7JpPZrnVj6Kao0t0euN64W8I 4rzA== X-Gm-Message-State: AOAM532yxYw429fbo2SGEHV/PKllzjh2UY2r3zQvc7H1G4dTR03y4DOo zALFFGUlJtVsznvcWRu9TBzRoA== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757903 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 291D714EB for ; Fri, 4 Sep 2020 15:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A8242074D for ; Fri, 4 Sep 2020 15:49: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="RrJg++r4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727051AbgIDPtA (ORCPT ); Fri, 4 Sep 2020 11:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbgIDPrK (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 47AC4C0619CA for ; Fri, 4 Sep 2020 08:46:50 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id z9so6523571wmk.1 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=IToi6q2UvCBgQ5jVpSpEKEyGIHqjCmNcaj9qrJAiiwzh4tvL6XHoyz/G5F3rgkmWn7 TLtTNPW+kOEKnQ3Y5lIELjLeMVF7MDmh4B7JqcpelC1hJvgClcHSNnrwR0FKY4JnLynR mnt6YyGkBtCwxvVDGUgVJrH9mUkxl2xI3Bo3gOjsNay5bZZ6N6FUwcmnphE5aeqZ2oIg 0BzF1/Cu7wsd9RNt+wsnb+nPQ4cfqaZMHmdog5FqjzVCsFEN8KugdUZ5PF3fvZ82tKmw dd5z/YYH0+c5aw1/WkWBYF5YmukidU50/38darT0rPrtsJJm3WbV+VezX4F3GHrXKWUy LBNg== X-Gm-Message-State: AOAM530TKUdI8lzpDMVwofq+GNbGhKviAVpCRDSerNzRv7X+LSU+p/fT E82iowfrEQGwoeQeP5nwGd0vrQ== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D60492C for ; Fri, 4 Sep 2020 15:49:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A64F20772 for ; Fri, 4 Sep 2020 15:49:01 +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 S1726293AbgIDPs7 (ORCPT ); Fri, 4 Sep 2020 11:48:59 -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 S1727051AbgIDPrL (ORCPT ); Fri, 4 Sep 2020 11:47:11 -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 5B80AC0619CD for ; Fri, 4 Sep 2020 08:46:51 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id g4so7215393wrs.5 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=lp6bRSaUFjKImoFKG6kZuQnBfFJHpsdiaNVkSsxDJrwmxgXPTVTDuRBJ4feUueu5Y6 QmOBaobmtI84W+hAjKUfB6gN3R5972ou+PHF2g/wNuN0Rdz0E9DBhdslvo9i2hDeoSMm Y7/gEJJF4ioVRT21znuW1t3J0KpF7/5N1VC7ht/yxNjQOg96l8TqPayYC+/QbWX1Ik2O nn9i5hxQ4ZT8nLcly6FIjF6s5HBA5KkpYlpbCXoTJviwoPbX/grLKnM08ygLqnXpa2aV mjOD9yj8LvsceA3hHy13NQh7stKAMSupCWxTgrraQK1vtj8NuIo4HJyFuv/rsqycqTwk X4NQ== X-Gm-Message-State: AOAM531HEXA+Nl8ji2LyizwAbj4kwMjJQpgScx9HivXmdFYESs0tMu/q 1MyZ3rAnAc+Qc25t5+bfV0BpMQ== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F271D14EB for ; Fri, 4 Sep 2020 15:48:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA5A120770 for ; Fri, 4 Sep 2020 15:48:38 +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 S1727109AbgIDPsY (ORCPT ); Fri, 4 Sep 2020 11:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727081AbgIDPrP (ORCPT ); Fri, 4 Sep 2020 11:47:15 -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 86630C06121A for ; Fri, 4 Sep 2020 08:46:52 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l9so6513543wme.3 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=dA6MUmFvXddXWvdEgPQoKS66OUMRE3pv6EctQOUlf6baG4iK714K2P1cm+OqOdqDet 3s4V0RTATtCH/z8ESq4x3CQPVIyalZuTFDHzD4pSzOaUaNKysc0o/JwPa67eHsarSP53 KGyraV1HL292YBamez1wmT2oahj/2SEPbn+xCqipnpsXNtt3kiL26bPbpjNViyBGPACB VAJ2le84lKgqNdLwgBlYUHlEj6DiXQ6GZuFjbdVkwHJEjFYLPkfH8TAX+NF9VoxYDI7h AUFZD4CRLoYTbX4c5MwZOrsdBjnspFKDNOENQUH/7NKQ5wkgUI4AMe7vqkJsk8nsXheI 16FA== X-Gm-Message-State: AOAM53094JJqlwF2cEwv3oz39MXum3v3R0LhvyilJTo/WP9/zhsZmV4P m6vseBYokat+3Sv/+Q0rJvx/Pw== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D53D014EB for ; Fri, 4 Sep 2020 15:48:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCCB72074D for ; Fri, 4 Sep 2020 15:48:41 +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 S1726184AbgIDPsj (ORCPT ); Fri, 4 Sep 2020 11:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbgIDPrO (ORCPT ); Fri, 4 Sep 2020 11:47:14 -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 95A68C061233 for ; Fri, 4 Sep 2020 08:46:53 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id e17so6506329wme.0 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=TtiXpT5Q2YZkuyWlPDe+TXVAZaDk3VwnH3TVI03TjRWj3DpSFoYF2EE34DaLAu86wr 3VPg3moQx9QGxkdxu3DI13ATUIilWKqV60q7oBbxwWA7Klv3/5B5Xlx1Vyw9stsH1c6u 447PZoCU3huaN6dwr4KD/01s+t1StOn7UyMvRXYhpGWxTF62ipcSQmcIlASr0Vn5L6Ff u6J/qzJLryn3wy2+NV4zYT+GIu43rL41T/8y0D0IOcYHzHY1zAPtDNDTRvT1vZ12CwCo iCUfxmsS/GHlDvanSZOqoalwRFfi7jq1ScxpSfuOd3cp20Nuzo5zcbpZ4g7oB6rbnKn6 y4vQ== X-Gm-Message-State: AOAM5303QIvJhsx9dJJGPGs6fCSEw5U9k+1HqBOxFJRoz7FSc7gq8Tfs cAPjCae/LDdSSDqpxZJb+R5ebg== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9C5614EB for ; Fri, 4 Sep 2020 15:47:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B679207EA 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="Pph0ChKq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727794AbgIDPri (ORCPT ); Fri, 4 Sep 2020 11:47:38 -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 S1727019AbgIDPrR (ORCPT ); Fri, 4 Sep 2020 11:47:17 -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 B3E7FC0619D1 for ; Fri, 4 Sep 2020 08:46:54 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c18so7184205wrm.9 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=sZfiVD8XlqhEG+Kl3Iv/9BpZc3cafx3wkGZClRTF76rO6MlONYcpWy4DLMuPPEfb53 eptaZLLyokbgztqzAq4EIsqSh/bc4pfJSsqocKK2DTiw19rwuUrWJ+BPZ1xXd48cuUKF gEf2aom7E4KYATc9+nJDkZZFeAd4Os6se8FPYv3u3GQtZPaI1cUN4YnyL2gclxf3ZvIO tL9s0d+Bw04BhVW94yh3kO21/PuUXXdG41Sxr5E22jjRPjZ8VokjRFyG1NihQse1CRXi cs3VBgBErUSCRKAAAmG99S7BFNDzi4ibZSGcYAFqOB+hOcqS1e8Q20f444MIoXkEcT2u I/jg== X-Gm-Message-State: AOAM532teenSjfeyLIrU08tzDh1TDQX6THW5u2N3jycvsRrmfPPz9kJ9 dG6ZM0Q/aj0nsf2MqqUjF9qJ5A== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757895 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3B8292C for ; Fri, 4 Sep 2020 15:48:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C32720770 for ; Fri, 4 Sep 2020 15:48:39 +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 S1726399AbgIDPsX (ORCPT ); Fri, 4 Sep 2020 11:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727109AbgIDPrU (ORCPT ); Fri, 4 Sep 2020 11:47:20 -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 D5EF7C06123B for ; Fri, 4 Sep 2020 08:46:55 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id z1so7244925wrt.3 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=LJzlP2haZK8A2j7KHKcN+2ndWROW8YUx02IQg4+0Lx5JxGL5HKH9iDcIZfKdd1yVIm 7LQ9fcSoYEIfqF6LN1mDTRgp4TTf98OVhmDAVjbwR+2A72CQigYRkS30akKqHRdwkj2L hunXqGpf3ZcJChBdOqe6tJTmEnyn4Lj9QVaiL0/w0EnBOyo5odODWj5J9CsejLFwio6a VHXVbyH7hF9LrmvBALJdZUvnJPHq8MAJ5c+OYdMigHPmDHu9z8U0DgDaYqUcysJK6FWH 0h9+D7P9cgGPqFpng9tCsgqFW6C0cujoGsBtMeJfFnYTp4lnR0vQWqT6qqHjOq7aav+I +f9Q== X-Gm-Message-State: AOAM532GYAegdx74Dx5xt5+hwHoZ5y3spYt5Nj46tvjXqzCSEw5v8h1l sPUwlDRTsDDBQCBYhuasTS5e+w== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8128E14EB for ; Fri, 4 Sep 2020 15:48:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 690EA207EA for ; Fri, 4 Sep 2020 15:48:22 +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 S1727859AbgIDPsJ (ORCPT ); Fri, 4 Sep 2020 11:48:09 -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 S1727116AbgIDPrb (ORCPT ); Fri, 4 Sep 2020 11:47:31 -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 12110C06123A for ; Fri, 4 Sep 2020 08:46:57 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c18so7184318wrm.9 for ; Fri, 04 Sep 2020 08:46:56 -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=sB+jrRuRaQUztLK/ed3ASGIrhz001Bx4WSoUJGZs63nIGzMwWa4OANL/v6zhzkQZoP OvpVXU73DuOU1SB3FSp2rzamoy6q2OORHjJVT40blk7kUz7n4PwKGgS5dBNT0Yx7GNUK 1dEARXLqhvVTCwW4y9LMJPzJEA+2byZSzLKLoHT5eI9/CpB+RxDHts6yhEGXGKN+lSAG nMZZFPQ0VWpTBRkldzJ1dzQwlkHA7dxZerNZ+gi3+S/YeRzoJUvL2f3hDXXKhLtYEOiK B8zAA86C7v0rjxo1n2wZT2OutTMDjah4+VCHaFJwz9ftqjw3eKErcfJ0smxweuKgEh87 zIPw== X-Gm-Message-State: AOAM532AXdMcsKWAvu+xCg7UveICQZ9K7MJkOwH5nmM46zlptAzFwKLv mw00R8UdrSjmPZsWtFzmiKbKR2qgMvwmkw== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E47D192C 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 BF6C22074D 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 S1726267AbgIDPsI (ORCPT ); Fri, 4 Sep 2020 11:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbgIDPre (ORCPT ); Fri, 4 Sep 2020 11:47:34 -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 62CB3C0619EA for ; Fri, 4 Sep 2020 08:46:58 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u18so6484118wmc.3 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=R4mF9vEdjMAd5JPlhw2yVisZVh6Il3JQr92uk2ZBXihRORfpVOeznbzQJ7RGlVYssL 0WafNDQxbqmrrqAiz0UlS5QuL00JHAHVMwLb/R70qcVoieE3XnBOtwd0nfyUUcFh++ht 7pmMoaMw2MS+oE1Gzdj79KMWz5jee5j2tNPWRwBtNzZ8We2lCJbYRVodck1DthNP5UKT 7s8P6bk7fGFc2hmqd8TlijnRXOCy7mtO1V/Rj7HgFxIR3bY+e9Mdzz5O9QdADDBBJH5P SqZZdKf/5gQNB5hhe2vALcOFGbmaIec6XFxFiqEr90jZECDl24hrNhTI65+OZK7W8nTQ y+qA== X-Gm-Message-State: AOAM5313hNLrKDxzha7tcfgzVDXlzhZxtgrD8y2wPIAqZ8prrEwBcrKl BZEtbkUaw+Riejdv/i+2TD4x3g== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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: 11757883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74D9A14EB for ; Fri, 4 Sep 2020 15:47:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ACCE2074D for ; Fri, 4 Sep 2020 15:47:57 +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 S1726979AbgIDPr4 (ORCPT ); Fri, 4 Sep 2020 11:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727792AbgIDPrg (ORCPT ); Fri, 4 Sep 2020 11:47:36 -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 97F4BC0619ED for ; Fri, 4 Sep 2020 08:46:59 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id a9so6523679wmm.2 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=Y786tVgWdxSQza/NVYUZIloLt+sYXe67HKot8zPuAoVVgk7mjIeI5dZuSISR9uMX6l Pi6ATPxwW0lv6EZaxvCZ0fbImNX4UnhKA8MFW6e8W5hwwAQ4k8ehkGWFtUfyICysctL+ oO9U06xr0CDDtnWUcBYPH3tb7iD5FFw97VNAMIX662gqTuZmF2kbnk1bqXYQd5S2yhU5 XWA54KAZ3GXwWtyfnYTNCZgPT77ksz8j9aD/RDCaEYd/Nf5sPmo4hzPjCpoA/Hk6OmAP PKCtFhoVr2QLQ19+oowOBYLCTWxyAOwXmcYaxBRHIrt5ip/NI1dWtRoYUnbADIDO803X Tb/Q== X-Gm-Message-State: AOAM532R2i7WEeI+UTMA/8hjAbK5yDGB7g0yaSd1LL2+lS6mrITQRBTj 16o74IUCBPwS2MLa2E8x85jpMQ== 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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=