From patchwork Mon Sep 28 10:41: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: 254309 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 9EE61C2D0A8 for ; Mon, 28 Sep 2020 10:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C5882080A for ; Mon, 28 Sep 2020 10:42:07 +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="YJAh43x/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726564AbgI1KmD (ORCPT ); Mon, 28 Sep 2020 06:42:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbgI1KmC (ORCPT ); Mon, 28 Sep 2020 06:42:02 -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 076BAC0613D0 for ; Mon, 28 Sep 2020 03:42:02 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id e2so641270wme.1 for ; Mon, 28 Sep 2020 03:42: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=HJxyTfrnsVopFxd6wdGP2V3s+TOdQlFPIRoGsXdX7TI=; b=YJAh43x/7YALxC/MBRgMjoUjy6KvQ5nmSmrWAGPSmA8CAoFN5Z9yjKirb0OgckpsFV 73MiUBgz7Pn72N3e9mhgzfl+1RCg3XYEG/Y6rkCEdgw470cAAdiC8Rdbn3FsyQFQiK0k 07llSY+rmGXla/Aveg5uqpnSjiFD7z3gHt1mqVu6SeeyZf8fGNPqYmUN4Bkyp4bQy2bB jvosPX+57HkMBh9MRtLBOX69kMEZjfM1q6DoSZs2TpfgnMTHDEpDG883o8im78mzWBNt 5rAzy6321VEl/nGT26MbNWLxT24mYsF9z17KcJwVusGlqbswauol094nkEeCee9S9YUs D5/w== 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=HJxyTfrnsVopFxd6wdGP2V3s+TOdQlFPIRoGsXdX7TI=; b=CTxUPWqhIhOHhBmTm+ddRgTLuftMPY7JANsALGxWHfr3Zvf2/Jrk2If2AnU4pACCgK H4gxrwdcrP0S261dpVAqoce1zZjLmplvC+t5wtCiz8/FEQzAB81NTaPncEq5mvT85QyM s3aXfTpN7jpvylMgfoKEBCmQRHW01gZlXVxvQu5QXJk8afh1V3tS5XQBls7dAK76VkGB TsNhD+LhWdAobtLSpyiCduE3Stlk/GJx6lHjiZrp9TjbxXG7jvcykmlIxIrDGBotJkRy rcrqLmfQUCilX8X4uGWyjzjEfPsG4EaUZsCVVaBwUEhukgFkUt6nMXHvdWY0iNtWnzXF P3fg== X-Gm-Message-State: AOAM531+o8svJ6Rh/8c3/0vFkyfnDPOQOYqRVcUPA988bio05I1I/vwC jv5byLfi+EWuSXQ197S3mVVQfA== X-Google-Smtp-Source: ABdhPJy7HYyDOpIMIkwKLN/DnCF60YJUQIIpnG0t84ueEj63J6ApVr2I3i9LXCoZK5i6kHETvL2NYA== X-Received: by 2002:a7b:c387:: with SMTP id s7mr910311wmj.171.1601289720594; Mon, 28 Sep 2020 03:42:00 -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 f14sm939258wrt.53.2020.09.28.03.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:00 -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 v2 1/9] lib: string_helpers: provide kfree_strarray() Date: Mon, 28 Sep 2020 12:41:47 +0200 Message-Id: <20200928104155.7385-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- include/linux/string_helpers.h | 2 ++ lib/string_helpers.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 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..bfa4c9f3ca0a 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -649,3 +649,28 @@ 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 + * are valid use-cases. + */ +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 Mon Sep 28 10:41:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 285668 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 BEE4DC2D0A8 for ; Mon, 28 Sep 2020 10:42:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85FAD2080A for ; Mon, 28 Sep 2020 10:42:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="g25S92Gz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726630AbgI1KmJ (ORCPT ); Mon, 28 Sep 2020 06:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726566AbgI1KmD (ORCPT ); Mon, 28 Sep 2020 06:42:03 -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 13896C061755 for ; Mon, 28 Sep 2020 03:42:03 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id k18so621789wmj.5 for ; Mon, 28 Sep 2020 03:42: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=BgQC3n53i35n7GC4c6lOV6W434EKfBGkaRy/2vzORco=; b=g25S92GzFTtlvrXh1qKrS/Vwlmclx80rOqSPIoXFYXySdro3WbP05KxXTAPR6v3exM ktTM+IJme5cRnb4LbYPLmz1mXORBY7M91DOyzGSbReyWETCpIyAfMA1stxJJLtDtxYak OdXu930qd9y3kFxYNsvMaDZN1sUYXRasTgjeflLvqROirlEIEi47pdPrdolGMO9W2Mfl saNiCjsYw3hpDcf052MHVKMu6/CP3RWUrd42qbQ+WEMUe49rppw728yuoFN9a1iTi/25 EGAsht8jzipIbdyIVTys8PMyYmtjgtrJjoL3DwTLRgFqB4fNUsT6bnABqUL1G+AtQitg uhOg== 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=BgQC3n53i35n7GC4c6lOV6W434EKfBGkaRy/2vzORco=; b=Qy3XvgPAyc3kft9hRlFBg0FxN8g/sM00aAqHSnFZ87M1KeDG3INkMyG24003gDFemX lW1tX7IgbuVsqT/0nsY6QWOyJTKDk3sedl5srXecg1Mg1Kse9e5c+a1h2Fb6FRfTTGDA VkHvzwMfUwuB4lBSA5wcoC4msx1Vvl3z8Jlwxx74eoTS47Dm/bprJX0Nc5L2DXKx6wB2 OqfbiYRPdS0AS92Q6aeB7G0bub0USy42DwYQQ98H4le6C14YEVlahJIZrC976WE5pSmS eha9l1dwyLF6IJy1FUBQLu7o3q2GzsaEuOMcguQpw8g4JKUQVJzxXEXZLR9Av1KaV6ys T9fg== X-Gm-Message-State: AOAM532VsNuGet4T6sLODHcod7FEethVntQJo8a+QAeGWTHUgzYC+XdO L/5/t7UFxOuETOPT5oJUeGpxNg== X-Google-Smtp-Source: ABdhPJzuoHu8hiPRyruz0R0GxX7FPtBX6BtsAj+v2MOxtfNzI1H20bJDYnfNZISzWIcqTHi2x057Ug== X-Received: by 2002:a1c:544c:: with SMTP id p12mr963978wmi.170.1601289721775; Mon, 28 Sep 2020 03:42: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 f14sm939258wrt.53.2020.09.28.03.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42: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 v2 2/9] Documentation: gpio: add documentation for gpio-mockup Date: Mon, 28 Sep 2020 12:41:48 +0200 Message-Id: <20200928104155.7385-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- .../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 Mon Sep 28 10:41:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254305 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 9AE20C4741F for ; Mon, 28 Sep 2020 10:42:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5169B21531 for ; Mon, 28 Sep 2020 10:42:42 +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="ScYcOk2g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgI1Kml (ORCPT ); Mon, 28 Sep 2020 06:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbgI1KmE (ORCPT ); Mon, 28 Sep 2020 06:42:04 -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 13FA7C0613D3 for ; Mon, 28 Sep 2020 03:42:04 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l15so4078250wmh.1 for ; Mon, 28 Sep 2020 03:42: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=zg75WLPDLUTD/dO6gE79rZ4YNo3MHudSB6Cl7I/Dq3Q=; b=ScYcOk2gYrPUF+aDftw5XnbeNkA0ruf2onhIh0ABlCuUjDkJDerZAn7q1QXNQ1RNrW B48J7+lPhjb4yeERjOnSs3arx8Mrld4olbl9cBlF+e7u8ecfH6qBSVCue/4dr6a6ddQE cvWP19IelW8Gwd6omyP5cGFLQ1g7P8VSpQJanly6F+bAbfuto0XFUSVFjX8zffy5XwaQ 5ent6yYRAXC+tM/uhwc+/7Ya5fSsB4HcC2s5SOr1hiirYTzh+y6CXBgoZDyAkNLdpoP2 N/xUrI8qDX3nd2aJ9j6OWgBuf1753b7p7OJRE6tLuwIKDccOp7tT28qQOSxWdCyP+9qd up9w== 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=zg75WLPDLUTD/dO6gE79rZ4YNo3MHudSB6Cl7I/Dq3Q=; b=rTM1EOra+a6EQsY18F6rInaImWwmuiK19FOU/YXFEb01HOw5WH34dW9gFG5NYbwpsw DWvXzNaveNquiJIC7WeCRf1P3IM2M3SOfc4ttBQpM4DISWa7EDLS5YHuIh+mvACim5Oo gTJh6YZs7nxslR4rReS0ETu28mx3M/KY8PctcX9k1603qi2o5lR8E7n6/b+V59w7JRaC 1jG59iW4OlPaagl1JBT+0ZS9JGKTbc8X45AsEUbWmH+X+wlm3LTP0V3UhB38YJN35xjt yfo7fZuKxgD1Y6wfyAfKkWFCYbqixLOnxClJO3TSiYmIzUvTlJB7ALF37E9Yzl4RhSHc eQIg== X-Gm-Message-State: AOAM530NJf4v+29Aowdo1Amwpd3xrxPhs2bJhNzqiC5ouglkqz8o2pwx 2CFkclFszQ6GvDBn5NfQysGXlQ== X-Google-Smtp-Source: ABdhPJxnb9lRsJOBi124nd5PEFi5RPTF9+iWsUyLiJLnsQi4cRUlKeW5N7Q2dB1SEdnBlCLzwXmR5g== X-Received: by 2002:a1c:2903:: with SMTP id p3mr986048wmp.170.1601289722823; Mon, 28 Sep 2020 03:42:02 -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 f14sm939258wrt.53.2020.09.28.03.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42: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 v2 3/9] gpio: mockup: drop unneeded includes Date: Mon, 28 Sep 2020 12:41:49 +0200 Message-Id: <20200928104155.7385-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- 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 Mon Sep 28 10:41:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 285665 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 4CF60C2D0A8 for ; Mon, 28 Sep 2020 10:42:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0D7E2080A for ; Mon, 28 Sep 2020 10:42: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="wW9p0ooF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726773AbgI1Kml (ORCPT ); Mon, 28 Sep 2020 06:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726600AbgI1KmJ (ORCPT ); Mon, 28 Sep 2020 06:42:09 -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 3F92CC0613D7 for ; Mon, 28 Sep 2020 03:42:05 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id e11so4079413wme.0 for ; Mon, 28 Sep 2020 03:42:05 -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=3rBuEbcYA2LHM9EtzTttUwU6XI5h8fPFHgRL7rmnAS0=; b=wW9p0ooFod3Bkjml4TY027l7RNbvLUML7kxvbOo9bzSOOntEK2jCMJxDR38WyLDSMt 6r8tTb8wwE4Yp5tNej41crQLAPiH4p05LliJKqKB76w/y+7rIEYpcwKNgBjAhkOdTMg3 gwaAYBty7mKHxoBWxJaNrFejILAEEQFGvnLvl+cw7oIsTKdPkTcuoHd54jqw3eVC1b72 YkRdyvMfYpeAggJ6TeNSkLn8DhC2Qw2KuDUlDHrAbzgL+U01HRFE9gT158HhLUO0bjmX /S3OS2onmluX6QhO7vFsGuQ1ifHa6Ov0Pmh1p4NGn3Efhj2JLnPnWefFZ3JQnnjBC30L 7wgQ== 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=3rBuEbcYA2LHM9EtzTttUwU6XI5h8fPFHgRL7rmnAS0=; b=lhY5SBcTjadoZsTg1Cnrmz2eyqcT3naFw57GiD3LuyO/PpxP6ndT/0ftXVFHq5HGaG MbuOaNIiBwxE5AvtLuxLvaL0FX2PgnreOu5azegG5ovXtdaZA5OQZj7DVKX+PAWT8VC1 YO2AS9J0Ki/ckaHxUxYml6QZfx6Wwwj7mo/xawq43DxBt/LOdoRhUzzDkAmDoTPHudYd vMjP7dBnLWRgLsP5vgUfWhIwIwDWwiUr+j6CyU09JukWLJ7uR647Jmdh4gy4m6kmATBM 3Kbqd1NDtVQZy+zRTQkikax2ooIXbBbxN6mfeuI+ZMEIBGWrfBxb/b2YRCWNg0KZhnJA e01Q== X-Gm-Message-State: AOAM531opOEFtUkIkYGuAbkhSuL1uRZt9PJO1ljaoTq9LqF8xyAOfdA7 hWmcpA2c35bwk4Yb0V/llLjOhg== X-Google-Smtp-Source: ABdhPJzyLRcVrBW44bJaSnnG566begqm8JyC9mmAB8rWWDBs6CR4oZHMwIpQcBj0Q1o+qFGt6g/x8Q== X-Received: by 2002:a1c:4303:: with SMTP id q3mr954114wma.158.1601289723948; Mon, 28 Sep 2020 03:42: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 f14sm939258wrt.53.2020.09.28.03.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:03 -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 v2 4/9] gpio: mockup: use KBUILD_MODNAME Date: Mon, 28 Sep 2020 12:41:50 +0200 Message-Id: <20200928104155.7385-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- 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 Mon Sep 28 10:41:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 285666 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 37EBAC4741F for ; Mon, 28 Sep 2020 10:42:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFCD221775 for ; Mon, 28 Sep 2020 10:42:28 +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="a5ghI0fL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726614AbgI1Km2 (ORCPT ); Mon, 28 Sep 2020 06:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726607AbgI1KmJ (ORCPT ); Mon, 28 Sep 2020 06:42:09 -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 6BAFDC0613D9 for ; Mon, 28 Sep 2020 03:42:06 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id a9so641718wmm.2 for ; Mon, 28 Sep 2020 03:42:06 -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=9OHLxj5LKThNKX3AdZ96/ghdViR26xgQsL7zhp/+aDs=; b=a5ghI0fLgsfZKabmY7q23//OX5oPw2iffveHVQ71bkjGVVICZKZ17FxZGZCoYb1D30 hddl2lKzBQFamZTmMVG3n7p0Zs0/v6UBj/vSryoXw1wc1ZcA36pEWjhUBOa7ZD01L6cu EDHNit98fpoeDsy9F+TmaNP9mMQHlt14cJVNwEUJqjqmzodnuRQUPiKMiER95nW+yFkA 5FfIOoUthFQb9fX0KBbqlQnHnj7Yv13lyWOs8+H4V2T9n1ZRcWYLkAWUfmoc15nMhHEC FByGJR4jVd/F2rXJY46vesVPjgQlYYr+LVmmWL0fQ8F2rwQk29Azjd+Pz7eBnvbjiNVh McgQ== 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=9OHLxj5LKThNKX3AdZ96/ghdViR26xgQsL7zhp/+aDs=; b=isHIZBTLMXV8+HnNJqfGK2QlkZ+vBPBTzMeGn2pUY8gVmPwVnuH9BAgQa9jURjitJp XC3q3VymmXaTLJY7ivYPsZgmmSVi1gJKP3KNk4fLrsEVIJNY2AtVIlM39tqtY4zCpUMm R2JIhZPlFkazU99bBUsaIEx9PkB05hbGNDup9PZS+SSwEk9tokwhuv77juW+jj2bG2E8 jH/wk9dyl3wtJ6zHbaVkika3cq+SlejZpd6JhcfDewMofT5M+0muNNDBrd9Mh5Y42ZZ4 EawodPkXSbZriDSOBb+19XE3doohjhCtRTSM5U2l6dzBpja+2aNRLJp5kmCTshIaBdIf pu8g== X-Gm-Message-State: AOAM5336vN9o3l8tCbyeYLXt5oXrSxINUtEcSnoC1LY9yfwOt4S1DnTf YRcrKWFaF7eE6KFv61hrDESsZg== X-Google-Smtp-Source: ABdhPJwnSwPvU4Rl2Aysgxa3ibHM8/8y6qDuUcA7Zu4ElxXOmY/yIYDsD3cAgYZQ66J8Rgwz1J0yfw== X-Received: by 2002:a7b:cc84:: with SMTP id p4mr1008856wma.58.1601289725175; Mon, 28 Sep 2020 03:42:05 -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 f14sm939258wrt.53.2020.09.28.03.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:04 -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 v2 5/9] gpio: mockup: use pr_fmt() Date: Mon, 28 Sep 2020 12:41:51 +0200 Message-Id: <20200928104155.7385-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- 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 Mon Sep 28 10:41:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254308 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 5F8B0C4741F for ; Mon, 28 Sep 2020 10:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22E7821548 for ; Mon, 28 Sep 2020 10:42:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="vNIfUXVV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbgI1KmK (ORCPT ); Mon, 28 Sep 2020 06:42:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgI1KmJ (ORCPT ); Mon, 28 Sep 2020 06:42:09 -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 3D766C0613DB for ; Mon, 28 Sep 2020 03:42:08 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id v12so634785wmh.3 for ; Mon, 28 Sep 2020 03:42:08 -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=1YXp6sKFkcXTnpolw457jZq5A6kI2Z1eojr6/yOZQYQ=; b=vNIfUXVVyoXDF3umKSsKVBddWePCozTPG5ZzyeBjzZ34nAwMZRiRo7CkupgjKqL2lP 4GmsanTd8x1Eb9jZCwA1h1QNEjvcKquIVW9e9ZV0kiubuGvQch5daq3cvyC6A05BhxRc fZEUyRAk6HOGKS8KL3OVg48iz39XiuLbNpqnnnoXce3L6VERVqiGirah6zqCoMmnY5Lq nl/IjL7CHR7HANLCBLKwy651j3igv0QrU+4xRIQjArVe8cPkQR3t1cEZoNagi3mOISBp a5nd8W4jaH+uHWghljLqX16U/CE7Wl4adi4SydwTKJH3xNZ8Q4fFA7X8NaodN4OESkuS CAuQ== 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=1YXp6sKFkcXTnpolw457jZq5A6kI2Z1eojr6/yOZQYQ=; b=hoIWidRuNgY58dOXvznwHotabc1urq3ZSMRzsvTLQFRXw28Sa+XSRwwdg0/avVlzdl LNT2BtTJoNzc5AI58U7/t4zp+ifDB8dHPOp3hGVB3OL6bI3x9GVxqy6eXMu8VusGYRo6 dArlM34XndlGQGKF/qH7Rt2aeib7lQKF6RhWLJ2BK/LHGY2BWY3mY5sZ1DF6UdPOszlB xGnw97lwE62qHkI7lqyyc9BFgyObVu+GmDyXGm31uiifF9NUnXbwSRHQ0Suyl71Al2M1 RDcXyKLld2MKwDb3erub9uI8Js356l6/j8KzQRkNC3GBIED9SGbMFmh8rBxjHfqLEnPE cpJw== X-Gm-Message-State: AOAM530mhK1lsWczSYl7KNd/Bxdr+xMuYEp5juc9aBXvOZcprKvSJg6A +PHNsEPBLtToinVPiNe56kEsfw== X-Google-Smtp-Source: ABdhPJwm/5yfZIU5/UeaMe5AmGIJAnRbOKvN85ev4Jzz8RSD5ORDHUPuI/APLpFiCoNGFVCGbbEvCg== X-Received: by 2002:a05:600c:21c4:: with SMTP id x4mr958052wmj.107.1601289726952; Mon, 28 Sep 2020 03:42:06 -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 f14sm939258wrt.53.2020.09.28.03.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:05 -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 v2 6/9] gpio: mockup: remove unneeded return statement Date: Mon, 28 Sep 2020 12:41:52 +0200 Message-Id: <20200928104155.7385-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- 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 Mon Sep 28 10:41:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254307 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 B67E9C4727F for ; Mon, 28 Sep 2020 10:42:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 732222080A for ; Mon, 28 Sep 2020 10:42:28 +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="M3VrScx8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbgI1Km1 (ORCPT ); Mon, 28 Sep 2020 06:42:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbgI1KmJ (ORCPT ); Mon, 28 Sep 2020 06:42:09 -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 41B52C061755 for ; Mon, 28 Sep 2020 03:42:09 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id s13so588965wmh.4 for ; Mon, 28 Sep 2020 03:42:09 -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=M3VrScx83cIf9TdOKfJkxcCgoTVUURV9fTusoQNJllZ20fwAhw3fNXK4nS/dMeO5Kt UChDVYnj1tvBAYpAby1GSsojzjdMQPXJFfLuxQvlvMgHrPm+OsNHB0Lm3aIdeLEdLohG 5LEZxvesQ3CgzaXepH2auWfMCGsI/YT0Dz3RewkJ6CiWBiXSl6pm5hyjj4XpGewnZw9n mkh+RLTVuhDswiB5ZI+UbeCxV7Rx7h/5SogblQf93ngEg1g7mek7jY5HqZQtS9gJVLqk eo6K4TosxmroAKtjKWfEQVlnwvA6KFnfgOevU3RLvKvdrOvDdMIXJ6cuLUY6Oxdyc1vj wyJg== 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=klf/LQMZEOvhGlJQxjFJgmi1QdqtetzysjLQfnVGHHeAoWb5BKN7G1IisWPq6yrhD8 QzDVSb6xUC5gorz3R2crrg9W9GiwDa1iYpZCmcuYZQAcBiYi2E/qmHWXfjnwI4QsD9eW lYb2GaD0iYfFyhBXUiayGL2JO0EqrJ7Bt7fNXne8kciCnzkuP0/uzYhuQko+yuT8+xXW NrpT0jP8z2Z4nvtQ1tQwvC7S5GyKz2PT8MRPoBJlBhTkxJwf90KCXlVsdwmjTFE4JqDA vBImudMWUbTXY1R+RhjvkRFAACLIeUa1EXGGL8k7PR/oOoJkFR+BsEgA3ai4KjzlZqCu wCdQ== X-Gm-Message-State: AOAM531WXfskiRcqoZjvXq6CJtHqpOtE1seYwfJA+2iFEILFEosoL+VL yO75H3TWV19lp2bA1bf8Zw8YtA== X-Google-Smtp-Source: ABdhPJxVepUhAI8N3bF13gdj8iuq8j8s9/oL2DEa7gPgNU4kvF9NdFEPiFQ1qOG770JvQDJgdWh6mQ== X-Received: by 2002:a7b:c1d3:: with SMTP id a19mr930864wmj.19.1601289727965; Mon, 28 Sep 2020 03:42:07 -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 f14sm939258wrt.53.2020.09.28.03.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:07 -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 v2 7/9] gpio: mockup: pass the chip label as device property Date: Mon, 28 Sep 2020 12:41:53 +0200 Message-Id: <20200928104155.7385-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Mon Sep 28 10:41:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 254306 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 F3259C2D0A8 for ; Mon, 28 Sep 2020 10:42:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B09AA21548 for ; Mon, 28 Sep 2020 10:42:26 +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="WFDjseGU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726648AbgI1KmY (ORCPT ); Mon, 28 Sep 2020 06:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726640AbgI1KmK (ORCPT ); Mon, 28 Sep 2020 06:42:10 -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 5FFCBC0613CE for ; Mon, 28 Sep 2020 03:42:10 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id k10so747198wru.6 for ; Mon, 28 Sep 2020 03:42:10 -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=NLkzILStzwcX5lWd3OZiiqerlwq7qQv7m5/oV3taC7k=; b=WFDjseGUVlezz/bmtsAMRVQxh6txWCSr4tDGr+HrSe0GebeYy9FkDETLABW3zzPeEH SDptFyV5Q5RJcuam/uANjyJuO6Mizn84OrLr+MYrLT9K3cJ4W2qzrUVMgMVVUpQoppTC ahFvBd/cJGMtW3ui+g2LUydunm9/zJOXHJisCapohQtinTyMeyeUNzxJ1rmLV8KLbHpE psr1T/h2/dcELUuht7ocskjnfbZuJRbqlXJfF1Yn+9//0wB7MgnudfCPE+pq9pJTwsBG 6fHZ1hFjIQAL+pKMGkNxFq2PWgcvSzKvaOKlrg54XKyc2KgYjhyHCZDORVHXzhEvOPeo ikCg== 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=NLkzILStzwcX5lWd3OZiiqerlwq7qQv7m5/oV3taC7k=; b=kRpmpwW5g9G5FXRSTdeU4mw//65dJ3jPmpiO+Zh24w/610IbvcnFNKNxbrLg8n5ad2 R+H3S6eajmPpFVj7NY+3n0H3qJeOCMafcyHgGqTt6tVNkndC97Jw2HKkBVyo3BiOUVYt uhmIymHaAX70C5xG6r1/sBtqFlwsKUiS/QBidj/QvNqmvPCJ00c96J9N4+7s0a5lDYZj 6jUr9DPWCTrF6j+6woIi8JmEcsdnlSsgpD5lJZITkRmo6Bi4BJZosMKMLReX+PaXQlja Uw9lSe8PaJBNP4jAqvpvfrHFhtioXS4LVJyeQlZwhknIesYrjT+lEYpG3L4mlcbO+4Kd rmHg== X-Gm-Message-State: AOAM53189Rbnmof8XxHf0oW9RkjYGonQGkNBIAnQCuMqP+eiJeR+LNvq phvopIgd4zjs8AsVR8jmIgrdKQ== X-Google-Smtp-Source: ABdhPJx13KAAjVjH5El6zXYhK7NIg8cBZH4ORAyd17YH4P10hU6QzRfN0h4l+JoyeW/WOsJSdTHGJQ== X-Received: by 2002:a5d:414b:: with SMTP id c11mr916082wrq.181.1601289729043; Mon, 28 Sep 2020 03:42:09 -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 f14sm939258wrt.53.2020.09.28.03.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:08 -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 v2 8/9] gpio: mockup: use the generic 'gpio-line-names' property Date: Mon, 28 Sep 2020 12:41:54 +0200 Message-Id: <20200928104155.7385-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- 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..47b7de6d5ab1 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, ngpio); if (IS_ERR(pdev)) { pr_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver); From patchwork Mon Sep 28 10:41:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 285667 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 C00B0C4741F for ; Mon, 28 Sep 2020 10:42:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 899D82080A for ; Mon, 28 Sep 2020 10:42:26 +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="UP6FbU97" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbgI1KmX (ORCPT ); Mon, 28 Sep 2020 06:42:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbgI1KmM (ORCPT ); Mon, 28 Sep 2020 06:42:12 -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 73F03C0613CF for ; Mon, 28 Sep 2020 03:42:11 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id o5so699733wrn.13 for ; Mon, 28 Sep 2020 03:42:11 -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=WjvGzyO62y8+TE10NX89uaVC3jyOwciikUlJLtdxrSc=; b=UP6FbU97hiLI3MWndLsukFiAqWATwepolyDq9C2sft9a4uW61HXqHHdlmryW5fOeGk AvFbXjzWssoioAlwHVB3m5lWEYWDLceWZl0e58Vm5AQGKqTIvcUPq/VD42dMRUDleFXJ rbWSwvwmEFUQ+1NWBfpmnNzrNh5aJfp9m8GjGfTqhtBJrigyA/oFNUJo9kM5zZXt3IVA n84qcoYzzop6WqR2np2o1mJ0liJiPJFKTNFnmuykYCp+5qpnhRV4e7F87pD7fLqgzMYs rxq4OxP+5BO29PuQHj1fKaMi41SisX7vk9ByFuBsfwPV6Ia/fSHrzTnfen6IWxajQS1+ v/sA== 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=WjvGzyO62y8+TE10NX89uaVC3jyOwciikUlJLtdxrSc=; b=DXJwaKgSapI/1E+GX+FcH91W46St3iR60Trr0vnCu36djHWqHn/qs4KBG+vB7L8Akn npyaXtQ0SgMaLHuw+jwoQ6ya+KjUt+EeJmUOO/3dPNVb7HiGfkZ1WDTmGn+TzJjOPISr IR/X83Zk6ElfeuTEYFUgqk+yhSRkw0iZUFLSOSUHmD4VvrJNQgZ1lQcIwC78ZXxCwVjz TKJMUBOZ3o6mPQCDO+/JW7k721G7rNKS+dXGg+S6YgajE6NJT9YPo62qMidz2ZX7dzgT loWnPQg21wqCZ5Aip0IwIcM0EEqsuKWR0qnXZS5Alag0h9yIhWu/vqaYSQJHfsdJfpeG UuoA== X-Gm-Message-State: AOAM530LTPqSsLTrdL/VdgaeRSRKwNC9UgO9cLiY9X1RFHPs5PDInGk9 lvc08k66yIQ+WIXurjz931Zosg== X-Google-Smtp-Source: ABdhPJxPHM6y/EAjEjcY3fXmak9oChruhF6beTZp/+Z1PorBJ+2DWmZynuhGzwunOEQGzof6DeRUsA== X-Received: by 2002:a5d:43cb:: with SMTP id v11mr1044613wrr.188.1601289730189; Mon, 28 Sep 2020 03:42:10 -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 f14sm939258wrt.53.2020.09.28.03.42.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 03:42:09 -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 v2 9/9] gpio: mockup: refactor the module init function Date: Mon, 28 Sep 2020 12:41:55 +0200 Message-Id: <20200928104155.7385-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200928104155.7385-1-brgl@bgdev.pl> References: <20200928104155.7385-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 Reviewed-by: Andy Shevchenko --- 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 47b7de6d5ab1..02eea05a09dd 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, ngpio); + 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, ngpio); - 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;