From patchwork Thu Sep 24 11:38: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: 293415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40EFDC4363D for ; Thu, 24 Sep 2020 11:38:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3AF72311B for ; Thu, 24 Sep 2020 11:38:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="a7KuNLrw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbgIXLiy (ORCPT ); Thu, 24 Sep 2020 07:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbgIXLiv (ORCPT ); Thu, 24 Sep 2020 07:38:51 -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 ED0BAC0613CE for ; Thu, 24 Sep 2020 04:38:50 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id x23so3176992wmi.3 for ; Thu, 24 Sep 2020 04:38: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=bCsr6AFFHdHhAugFVMGJohC8JN0hd4nL8k90M/6i7xA=; b=a7KuNLrwlM7cvptfMtEqtc5CpObOWJJFH9henQqs6idqfzL5qx7a9wLt2qGL4rT1Qz HutCQ1XrFdOs4pQA/nDIfdY6FMVAIEQsMDZlU5mc/CuxvUbDh/zIlSkAGsP6NFHhhnNd 4p6qhRDO0u8+AeeHYDV1nzUhpue9ar8pyt3JB0SRwKUyE3yfGvNtDXvkGzKkIQnMjJmI BXn0xVBLk0iwWyTAtoRm2eP+V4REcHuv7huXbBX3HW4qyd0PxDCNQAo6QX1K6rz6SS8y TFsyKVS7ba824hLFuu3AlRdnQMNyxc8FI06nsImBXaOtWSfuZWrgZvoGNTJFCAk3LEzO 8tRg== 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=bCsr6AFFHdHhAugFVMGJohC8JN0hd4nL8k90M/6i7xA=; b=oWkGOp26+Kapfnj/CW4EYd08McWsuQJVCq8INF34KR5iggsK/KSp44NugwJ7ep5ATL RTw1QfhJESzpx019QTULMxwhgp2/VeH/+fq3iFAYQNyZq4XxQHKBLbNebSdvZJo6NlU/ aDiXVxy66gtOYgjI9TBlVyqJEQDEL/NaIZl5kElCe8wssuEWLvUk+/GNpuOGs1QHNbSv NMHS4C6oRAlsBIAoz2Nx7ZXMMIZPKg+2KXpRcwgW40tmRPHK0OutGkxexpWHlW7YOIkb Yla+mVLhXAbDB0j6Nj370BuO5DvSPh2LomQpqS1NOFePJcS4e6Km1hfogHTgOajU+f+x XCPw== X-Gm-Message-State: AOAM53033RwMaYsUDQ0fkkWXTeV5u5iuzgGkcj/PddZy5pOmcqdw9ftw wsvvI1PTTDD8f7X0jbyMQ7S+nw== X-Google-Smtp-Source: ABdhPJyE32p6WO+xWXo7rVqwDl6I0AjipMB9OZdrBkbmGOJUcH79pPsUmdL65eiq3Ag6J9S6fIqm7g== X-Received: by 2002:a1c:b608:: with SMTP id g8mr4552385wmf.106.1600947529507; Thu, 24 Sep 2020 04:38:49 -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 y207sm3390133wmc.17.2020.09.24.04.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:48 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/9] lib: string_helpers: provide kfree_strarray() Date: Thu, 24 Sep 2020 13:38:34 +0200 Message-Id: <20200924113842.11670-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski There's a common pattern of dynamically allocating an array of char pointers and then also dynamically allocating each string in this array. Provide a helper for freeing such a string array with one call. Signed-off-by: Bartosz Golaszewski --- include/linux/string_helpers.h | 2 ++ lib/string_helpers.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 86f150c2a6b6..55b25120a1c6 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -94,4 +94,6 @@ char *kstrdup_quotable(const char *src, gfp_t gfp); char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); char *kstrdup_quotable_file(struct file *file, gfp_t gfp); +void kfree_strarray(char **str_array, size_t num_str); + #endif diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 963050c0283e..56c01ec8a076 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. + * + * Passing a non-null str_array and num_str == 0 as well as NULL str_array and + * num_str == 0 are valid use-cases. + */ +void kfree_strarray(char **str_array, size_t num_str) +{ + unsigned int i; + + for (i = 0; i < num_str; i++) + kfree(str_array[i]); + kfree(str_array); +} +EXPORT_SYMBOL_GPL(kfree_strarray); From patchwork Thu Sep 24 11:38: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: 293412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2554C4727E for ; Thu, 24 Sep 2020 11:39:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE28B238A1 for ; Thu, 24 Sep 2020 11:39:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="T1YaoAIm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727531AbgIXLiz (ORCPT ); Thu, 24 Sep 2020 07:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727486AbgIXLiw (ORCPT ); Thu, 24 Sep 2020 07:38:52 -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 0B389C0613D5 for ; Thu, 24 Sep 2020 04:38:52 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id e2so3255454wme.1 for ; Thu, 24 Sep 2020 04:38: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=wWev9UkO42jRbRsY5byu55gJ732xfhhQhwpq7S9JN7M=; b=T1YaoAImjSA161NmXY3XnIg49iksszJrPF7tIuhTP6ZjQyLkCtUpCIVYPuM7B5gDtP Eg3r8IJ05CSZzfhRTwA/pLsKI3xrHBgyD2apE5cHKuFnn25nkfmaMBAyAYiOWzlUKWth c3aT7cK/pyohmnLEKswYslvDsnt8tlOHlpQy2lz/TU7kQKYkvUHFT2spgiiDSWWaBpUx QavhMnjVSjHbPIB//Jvm621BvjHbGi4+i2felScgwDggQP5orDoulnqo0naDgqdOT6pP gHP3EvWXmadO3h7Lb2p0rJQkv2bnb8FtTmy2Imir1TslvCtFXv8xURbZrQs8mg440P3g RbmA== 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=wWev9UkO42jRbRsY5byu55gJ732xfhhQhwpq7S9JN7M=; b=WaOV7MDuIH5Kb/03ueqbHCfOxO7AIBXGRWDHQl0FAoMr1x289XQdI1gjQC5nFsA7T4 jJXnYelShi1aDxy23EPt2JWjXLT+frjdY24GyU/NZOXWevSfO2MPgpbEJgS0IiMNglEB TOhXYs+qSVloJi2OYYhfozPCvre4HxXUUkgr+FLluioOQHuRoIC0cNfCTr7Ukigd3ib1 msfTF+UR8DuRth4Wr8Us6xzBm+cNzZGFIldVccX0RLt4eAd2+NiShzsJF3W4ExcQsL3T s1DKjs15tb8W5Ru7sxa0uJ8sqmpZ4PFw888Fgf7gq3752pbfvi5+Tp6DPZBbe2/nE0eJ 2Qlg== X-Gm-Message-State: AOAM532h9mUzv0bUEz3XjK26/y6vpQ584iPXlmJGvbmJYW4o+rZe+oXX nPDWr7R8Mm8XIjOI8shC5Z+/eg== X-Google-Smtp-Source: ABdhPJwrt2MlBcTP0XgtXva4MaqZyVUSBZvDLONbzEc0v8hoFE43xWtvMIUuy+87Tt9DMBZB+1SbQg== X-Received: by 2002:a1c:1902:: with SMTP id 2mr4588867wmz.26.1600947530739; Thu, 24 Sep 2020 04:38: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 y207sm3390133wmc.17.2020.09.24.04.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:50 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/9] Documentation: gpio: add documentation for gpio-mockup Date: Thu, 24 Sep 2020 13:38:35 +0200 Message-Id: <20200924113842.11670-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski There's some documentation for gpio-mockup's debugfs interface in the driver's source but it's not much. Add proper documentation for this testing module. Signed-off-by: Bartosz Golaszewski --- .../admin-guide/gpio/gpio-mockup.rst | 50 +++++++++++++++++++ 1 file changed, 50 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..9fa1618b3adc --- /dev/null +++ b/Documentation/admin-guide/gpio/gpio-mockup.rst @@ -0,0 +1,50 @@ +.. 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. The lines exposed by these chips can be accessed +using the standard GPIO character device interface as well as manipulated +using the dedicated debugfs directory structure. + +Creating simulated chips using module params +-------------------------------------------- + +When loading the gpio-mockup driver a number of parameters can be passed to the +module. + + gpio_mockup_ranges + + This parameter takes an argument in the form of an array of integer + pairs. Each pair defines the base GPIO number (if any) and the number + of lines exposed by the chip. If the base GPIO is -1, the gpiolib + will assign it automatically. + + Example: gpio_mockup_ranges=-1,8,-1,16,405,4 + + The line above creates three chips. The first one will expose 8 lines, + the second 16 and the third 4. The base GPIO for the third chip is set + to 405 while for two first chips it will be assigned automatically. + + gpio_named_lines + + This parameter doesn't take any arguments. It lets the driver know that + GPIO lines exposed by it should be named. + + The name format is: gpio-mockup-X-Y where X is mockup chip's ID + and Y is the line offset. + +Manipulating simulated lines +---------------------------- + +Each mockup chip creates its own subdirectory in /sys/kernel/debug/gpio-mockup/. +The directory is named after the chip's label. A symlink is also created, named +after the chip's name, which points to the label directory. + +Inside each subdirectory, there's a separate attribute for each GPIO line. The +name of the attribute represents the line's offset in the chip. + +Reading from a line attribute returns the current value. Writing to it (0 or 1) +changes the configuration of the simulated pull-up/pull-down resistor +(1 - pull-up, 0 - pull-down). From patchwork Thu Sep 24 11:38: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: 293411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17C4DC4727D for ; Thu, 24 Sep 2020 11:39:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D39532344C for ; Thu, 24 Sep 2020 11:39:24 +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="wfm3BVCI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727522AbgIXLiy (ORCPT ); Thu, 24 Sep 2020 07:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727495AbgIXLiy (ORCPT ); Thu, 24 Sep 2020 07:38:54 -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 259A7C0613DA for ; Thu, 24 Sep 2020 04:38:53 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id d4so3174398wmd.5 for ; Thu, 24 Sep 2020 04:38: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=38tFXZO/xNQY1Ryhqk0ixri0sl8E4vYZ3bH752VHOf4=; b=wfm3BVCIiKYb0LwpFdvrg59EW2nWHfTOqaUFAj0qo+jC5BNKds3G1c0EYc3wc4Jvo9 qiTWqV8urdUlac6rowUlVB3KGHDQFXn9VyQZCFvIPQlNS1nRbDGDwtYIz2xWEtFdKWrB 3eqLRs639j5AVmluOUpY8cPNScQWZB+Btfi5XBRpnWBC9xBjNwZ9NNEaafEGiL+YYXzW 0TR2pR5H5hKhKk18KJVlRabUX83O2Muv34OPrV8zCUXFPIttKrYLHucMJ8FKmnjwaiLM UqoZiKh3t/nJM5pw4JF0MeTrAhAlVb9jDB8Y6fxJaRQqUzIoBpzJlaJ5dQMedFXna8c8 Sy4Q== 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=38tFXZO/xNQY1Ryhqk0ixri0sl8E4vYZ3bH752VHOf4=; b=rV/0QbimLjwpwE05gKoQOLaEY42qdHQvKY3Dy8WoWbxkf6MHdTJ4J7jWseSs3ctc3x whL+An2ysNtiZMAJHDfRbvV4uSQCWMknjaiQ86XAih6NaSZVZWIVCHzIUEQCFJAcY1bS cLZpgJFpQmyUzlo2OyV2jK6Ii5zRaLQdI1u6e3eNC0YZLS4L7pv8PMHcwI6k8uAWWEjp ZVxJi0v0Am7ljMo+FNUQqMENdj+1b4szMMMbHMWxbOlNgcpPfD5gLnJKP54ZYHSiYrW+ LRezImuIEr1A5k7k0f9cWB4iRk0PQ9E8+ou9+KeChH7teUAzs2qabDH0TI3hYZ6jNfdi dLSg== X-Gm-Message-State: AOAM533COIUleRikF9lJPGzR7+NcMriAnVrvriqhaujp8mRg5+VFphR2 F1yf9xm7acvKDijhlr2s2vDlphl/lKKevw== X-Google-Smtp-Source: ABdhPJxRA+J/+iFKjoXyeKGk7hmuTJJI3JDJ9FyrQ9bljbCM2utr8gxH3eRWMklqkS0jxniqYwv+0Q== X-Received: by 2002:a1c:3985:: with SMTP id g127mr4518078wma.32.1600947531822; Thu, 24 Sep 2020 04:38: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 y207sm3390133wmc.17.2020.09.24.04.38.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:51 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/9] gpio: mockup: drop unneeded includes Date: Thu, 24 Sep 2020 13:38:36 +0200 Message-Id: <20200924113842.11670-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This module doesn't need gpio/consumer.h - it's a provider. It also doesn't use any symbols from init.h so let's remove both includes. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 1652897fdf90..c5092773afd8 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 Thu Sep 24 11:38: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: 254336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 491F9C4363D for ; Thu, 24 Sep 2020 11:39:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11E252311B for ; Thu, 24 Sep 2020 11:39:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="vYnow2xo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727543AbgIXLiz (ORCPT ); Thu, 24 Sep 2020 07:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727520AbgIXLiy (ORCPT ); Thu, 24 Sep 2020 07:38:54 -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 2D36BC0613D3 for ; Thu, 24 Sep 2020 04:38:54 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id e17so3205122wme.0 for ; Thu, 24 Sep 2020 04:38: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=GvwtjhQCT62SYD+p95TQrRZLwK1iHvfvwiDgAUHz68Q=; b=vYnow2xo4MYAUf/BsQL3RQk7QB/rzmXGEs65ivwKMagzOf9IdjsWnroM4ll5Fr4k9t rpb5kNVC9Y4lUpbKJPZwp8zR8H/a4IIgkj6ehpG13bgwesam7LscKUz/wuF8pbhT0hPQ roUyq0wDT1iCuTcUHMl0/cTP3TSYMdNCfkC5HurdRDalG/FvookPRU71/7hmfV8RTe3p D5ZcQ3YQcLpsDp/stNL0L2xL5OvIo9/AxUawIka0BQoet1uEywxCiNYsQFIPRwrwJ6/c Ta0IjLq3U4SE+mg54TFXeVOyTonMIHf7UqRGEkwL428eKSR4NDakKkzlt+uG2LekdIhc GRxg== 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=GvwtjhQCT62SYD+p95TQrRZLwK1iHvfvwiDgAUHz68Q=; b=Ply3nZU7cyffN+hS9NymZVCltlNiu+G4s/Ci7hbE6W0bPS+RZtuG6uynZR5zx6WhXN g3/Iwoma8nXwEhkY/N+05L8k/nMMdi1rRNaOhkaW7RuMW35JrL1RmnyJWZBYtGgDeqzG xg2oK4jZTldJ8/auOT9tvTNP1Wm507CrLlOxj7033rmzxTt4z8HTvaA+Az/r1zd/fLSp Xohm2a7lFyBHMrWOxE+3LYul4uGqUwpTm6/LWjlwbR2c7KpOTIuqQjqAv1Q8eDdbJVmo kRlI0zJEIq3F1cvAUgaoW/kFFuNHHut8z5lhGUSduKzWYxteKtGN1bKcuP26w7hIj031 3Hew== X-Gm-Message-State: AOAM5317rhcs7/0FnS9wI3s9Bp1PIRB9k48aOhEaqvSq3O94Hk/oR5YK c9BWneIWx0BSlZWQdDmgOjBfYA== X-Google-Smtp-Source: ABdhPJyjqo45RuWdGkVSIpCBr8Qh6l0l2Gm7090fg4NRKWDcIXqa6i4PZS88V2nY8ytF/Vh5mGnjPg== X-Received: by 2002:a7b:c4d3:: with SMTP id g19mr4458961wmk.165.1600947532906; Thu, 24 Sep 2020 04:38: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 y207sm3390133wmc.17.2020.09.24.04.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:52 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/9] gpio: mockup: use KBUILD_MODNAME Date: Thu, 24 Sep 2020 13:38:37 +0200 Message-Id: <20200924113842.11670-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Drop the definition for the driver name. Let's use KBUILD_MODNAME for the log format and use the "gpio-mockup" value directly in the only place where it's relevant: in the name of the device. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index c5092773afd8..90a1d6c2775f 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -21,7 +21,6 @@ #include "gpiolib.h" -#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 @@ -31,7 +30,7 @@ /* Maximum of three properties + the sentinel. */ #define GPIO_MOCKUP_MAX_PROP 4 -#define gpio_mockup_err(...) pr_err(GPIO_MOCKUP_NAME ": " __VA_ARGS__) +#define gpio_mockup_err(...) pr_err(KBUILD_MODNAME ": " __VA_ARGS__) /* * struct gpio_pin_status - structure describing a GPIO status @@ -500,7 +499,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 Thu Sep 24 11:38: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: 293413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17287C2D0E2 for ; Thu, 24 Sep 2020 11:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD9142311B for ; Thu, 24 Sep 2020 11:39:14 +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="YV/LuNUt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727570AbgIXLjD (ORCPT ); Thu, 24 Sep 2020 07:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727486AbgIXLiz (ORCPT ); Thu, 24 Sep 2020 07:38:55 -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 52A59C0613D3 for ; Thu, 24 Sep 2020 04:38:55 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c18so3409033wrm.9 for ; Thu, 24 Sep 2020 04:38: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=n2JY4y6G63c9t0dZmNJwSFHTZrY4FxV2DVKIqjOIpiI=; b=YV/LuNUt0fhJH2foObHfKzWfOfdhPYcWnA1rrHzNF/tpNmRW20GHjlxS9Gwp/xAlTg GtejR+sGat1PNHMYNwBwuUwPX7lPEF6VRJcTjcRX1EgW8oogvtvGe+McNgDqL7A7tgvQ /GHwQqTkVIEGPGPSh+K8Mct+6HMQYxZXfQIBDyvrYbAyQT/Y29j599IfFQQnV3tCK9z0 6Y2/Fhua2YmuIJLElVQ2ZRQaawki/ftrrJr7QkjCcylejdP8rbDd5TAfEpk5wRfYrto6 KKV24Uz+GUsAMMMhf6+xt02kgmPK8GYI6nE58n7h9ZH4VzhgML9PkDwnrRaYYA5SByxW lIPA== 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=n2JY4y6G63c9t0dZmNJwSFHTZrY4FxV2DVKIqjOIpiI=; b=RhEzcMfVeS7oL6NtiCuCcjnekKy2t3u+oA0T+Iwtdz+kifb6jdyRU4mG1JjGzZbRYQ 8bZXGBkpFzLmyYc7JCQl5FkxtGUqV4TwgGxDkboy3Y9H7ckbYkPMrH5vub4upQa5SVbE JRNWmNETABZ3yJ1kdG1iTPO7gN0/fXiMDRgZ7VPOWkQZiP9IXhYvtMuE3di38lzpzt/B f4mDeDAjNex6m0wpO9RKNH1swvuTYo41QsYeY/DVRWsbW3vPUOaeIpiiCLCXu0azKpMW S6UTWufdXw3CDjsWFWvXSkibVnq3diKv2E3JcJv/q3WX0MhZd944sCGTn13elv55H0Qx njsA== X-Gm-Message-State: AOAM532HkknZG8oPXq5Bv+Vz1bju6/ZPFmXn03fMgr56LgBCdSqpterf HE+ZTHJ72Uul4seiaanmK08YWw== X-Google-Smtp-Source: ABdhPJxszIv5I6KqPwDcF9d4YVnuB60mUO54pGcBuSosO21bSkVQUUse+B0FadjwGM2oScQAdjMkHQ== X-Received: by 2002:adf:a29a:: with SMTP id s26mr4657115wra.197.1600947534010; Thu, 24 Sep 2020 04:38: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 y207sm3390133wmc.17.2020.09.24.04.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:53 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/9] gpio: mockup: use pr_fmt() Date: Thu, 24 Sep 2020 13:38:38 +0200 Message-Id: <20200924113842.11670-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We don't need a custom logging helper. Let's use the standard pr_fmt() macro which allows us to use all pr_*() routines with custom format. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 90a1d6c2775f..c2b2f7d5ff34 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -7,6 +7,8 @@ * Copyright (C) 2017 Bartosz Golaszewski */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -30,8 +32,6 @@ /* Maximum of three properties + the sentinel. */ #define GPIO_MOCKUP_MAX_PROP 4 -#define gpio_mockup_err(...) pr_err(KBUILD_MODNAME ": " __VA_ARGS__) - /* * struct gpio_pin_status - structure describing a GPIO status * @dir: Configures direction of gpio as "in" or "out" @@ -548,7 +548,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"); debugfs_remove_recursive(gpio_mockup_dbg_dir); return err; } @@ -577,7 +577,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(); debugfs_remove_recursive(gpio_mockup_dbg_dir); From patchwork Thu Sep 24 11:38: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: 254333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95A44C2D0E2 for ; Thu, 24 Sep 2020 11:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 477C82344C for ; Thu, 24 Sep 2020 11:39:24 +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="2JjxeELo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727589AbgIXLjU (ORCPT ); Thu, 24 Sep 2020 07:39:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbgIXLi4 (ORCPT ); Thu, 24 Sep 2020 07:38:56 -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 764A3C0613D3 for ; Thu, 24 Sep 2020 04:38:56 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id j2so3428948wrx.7 for ; Thu, 24 Sep 2020 04:38: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=LuUI/vBtXJYb5lrBsJkZLuZDFBHGHAPpV5LdIYhZxrs=; b=2JjxeELoVhjSUqUOW7Hu6PuV0/8XE4XmUTBlFiT4aHyPLH3ILia0DHWLU9WpRD3eug Doo0iZvPyOKNTkzuBT/+nSrDhyW88XNL87nw5LxG2PXW/Ae0KrCxn97v/wQnrmKOzLH0 X+TO0u9Ol4YBOS6q55foxfA/5VhgXEQzduJDQLlHFmK+onw5hakaKsbGSL1oaERfRso9 NBX+c9TQXF1G/y0nHUBQD0ZqPJx7JQucTZlwrMv9qJJC0rCeTbZStnwP5R7bQU6MQYDk WOfdAqF7vbxN7cZRJTw/Sk6hghgevmg1VltBZCYIRY+xoPngnXc1DevbLBCo12X1beo6 rOQw== 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=LuUI/vBtXJYb5lrBsJkZLuZDFBHGHAPpV5LdIYhZxrs=; b=PLg6aVCdxE3y0LLbaCjKrv9zE1oW73p4kjTAF4jBOelqfrGiXduG6FNCPSJ0ZySv/A BrC674ZT1NfuXLs80pq521RVxcTQCs8rIB10vWV24MpwAP2nuNezDufAqpo9XuC79jL9 F1PLterG3XiikRuod2TUUfZfkWSx73S5xJr4NRECUTl//0En0uFN8qVZIIFFEEthAi97 bQZ62uzObmC/T6vsFdiIbSeTlTPoICOLNlGMi347KEEc9G3bAyocj0zU1td6eOEtoaKX +oMiDoyQmCOjbQwO10bQEJOSCfPa6yELaZ+PXJrdB45i+RNSpaStICt3mC36wQclIKCZ 5ryQ== X-Gm-Message-State: AOAM530tzB5zqpFBoM34+TCe+HlGjxAM9uiQ52mx3qhUSuD1/WOdtyKT xEIP7XbKAnnXfXDalUOWc8AADg== X-Google-Smtp-Source: ABdhPJy+q9F2YZlBGvmByGUC6iWaNWXvBE+GDse+Zy2s8RdQcOenlSRQL9b4btXOvyH61NP89sCczw== X-Received: by 2002:adf:84c3:: with SMTP id 61mr4567912wrg.131.1600947535186; Thu, 24 Sep 2020 04:38: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 y207sm3390133wmc.17.2020.09.24.04.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:54 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 6/9] gpio: mockup: remove unneeded return statement Date: Thu, 24 Sep 2020 13:38:39 +0200 Message-Id: <20200924113842.11670-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski There's a return; at the end of a void function. This is not needed so remove it. 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 c2b2f7d5ff34..de778b52f355 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -372,8 +372,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev, debugfs_create_file(name, 0200, chip->dbg_dir, priv, &gpio_mockup_debugfs_ops); } - - return; } static int gpio_mockup_name_lines(struct device *dev, From patchwork Thu Sep 24 11:38: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: 293414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74D44C4727E for ; Thu, 24 Sep 2020 11:39:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 367AD2220D for ; Thu, 24 Sep 2020 11:39:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="r8b8KCmC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727590AbgIXLjD (ORCPT ); Thu, 24 Sep 2020 07:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727569AbgIXLjB (ORCPT ); Thu, 24 Sep 2020 07:39:01 -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 16912C0613D6 for ; Thu, 24 Sep 2020 04:39:01 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c18so3409352wrm.9 for ; Thu, 24 Sep 2020 04:39:01 -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=yQHFpzhsra7eF21NOHukB6Qo7UOtUhx3yAmCZtWq61g=; b=r8b8KCmCtWNNk5vpqJp3h6gV8JUjmH+9nkgQlRWIpvpCe15Egu+DmAzUrIe0+Yt96W Rij7NuiRrkA3uJ7qfOLBfpyvflwiXdGU3TxfNluhmbILQfpFYnkDj+8n7mrewCAafUvr /truc/o799wMS7i6DaMzbM1H/F4/u3uulFwzcrkGDiWOQ4LW8f53YwWnu33SoNbT4elg 4/tWzUdMAriSaZmVmogZOM9qD5aFcYT3/6SHnRktCdE0tNgZqKUbTdFyJWwo68d/8Yct oJcH35ymLp6PEkL/omBLkdbMfZ7Xxq/iD0Wr9cxKGVA/CM/JjjOMRhRpBl9LQkKJ04PJ CCNw== 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=yQHFpzhsra7eF21NOHukB6Qo7UOtUhx3yAmCZtWq61g=; b=bujozA157YcM8snEAxEd+hqveYDVfSEND5tTNLF3FxTGQzo9UZtB2yZwmZ3eRNzgsq H0g+1fWHwkTtSKvJFy1t6Gk1R8Q9jcfosaSIjrIi28qV5Yk2r/vXKjhdaDJLsP+V/7eO QJkeFKdHTBj0NQXCK8wXDXnmREdssLOZjsfH5nuijz9X/2Sg7H/CKw5IivK0w/CJ2kli TAPYYTHj6XXfi0XyYEISZki6J44j8Q8CBPN1GA0YAQNTLAf96hCCwOBYn8arGevHkNyo IWSUN7npXYcWrDRiY5XCPAv024JrynMEBSRZrxq/wvGgSFKg0Uv+rFZ1g81LTmDoD33t VACw== X-Gm-Message-State: AOAM530ukO/sR6BV+kPJorBo73P4+NVaIiYBGTscXbeZ2bR0YC7ELa9C TBnY2N3abmLD0exlAPpXG525PKd15M5vSw== X-Google-Smtp-Source: ABdhPJxGiaGWw+Oo0LZopqCdypwJOIA8psg2/o3jQx2VSOTghc7eAxRwv5BwZ+SEVu1hHvtfdhg5kQ== X-Received: by 2002:adf:a4cc:: with SMTP id h12mr4555529wrb.123.1600947539806; Thu, 24 Sep 2020 04:38:59 -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 y207sm3390133wmc.17.2020.09.24.04.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:38:59 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 7/9] gpio: mockup: pass the chip label as device property Date: Thu, 24 Sep 2020 13:38:40 +0200 Message-Id: <20200924113842.11670-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski While we do check the "chip-name" property in probe(), we never actually use it. Let's pass the chip label to the driver using device properties as we'll want to allow users to define their own once dynamically created chips are supported. The property is renamed to "chip-label" to not cause any confusion with the actual chip name which is of the form: "gpiochipX". If the "chip-label" property is missing, let's do what most devices in drivers/gpio/ do and use dev_name(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index de778b52f355..5b2686f9e07d 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -429,21 +429,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; @@ -523,6 +516,7 @@ static int __init gpio_mockup_init(void) int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; struct platform_device *pdev; + char chip_label[32]; u16 ngpio; if ((gpio_mockup_num_ranges < 2) || @@ -556,6 +550,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 Thu Sep 24 11:38: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: 254334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21483C2D0E2 for ; Thu, 24 Sep 2020 11:39:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D540C2311B for ; Thu, 24 Sep 2020 11:39: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="UFTTEf9B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727648AbgIXLjN (ORCPT ); Thu, 24 Sep 2020 07:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727584AbgIXLjD (ORCPT ); Thu, 24 Sep 2020 07:39:03 -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 40EC9C0613D3 for ; Thu, 24 Sep 2020 04:39:03 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id t10so3478138wrv.1 for ; Thu, 24 Sep 2020 04:39:03 -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=iVGXPtrofifr0EKk808e6soMrHsX0INLF+uZEESKl5Y=; b=UFTTEf9BWbHqjwQYp0mES49EUeBixSGdVgi1ewRSl//tj1LtzGRiw+vR4iGOClKzS4 i4a4/y5X9VHhYmOnX7mITKIMqprPZ41Ll/49iwUZaobJVdbN4CnYP3nhWj8ORFesschL l9/EY8fpds2AdnDtlrf/a2td8mWjIeya0OxRtHj5FM0FFSj8+FHsYsst3C2cRu2uOGG+ PEjg9stni/Mf0sdlBRB03Su1k/Ohi28pKZvBtssWzaDnTcWR7GdgUBxnDHVlHfIwAOgm Gbsj5K+I7+qVr2q2I07L2C5TOCldD1jwOQBer9XYCspKkWM6SdlRk5TV2YXYPNPshpc0 7B1g== 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=iVGXPtrofifr0EKk808e6soMrHsX0INLF+uZEESKl5Y=; b=c/Nch0QjMKWWTcPo407VgpT4CP2smww1yguFC74zkYyPzoXGyWCQT3+tWbNqPILEtM q3yIH0J9taeLRDAcNpusugs4segvso4aHra3tPoBfs52SZi0gaYqrjEOq4AZ3uYkSqZI pdFe4qxKGq5IweKkZZ+5bFtJ3MOSBVYjGbGjHk+oIt9//3fOoAn/yd9zmq9eDMtJIPGz TQNJ6s0aZFPdUHjOloChrW4dOLyMFuMAnmlXsujQgApjKe/i7RVZZAVxHOy7dg6TglVz NzDsdws567Xw0+MMaM4RAVvfGM+X0e+2BYxorEq4BxWQh9BfQQjYHNRMYgXsQY3tRlln KrRQ== X-Gm-Message-State: AOAM530IJfvde7iMwjLnSLrQNctEOaekTXiY3gegGWeoeKvXhSuSnEGt VCSt+M8WYd9bO8ss1NT/LTy7dw== X-Google-Smtp-Source: ABdhPJxGxR84Nk8fjH7RYULiM3zBKgyMncDKWHpAdpsN6n+vg2GyxsQnV1t0AHoqGHmupnWrxQxGJg== X-Received: by 2002:adf:b306:: with SMTP id j6mr4432039wrd.279.1600947541914; Thu, 24 Sep 2020 04:39:01 -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 y207sm3390133wmc.17.2020.09.24.04.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:39:01 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 8/9] gpio: mockup: use the generic 'gpio-line-names' property Date: Thu, 24 Sep 2020 13:38:41 +0200 Message-Id: <20200924113842.11670-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski GPIO line names are currently created by the driver from the chip label. We'll want to support custom formats for line names (for instance: to name all lines the same) for user-space tests so create them in the module init function and pass them to the driver using the standard 'gpio-line-names' property. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 70 +++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 5b2686f9e07d..c35fd05de395 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "gpiolib.h" @@ -374,29 +375,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev, } } -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; @@ -464,12 +442,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)) @@ -510,6 +482,27 @@ static void gpio_mockup_unregister_pdevs(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]; @@ -517,6 +510,7 @@ static int __init gpio_mockup_init(void) struct platform_device_info pdevinfo; struct platform_device *pdev; char chip_label[32]; + char **line_names; u16 ngpio; if ((gpio_mockup_num_ranges < 2) || @@ -549,6 +543,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'); @@ -564,15 +559,26 @@ 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) { + platform_driver_unregister(&gpio_mockup_driver); + gpio_mockup_unregister_pdevs(); + return -ENOMEM; + } + + properties[prop++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( + "gpio-line-names", + line_names, ngpio); + } pdevinfo.name = "gpio-mockup"; pdevinfo.id = i; pdevinfo.properties = properties; pdev = platform_device_register_full(&pdevinfo); + kfree_strarray(line_names, line_names ? ngpio : 0); if (IS_ERR(pdev)) { pr_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver); From patchwork Thu Sep 24 11:38: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: 254335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93FCEC4363D for ; Thu, 24 Sep 2020 11:39:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 595582344C for ; Thu, 24 Sep 2020 11:39: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="SLT/EHgS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727633AbgIXLjF (ORCPT ); Thu, 24 Sep 2020 07:39:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727617AbgIXLjE (ORCPT ); Thu, 24 Sep 2020 07:39:04 -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 7C423C0613CE for ; Thu, 24 Sep 2020 04:39:04 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id j2so3429367wrx.7 for ; Thu, 24 Sep 2020 04:39:04 -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=JGub3DzXhL7AkkI6iK+SL+4zKCGwxV6kIyrPE4bsyiY=; b=SLT/EHgSLvugpIfJOPkw+tO2fR6eaV03IDkcCh6puDqsCE52mI4xx0iLXRzlVE212Y fXQKbrNW5b+CmVuRwvmZDpea6wVt1//t3OsdZLK8hyBNmtdfF5tdzQu18bxQ8484fG+g q8z02hAuqdAFa3c0IqYMDagSBFatcLaQ4JH9+ervHXzTvKQ6tQMvnu3wB6r3bwcXOdtv NdcDNeoCNHhEJNhULzeFSz1KUXGmtf4CanAp6tTlEdDE82lLUEr+ixR3oP3vj+i+ZgYU EZbYqXG/scstrg6SqDGri3qay6PS+OLK+7lX5drQd3UgOv2DvQ9KtgIrsqe0UkOrStmD 7lVw== 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=JGub3DzXhL7AkkI6iK+SL+4zKCGwxV6kIyrPE4bsyiY=; b=UISf7n/iQVzDxY03Ieqt8xFXErX8f5LbKDw8A2lEOSU5SUp+TNoRGdZBBqglCjSQSy Krbc2UTdiqs9gkM45NnvQ31kYx+L8yk7b3i8Fw+Va+ZwBw7ezFA/ZMqsfgdpTuHWlW9r SfSqqQ5jsx3Ss2rjZBSZem+IleqrcoYOGqnai/OaVTgmdD+IIaNBuVBc+YYSRVvAEYoT gDoiC13BL3i4yoGuWfZmcLeOm/cmsJRotqCqPfFG+Tru2BIx7J7RgsEtzXYxNIVG4l4L LR9EQ6FalUo9kCYwLFs3WnBd0zAh+OMDtuRrUfxhNKXuVFb++RNO0PZ4c/p5jy+gsj0b O9yw== X-Gm-Message-State: AOAM533t0iVpFzbShDVFhpafT58fAheCo1M7+zJp9qxONRBH1PgFN6H/ Deve1EYY8rtfpvmJ7i/sQW+odA== X-Google-Smtp-Source: ABdhPJwRRHKuPOnQPU5XvgVnwnnUf+lAuiTXOzt+of8grtjvRhvSYM0OgF6GJfQq0ans8+65ykY0pg== X-Received: by 2002:adf:84c3:: with SMTP id 61mr4568421wrg.131.1600947543143; Thu, 24 Sep 2020 04:39:03 -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 y207sm3390133wmc.17.2020.09.24.04.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:39:02 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 9/9] gpio: mockup: refactor the module init function Date: Thu, 24 Sep 2020 13:38:42 +0200 Message-Id: <20200924113842.11670-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Let's move the code preparing the device properties into a separate routine. This has the advantage of simplifying the error handling and makes the indentation less deep. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 96 +++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index c35fd05de395..e2285f4330dd 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -503,16 +503,59 @@ 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_chip(int idx) { struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; - int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; struct platform_device *pdev; + char **line_names = NULL; char chip_label[32]; - char **line_names; + int prop = 0, base; u16 ngpio; + memset(properties, 0, sizeof(properties)); + memset(&pdevinfo, 0, sizeof(pdevinfo)); + + 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); + } + + pdevinfo.name = "gpio-mockup"; + pdevinfo.id = idx; + pdevinfo.properties = properties; + + pdev = platform_device_register_full(&pdevinfo); + kfree_strarray(line_names, line_names ? ngpio : 0); + if (IS_ERR(pdev)) { + pr_err("error registering device"); + return PTR_ERR(pdev); + } + + gpio_mockup_pdevs[idx] = pdev; + + return 0; +} + +static int __init gpio_mockup_init(void) +{ + int i, num_chips, err; + if ((gpio_mockup_num_ranges < 2) || (gpio_mockup_num_ranges % 2) || (gpio_mockup_num_ranges > GPIO_MOCKUP_MAX_RANGES)) @@ -540,54 +583,13 @@ static int __init gpio_mockup_init(void) } 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) { - platform_driver_unregister(&gpio_mockup_driver); - gpio_mockup_unregister_pdevs(); - return -ENOMEM; - } - - properties[prop++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( - "gpio-line-names", - line_names, ngpio); - } - - pdevinfo.name = "gpio-mockup"; - pdevinfo.id = i; - pdevinfo.properties = properties; - - pdev = platform_device_register_full(&pdevinfo); - kfree_strarray(line_names, line_names ? ngpio : 0); - if (IS_ERR(pdev)) { - pr_err("error registering device"); + err = gpio_mockup_register_chip(i); + if (err) { platform_driver_unregister(&gpio_mockup_driver); gpio_mockup_unregister_pdevs(); debugfs_remove_recursive(gpio_mockup_dbg_dir); - return PTR_ERR(pdev); + return err; } - - gpio_mockup_pdevs[i] = pdev; } return 0;