From patchwork Fri Sep 4 15:45:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F576C2BB84 for ; Fri, 4 Sep 2020 15:50:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B0082078E for ; Fri, 4 Sep 2020 15:50:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="s1xR3LsW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbgIDPuh (ORCPT ); Fri, 4 Sep 2020 11:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726615AbgIDPql (ORCPT ); Fri, 4 Sep 2020 11:46:41 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3262CC061263 for ; Fri, 4 Sep 2020 08:46:36 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id v4so6494371wmj.5 for ; Fri, 04 Sep 2020 08:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G/17FBPXPIWM8suCIksrM34pviF3YRrgB9AFaEGMFdE=; b=s1xR3LsW3xC8wWHiTS17D3noApVypmQZqsrQfpiRs3PVIwAeFMZZbmrhd8Ci29gUPJ qeOOKIOcwVPtsmoJlPGUTae8LZaB1lpmP6r4EJ1NBihJlqmxiuHREKgewRXkyhcbElzS SS1a0rIr4TASNOM3hcJ3cZB11T75Gewkn/+XChRfGta6FMOWhPlpWi43w+qSn+26/cg3 pbuCojaEVkETdLTS/bA9q1uWIDfRtJyA3iW487kzDXs//zaJpMKiytj5yoUxgcrwimPG bUmkGN4uCR708R4v0zUpXw1XNhk53ufiFhyihcZ01PCTVRPSHlYYUYA4uWSsDCodiL31 v+fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G/17FBPXPIWM8suCIksrM34pviF3YRrgB9AFaEGMFdE=; b=LLEqQetJSkHa1qQ2vKaNMIRJTctU8FleCFr0JVsoNpWXrOmRPV6t0Rzvyo8TtWJk5u 2JWj/5f0iIB07DmmarcAO2XakDtas8iIT2Oo53atV5Il4hUxq9VjbH0nDBRvm7TW9GLG 4XF1By0RPTOry+EeW5qSPqfA8iB0LTSUy9n5C4bTn5FF9K845vC2kab+erm2QlNBGtPO gVkyo5aSOGaKjZnmXac+CPsBE15ZNegVznjkj6fM3MWSPDk1fowRag3HXZhFUrQwvXiM kH8oyYMtqOblIFcEaegzQ/F/6f/QPK06833w07q4COELx5TTx00g30dDCqOhwPKMOwOz SDjA== X-Gm-Message-State: AOAM531vGTVqLJG5f0S7tYdCZgLZ4kj/+mPS0gG2zyKoyEEQfAATgWmF 4Cg+myVG6aLfLbPoMPKCSomo2w== X-Google-Smtp-Source: ABdhPJz+8ARUs/kkukG0PPhJ3TJmui9hHStd+idsyDCLVB6+Ez/AJZiQ1EBjt7zRf0qJu3eKFFnoJg== X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr8050965wmg.164.1599234394881; Fri, 04 Sep 2020 08:46:34 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:34 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 03/23] lib: uaccess: provide getline_from_user() Date: Fri, 4 Sep 2020 17:45:27 +0200 Message-Id: <20200904154547.3836-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski Provide a uaccess helper that allows callers to copy a single line from user memory. This is useful for debugfs write callbacks. Signed-off-by: Bartosz Golaszewski --- include/linux/uaccess.h | 3 +++ lib/usercopy.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 94b285411659..5aedd8ac5c31 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -333,6 +333,9 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, long count); long strnlen_user_nofault(const void __user *unsafe_addr, long count); +ssize_t getline_from_user(char *dst, size_t dst_size, + const char __user *src, size_t src_size); + /** * get_kernel_nofault(): safely attempt to read from a location * @val: read into this variable diff --git a/lib/usercopy.c b/lib/usercopy.c index b26509f112f9..55aaaf93d847 100644 --- a/lib/usercopy.c +++ b/lib/usercopy.c @@ -87,3 +87,40 @@ int check_zeroed_user(const void __user *from, size_t size) return -EFAULT; } EXPORT_SYMBOL(check_zeroed_user); + +/** + * getline_from_user - Copy a single line from user + * @dst: Where to copy the line to + * @dst_size: Size of the destination buffer + * @src: Where to copy the line from + * @src_size: Size of the source user buffer + * + * Copies a number of characters from given user buffer into the dst buffer. + * The number of bytes is limited to the lesser of the sizes of both buffers. + * If the copied string contains a newline, its first occurrence is replaced + * by a NULL byte in the destination buffer. Otherwise the function ensures + * the copied string is NULL-terminated. + * + * Returns the number of copied bytes or a negative error number on failure. + */ + +ssize_t getline_from_user(char *dst, size_t dst_size, + const char __user *src, size_t src_size) +{ + size_t size = min_t(size_t, dst_size, src_size); + char *c; + int ret; + + ret = copy_from_user(dst, src, size); + if (ret) + return -EFAULT; + + dst[size - 1] = '\0'; + + c = strchrnul(dst, '\n'); + if (*c) + *c = '\0'; + + return c - dst; +} +EXPORT_SYMBOL(getline_from_user); From patchwork Fri Sep 4 15:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09A82C433E2 for ; Fri, 4 Sep 2020 15:50:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D402420772 for ; Fri, 4 Sep 2020 15:50:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="p6+ozsPx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727789AbgIDPuP (ORCPT ); Fri, 4 Sep 2020 11:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726742AbgIDPqp (ORCPT ); Fri, 4 Sep 2020 11:46:45 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C21AC061235 for ; Fri, 4 Sep 2020 08:46:38 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id c15so7166649wrs.11 for ; Fri, 04 Sep 2020 08:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U1nBCcNL8BeNxadPopc6bEehAwgvXwIu9mXvHzCgK8I=; b=p6+ozsPxwsblRZBCpVmBP7qVN0c1CSrx+fQWcqeSx2ykc5J0fyO83akiBJSKb4fObd yQkluWfXAW1xUpE/a/FmkvipuYuJFIXeBRQN6YHlrGEDwcxjGUjCifUpGQn+Z9PSKHB9 tZ/AGLgg2kq+Hz2boTAN8B2I18BtR2A4vZ+P6IvHlxuVzx6IB+fPjeFu7Xh74RXA5AVm Un7a6R2xmZSajmcdaTmP9wx0IbBq3KvVxsT+swGdZAFNxWtBAmPcFm+pJx10udDTzex/ LXUL3Kajpvv8vIpFGU0V2hdjPyqhZi0a0RY5fZOQYG8J9WZL4wcTCe2btth/wOeXwmQ6 gL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U1nBCcNL8BeNxadPopc6bEehAwgvXwIu9mXvHzCgK8I=; b=f/0/GRefyT7NzaSGviIPs8d1Jj5RWvci7F/ib9BjetC0oo4IRza6jYkcoJyM/LZeyt t9U+cKUqPWVSEDG2OkTNYUgyJf4Ra5x2k6QE/SyHZVQzrox6zoQGc2mXUcUkjb4tyHuc x72JUG6cdeQ7VOLLfOsMn7kik3F32gNOHCfrNjkRRM2zNGsCaPYSq+yqtyKOiPqWrrVF U5agfLM5j5gbTwCA9v6nMg0VFdYQKaSLbPgltgpe5WgPEs+zEP51pDRMAzqGDMKKUVPJ J+cbnhLFOatnWNTQwwXoB0VtXwVBvDB7myIlbEgLVK46XZciJXtfmHxVOlL9COFC6pwY uS3Q== X-Gm-Message-State: AOAM533XbUtpW1POHjDATqdtzowHRRdakuAMjcFUqPXpdmd4Hbj21LQe jJr+spteuftBEo/5+jUR+ksnK7fU942Xrg== X-Google-Smtp-Source: ABdhPJxKPO93ctBJ7Ow4MExd8CKDovERdU03BsC4lwZGsWCoWTY7HZN7SxfvjywlGty5Qr0fODTzVw== X-Received: by 2002:adf:e391:: with SMTP id e17mr7982842wrm.289.1599234397164; Fri, 04 Sep 2020 08:46:37 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:36 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 05/23] gpiolib: unexport devprop_gpiochip_set_names() Date: Fri, 4 Sep 2020 17:45:29 +0200 Message-Id: <20200904154547.3836-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski Now that devprop_gpiochip_set_names() is only used in a single place inside drivers/gpio/gpiolib.c, there's no need anymore for it to be exported or to even live in its own source file. Pull this function into the core source file for gpiolib. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/Makefile | 1 - drivers/gpio/gpiolib-devprop.c | 64 ---------------------------------- drivers/gpio/gpiolib.c | 48 +++++++++++++++++++++++++ include/linux/gpio/driver.h | 2 -- 4 files changed, 48 insertions(+), 67 deletions(-) delete mode 100644 drivers/gpio/gpiolib-devprop.c diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 4f9abff4f2dc..639275eb4e4d 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -6,7 +6,6 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIOLIB) += gpiolib.o obj-$(CONFIG_GPIOLIB) += gpiolib-devres.o obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o -obj-$(CONFIG_GPIOLIB) += gpiolib-devprop.o obj-$(CONFIG_GPIOLIB) += gpiolib-cdev.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.o obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o diff --git a/drivers/gpio/gpiolib-devprop.c b/drivers/gpio/gpiolib-devprop.c deleted file mode 100644 index a28659b4f9c9..000000000000 --- a/drivers/gpio/gpiolib-devprop.c +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Device property helpers for GPIO chips. - * - * Copyright (C) 2016, Intel Corporation - * Author: Mika Westerberg - */ - -#include -#include -#include -#include -#include - -#include "gpiolib.h" - -/** - * devprop_gpiochip_set_names - Set GPIO line names using device properties - * @chip: GPIO chip whose lines should be named, if possible - * - * Looks for device property "gpio-line-names" and if it exists assigns - * GPIO line names for the chip. The memory allocated for the assigned - * names belong to the underlying software node and should not be released - * by the caller. - */ -int devprop_gpiochip_set_names(struct gpio_chip *chip) -{ - struct gpio_device *gdev = chip->gpiodev; - struct device *dev = chip->parent; - const char **names; - int ret, i; - int count; - - count = device_property_read_string_array(dev, "gpio-line-names", - NULL, 0); - if (count < 0) - return 0; - - if (count > gdev->ngpio) { - dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", - count, gdev->ngpio); - count = gdev->ngpio; - } - - names = kcalloc(count, sizeof(*names), GFP_KERNEL); - if (!names) - return -ENOMEM; - - ret = device_property_read_string_array(dev, "gpio-line-names", - names, count); - if (ret < 0) { - dev_warn(&gdev->dev, "failed to read GPIO line names\n"); - kfree(names); - return ret; - } - - for (i = 0; i < count; i++) - gdev->descs[i].name = names[i]; - - kfree(names); - - return 0; -} -EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0d390f0ec32c..15c99cf560ee 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -358,6 +358,54 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) return 0; } +/* + * devprop_gpiochip_set_names - Set GPIO line names using device properties + * @chip: GPIO chip whose lines should be named, if possible + * + * Looks for device property "gpio-line-names" and if it exists assigns + * GPIO line names for the chip. The memory allocated for the assigned + * names belong to the underlying software node and should not be released + * by the caller. + */ +static int devprop_gpiochip_set_names(struct gpio_chip *chip) +{ + struct gpio_device *gdev = chip->gpiodev; + struct device *dev = chip->parent; + const char **names; + int ret, i; + int count; + + count = device_property_read_string_array(dev, "gpio-line-names", + NULL, 0); + if (count < 0) + return 0; + + if (count > gdev->ngpio) { + dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", + count, gdev->ngpio); + count = gdev->ngpio; + } + + names = kcalloc(count, sizeof(*names), GFP_KERNEL); + if (!names) + return -ENOMEM; + + ret = device_property_read_string_array(dev, "gpio-line-names", + names, count); + if (ret < 0) { + dev_warn(&gdev->dev, "failed to read GPIO line names\n"); + kfree(names); + return ret; + } + + for (i = 0; i < count; i++) + gdev->descs[i].name = names[i]; + + kfree(names); + + return 0; +} + static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) { unsigned long *p; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 56485a040b82..4a7e295c3640 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -756,8 +756,6 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, enum gpiod_flags dflags); void gpiochip_free_own_desc(struct gpio_desc *desc); -int devprop_gpiochip_set_names(struct gpio_chip *gc); - #ifdef CONFIG_GPIOLIB /* lock/unlock as IRQ */ From patchwork Fri Sep 4 15:45:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F16AAC43461 for ; Fri, 4 Sep 2020 15:49:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC3B9206E7 for ; Fri, 4 Sep 2020 15:49:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="OSJLrqQl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbgIDPq6 (ORCPT ); Fri, 4 Sep 2020 11:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbgIDPqq (ORCPT ); Fri, 4 Sep 2020 11:46:46 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87367C061237 for ; Fri, 4 Sep 2020 08:46:39 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id c18so7183464wrm.9 for ; Fri, 04 Sep 2020 08:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DcRR0cvj/PHR5JcTPOP5KmS/Yg2MBZu1qA5qfQNGk0A=; b=OSJLrqQlcETqpO5qPErz470rrP4H38PM0Pt8IMETO0NAQJtD9YhqhPpbnjVgO6z5Pc zFTnWa4ltyNBOIYyvM+4tgoe3kWJWGZqE++V+EWXWa7BQTeJRGUXB+RdjUucwaB8vcA8 a87JibEI+hux9ZIBnOWbmMRMtjtepM2P3EDk7RX7CdRquBDpTnwVnZks1Czho5gigPzO ZBW5pug6/6n5xkuc53cIUj/ofUMQo9ZoeuLagXDiIzxELjsil7e+coJ8Ky5yYDlrwcXU cOpD7DsDHXxX3RQEoBjI4dZ0NGVoglP+yauppUuvEEQIuJHNgVPXVtwRoCNu/iQqYXLn CGxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DcRR0cvj/PHR5JcTPOP5KmS/Yg2MBZu1qA5qfQNGk0A=; b=jtcblQTqD2sZ5fzEfrTHC0YsAZnmJBJONi2eqSYncXQrAk3CiAzQ0ZdVNXJaq3w2/u arKoV0pzDqOY1IoFiM0o8XKbBEWuozsn3CYqH1An10l0NLc8laUqrRjEGk1q9JTWSf21 CBHpDVtST31ngxHStIJgQ8BoNr17lv83V6Qj+3G+V5WzQCIL5Uv49FVWHg+IWjP45/Zr D1PGZqfLPcMuiJE41xrd5LKLzPRwPEd+RFXERDMZBGxf7C/B9F7zKBrBAtO8GDEpWR1C 8I47ThXXbfh+qCFdF4sXEwTAIAw1lpugHsX+r657mySWHO3CQhqHFWkeH7RfQzGh7ySh UCzQ== X-Gm-Message-State: AOAM530Kj8yS3idS4XH7k8siWDVxB4ysR/10/lkrY+zoCxcv62GlSHKk iukwkq+LjI90uUmI2RexDP4v3A== X-Google-Smtp-Source: ABdhPJzydKpw4Z5FsNZ+t0aMz2hV1ayLaJITUh07WUEGRLKoHkz5Fpef/XIauwVmwQp52xf/HGURHw== X-Received: by 2002:adf:9d44:: with SMTP id o4mr8314372wre.361.1599234398291; Fri, 04 Sep 2020 08:46:38 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:37 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 06/23] gpiolib: switch to simpler IDA interface Date: Fri, 4 Sep 2020 17:45:30 +0200 Message-Id: <20200904154547.3836-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski We don't need to specify any ranges when allocating IDs so we can switch to ida_alloc() and ida_free() instead of the ida_simple_ counterparts. ida_simple_get(ida, 0, 0, gfp) is equivalent to ida_alloc_range(ida, 0, UINT_MAX, gfp) which is equivalent to ida_alloc(ida, gfp). Note: IDR will never actually allocate an ID larger than INT_MAX. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 15c99cf560ee..591777bc2285 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -471,7 +471,7 @@ static void gpiodevice_release(struct device *dev) struct gpio_device *gdev = dev_get_drvdata(dev); list_del(&gdev->list); - ida_simple_remove(&gpio_ida, gdev->id); + ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); kfree(gdev->descs); kfree(gdev); @@ -582,7 +582,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, gc->of_node = gdev->dev.of_node; #endif - gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); + gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); if (gdev->id < 0) { ret = gdev->id; goto err_free_gdev; @@ -753,7 +753,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, err_free_descs: kfree(gdev->descs); err_free_ida: - ida_simple_remove(&gpio_ida, gdev->id); + ida_free(&gpio_ida, gdev->id); err_free_gdev: /* failures here can mean systems won't boot... */ pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__, From patchwork Fri Sep 4 15:45:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1CC0C43461 for ; Fri, 4 Sep 2020 15:50:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B25C32074D for ; Fri, 4 Sep 2020 15:50:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="uPvmch86" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726892AbgIDPuA (ORCPT ); Fri, 4 Sep 2020 11:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbgIDPqu (ORCPT ); Fri, 4 Sep 2020 11:46:50 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D082C06124F for ; Fri, 4 Sep 2020 08:46:43 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u18so6483429wmc.3 for ; Fri, 04 Sep 2020 08:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j/oJst/31Ve7sN2p8SCKacvVyyAcOuKLg7HZEv9T1Bg=; b=uPvmch86FehCHUzRin+H5CXUohTvqZcGHApZczW8eq9lu/MJzFf9k2ReFbXCNCKyKp QAnbVmcbSwdGJkgvs9p8KOl0pQFjMwybe/CpY7Hh8XOol4HEQj390odpGv/D8NzqLzMQ AvpKvNqhVW5l5nuN1vqDrYMGBJRpIjjleROe9WsZdIidLQSeFxFz28InaQK6FDuGaHh5 abODV06AGHy0/63WGITnhu2uh99JLKd0WdxfAiAeP2mKsEWCMrGiumxY/dt5qdEeKyOV cuO2DAPfpRJIBrUcEDpHpmxvfKAlccqkdA/9Vos4EFtb0JOtN0HxFexJBPe9MvVF5WWw hEzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j/oJst/31Ve7sN2p8SCKacvVyyAcOuKLg7HZEv9T1Bg=; b=j4jMLsIVC4nzDgzI1WaoCeAaCEKs6LfAu4L7U7O7WOmaE5p5zXQhPHkYWISdbFbNGJ SJz0gQvlwSiaCqF9LyYIOysywv/254PvuIFx1aAYGBfJWIKu4QtOxT/bYFbJRCoWyQj9 O1UF2v3plEvLmLQIoWNyxvzqoeZzOGY1DZJvxKoO8bHwNbOCcX4ZRAxbkYWvLlEk5PVK Rykmdu4ibilm7y5HweF40OojVv2mpRo3NuRxEFUmJeZ8zbLFA69twwvuE8ieOxc1l99x BCF2SntGZUdYu2epAQbcijCTKxAYvnhR82bvdW0ZxyM7n7cEWFlmPD8oop5JnyB4rSaI QZ6w== X-Gm-Message-State: AOAM5307mFHPNIXOiZMnhhX+wISQ6PQ7Q/v0ZzQEVauBqGK4MwLEl6hY dbHDwGlZWsbEgT+1p1VYRMkiTw== X-Google-Smtp-Source: ABdhPJxeZd3+cr0IB9roZ5GLjIlStXJyf7rbMppNX/92diAh72W08u+6KqmM8T0vs4cn4upk6ZXE0Q== X-Received: by 2002:a1c:4d14:: with SMTP id o20mr7896110wmh.115.1599234402232; Fri, 04 Sep 2020 08:46:42 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:41 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 09/23] gpio: mockup: use KBUILD_MODNAME Date: Fri, 4 Sep 2020 17:45:33 +0200 Message-Id: <20200904154547.3836-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski Drop the definition for the driver name. Let's use KBUILD_MODNAME for the log format and use the "gpio-mockup" value directly in the only place where it's relevant: in the name of the device. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 73cd51459c2a..78c97f7b6893 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -22,9 +22,8 @@ #include "gpiolib.h" #undef pr_fmt -#define pr_fmt(fmt) GPIO_MOCKUP_NAME ": " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#define GPIO_MOCKUP_NAME "gpio-mockup" #define GPIO_MOCKUP_MAX_GC 10 /* * We're storing two values per chip: the GPIO base and the number @@ -501,7 +500,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) static struct platform_driver gpio_mockup_driver = { .driver = { - .name = GPIO_MOCKUP_NAME, + .name = "gpio-mockup", }, .probe = gpio_mockup_probe, }; @@ -572,7 +571,7 @@ static int __init gpio_mockup_init(void) properties[prop++] = PROPERTY_ENTRY_BOOL( "named-gpio-lines"); - pdevinfo.name = GPIO_MOCKUP_NAME; + pdevinfo.name = "gpio-mockup"; pdevinfo.id = i; pdevinfo.properties = properties; From patchwork Fri Sep 4 15:45:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2407C43461 for ; Fri, 4 Sep 2020 15:49:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C31D2074D for ; Fri, 4 Sep 2020 15:49:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="DHwiLfdY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbgIDPtg (ORCPT ); Fri, 4 Sep 2020 11:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726621AbgIDPqz (ORCPT ); Fri, 4 Sep 2020 11:46:55 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95295C0619C0 for ; Fri, 4 Sep 2020 08:46:44 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id s13so6473072wmh.4 for ; Fri, 04 Sep 2020 08:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+YZpX0q+mO37+kQBR4DVC/6zJd6Q2vMMFs8yeO9lM6k=; b=DHwiLfdYkiuvwGGyuQJVAWH5TI6urmfg9xYzHsNJZRaq+W2VOEzGuDZHADH8b43f72 IdWm7NgZqeHyUMOex7xd1L+sKPbyTQU6bkDGKC+laJrmoA7AkcOWL7irwhKLtGgT8Sqf F8QMnwZ2j3f3Ev1NBQFKglsSE0ukhsx0DeGQmvPfA7s4XdmrdEBZCJLsDuZdy2py60av 7ddrLxRGhrc5nQk/J7X0Rd3701tAIqugtMXJWgIrCfExr2MwqBB6KT7fKNh50zVYZgFr KhutLsEsf7K3xZSOrPpo6OUVFbEEAZGhgmuf6GDrIPY3Qah5PrJ+GtBed+JpjV2iCFmm akIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+YZpX0q+mO37+kQBR4DVC/6zJd6Q2vMMFs8yeO9lM6k=; b=T8id/yvYT6A5HDyKi+TS6aC4V7WfApnGYUh7aDdOZCoOnHy5hBh3QAVVAap6IK8Qxu xhE4lUlynxLuxz/IMMgyWk+M1rtCy9MTn6EJcCl8GBr9CB+brN4OOLcido/39vMzE/A7 sMB7wjpPo/pf+AYbS/0O1TjAQw+FQHlCyPFc0reiO6iIdgsVJhSHsn/k62LcaP+VqJ1G q9W20pl1vhVoBrVqepVSugL5V7ZYxHWLURJa/70kWQBA/DybX56RVrm+JQNwXeMMZXz8 bwFU2HdTXPpK8lpF32M14QQLv506w0b6i2Jyhahl3bxobrbh44ga7xWIrdkB/gfc9aGH j9mw== X-Gm-Message-State: AOAM533XlH421ena65YTY4AEYOam8PLvvqf24HEg7hLYrUtGYzo5cikZ QWDofWJmG6iDZMO21f659vwDfw== X-Google-Smtp-Source: ABdhPJxcZNGnXPvX9i5H6bEC8G5YKnDdSyG1Hc0LLO25M6dxNysSMjIVg6JhStAhJl/uVlArUPCUtg== X-Received: by 2002:a1c:f018:: with SMTP id a24mr7818256wmb.7.1599234403325; Fri, 04 Sep 2020 08:46:43 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:42 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 10/23] gpio: mockup: fix resource leak in error path Date: Fri, 4 Sep 2020 17:45:34 +0200 Message-Id: <20200904154547.3836-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski If the module init function fails after creating the debugs directory, it's never removed. Add proper cleanup calls to avoid this resource leak. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 78c97f7b6893..19c092f814fd 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -550,6 +550,7 @@ static int __init gpio_mockup_init(void) err = platform_driver_register(&gpio_mockup_driver); if (err) { pr_err("error registering platform driver\n"); + debugfs_remove_recursive(gpio_mockup_dbg_dir); return err; } @@ -580,6 +581,7 @@ static int __init gpio_mockup_init(void) pr_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver); gpio_mockup_unregister_pdevs(); + debugfs_remove_recursive(gpio_mockup_dbg_dir); return PTR_ERR(pdev); } From patchwork Fri Sep 4 15:45: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: 251647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA05C2BB84 for ; Fri, 4 Sep 2020 15:49:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 585BC206E7 for ; Fri, 4 Sep 2020 15:49:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="BmXQtsk/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727923AbgIDPtR (ORCPT ); Fri, 4 Sep 2020 11:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727004AbgIDPrD (ORCPT ); Fri, 4 Sep 2020 11:47:03 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BCAFC0619C5 for ; Fri, 4 Sep 2020 08:46:48 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c15so7167154wrs.11 for ; Fri, 04 Sep 2020 08:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BFcXvT/mBks59Nbsnk6JiwVK+tMFpXxn+PeH1sXkPcs=; b=BmXQtsk/lNSK1NhzOpnVddLfxGsT8P0H9ClEgPxJpE8hkw4Ul/zwqczzS70BALZS8n vUW5AfqeO8+ikYrSu/35Ybp7/e/CjukugK16RO2+ZRrxjWbQ+6bTdhe0MJedMJxCczcx 87b+KiHycu6GRF+fkYgMryzrI/mI+X58xNIT8iWekGrHZrpJ5hLX9OnjMr4cj4t3eUxX wSZUpjgrh5l+Uhnbt4iDGr0J5la/xLfUcYhiu+0lj8jj61KujeIQqqZRmaS/rdRnkhUi 77/rijdpdD7LjPcI3LBVuEcAx0/sSZUJi07rSLSpvBU48UQsIdpK7sjEORTMAhaUC1ZA 29Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFcXvT/mBks59Nbsnk6JiwVK+tMFpXxn+PeH1sXkPcs=; b=jPrsNffbQ5kWDczlO0E2B5FAL2xjT6StWnjUcFxsxGEtUSOSoFQSbxKmzbu5edryB5 QahDqBCP3Q4hdCK31wnOl0942EQIUGygZ4C2n5LAabLhWw4+F+6rbAiZTrSWGPDoVI0j UJljYfZwQ+SBF+7U7M8AaGbkFgUFgLnNYCPXgkQv40yhQ4xjYH+r+lec7N/4ez33EAg1 VIqL2yzm/Ps8/JlToo42jubOrxRK+zzgQ3+8j7fZPTNNg+Wua2SIBXNbbFfuXdqXSAhv mNumDqTkgHXwAsBm/Lnt5PXOJjAyxwLgt54tTklzTubzrdUXZTFW4zF+tecXQz5sA2eJ pU/A== X-Gm-Message-State: AOAM5311RnckSmJhh65RVnoENs2fAClfGbI/X2ghANT57Hho4XtNqdT+ AzfislA/rl+ohKn2giXAcTq41Q== X-Google-Smtp-Source: ABdhPJxqVtqimUn/AOziI4okr5k6W+CeptUTEmSCRZWc/9G1FoORHyIyNXxgkGRVZJUKwoP2mlGlAw== X-Received: by 2002:adf:9ed4:: with SMTP id b20mr8360307wrf.206.1599234406494; Fri, 04 Sep 2020 08:46:46 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:46 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 13/23] gpio: mockup: pass the chip label as device property Date: Fri, 4 Sep 2020 17:45:37 +0200 Message-Id: <20200904154547.3836-14-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski While we do check the "chip-name" property in probe(), we never actually use it. Let's pass the chip label to the driver using device properties as we'll want to allow users to define their own once dynamically created chips are supported. The property is renamed to "chip-label" to not cause any confusion with the actual chip name which is of the form: "gpiochipX". If the "chip-label" property is missing, let's do what most devices in drivers/gpio/ do and use dev_name(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index e8a19a28ed13..ce83f1df1933 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -433,21 +433,14 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (rv) return rv; - rv = device_property_read_string(dev, "chip-name", &name); + rv = device_property_read_string(dev, "chip-label", &name); if (rv) - name = NULL; + name = dev_name(dev); chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - if (!name) { - name = devm_kasprintf(dev, GFP_KERNEL, - "%s-%c", pdev->name, pdev->id + 'A'); - if (!name) - return -ENOMEM; - } - mutex_init(&chip->lock); gc = &chip->gc; @@ -534,6 +527,7 @@ static void gpio_mockup_unregister_devices(void) static int __init gpio_mockup_init(void) { struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + char chip_label[GPIO_MOCKUP_LABEL_SIZE]; struct gpio_mockup_device *mockup_dev; int i, prop, num_chips, err = 0, base; struct platform_device_info pdevinfo; @@ -570,6 +564,11 @@ static int __init gpio_mockup_init(void) memset(&pdevinfo, 0, sizeof(pdevinfo)); prop = 0; + snprintf(chip_label, sizeof(chip_label), + "gpio-mockup-%c", i + 'A'); + properties[prop++] = PROPERTY_ENTRY_STRING("chip-label", + chip_label); + base = gpio_mockup_range_base(i); if (base >= 0) properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", From patchwork Fri Sep 4 15:45: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: 251648 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BC9CC43461 for ; Fri, 4 Sep 2020 15:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A39A206E7 for ; Fri, 4 Sep 2020 15:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="RrJg++r4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727051AbgIDPtA (ORCPT ); Fri, 4 Sep 2020 11:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbgIDPrK (ORCPT ); Fri, 4 Sep 2020 11:47:10 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47AC4C0619CA for ; Fri, 4 Sep 2020 08:46:50 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id z9so6523571wmk.1 for ; Fri, 04 Sep 2020 08:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=RrJg++r4d2sHRcNO3FHpdXscTwZC2S1z6mTa4gXaNzK1juMkhcaKgspDfWpLneE8ew tHNr9Istt1yOiqL4bpXNH0QTSrkeP/0+Sm0lWzrBSnNzA8Ipt1xnsSsJLqMRrfXfgPdL ByP89m21osn8Id9E+Wyld2kuBz/37527FByOq0o3H71SYeQv7QKjZwhPK8OLk7ZZ1+ln E6BINQjI5QOfdhbly6Mg+N5QR3sey2pYn/ItHPnMoSmlC2iJkFNPzpvM5K7zwL6RYcjj gqdPy1/YiAdUWwlNY/7Qrbz14NPumdr00luxiTymMknoqxMZo8w0KTk1eN2juH0xrC0s 99hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXNzTcdhYOLT/AXbUue/WL7HnvjNCgkZ3cLbmDzVGrc=; b=IToi6q2UvCBgQ5jVpSpEKEyGIHqjCmNcaj9qrJAiiwzh4tvL6XHoyz/G5F3rgkmWn7 TLtTNPW+kOEKnQ3Y5lIELjLeMVF7MDmh4B7JqcpelC1hJvgClcHSNnrwR0FKY4JnLynR mnt6YyGkBtCwxvVDGUgVJrH9mUkxl2xI3Bo3gOjsNay5bZZ6N6FUwcmnphE5aeqZ2oIg 0BzF1/Cu7wsd9RNt+wsnb+nPQ4cfqaZMHmdog5FqjzVCsFEN8KugdUZ5PF3fvZ82tKmw dd5z/YYH0+c5aw1/WkWBYF5YmukidU50/38darT0rPrtsJJm3WbV+VezX4F3GHrXKWUy LBNg== X-Gm-Message-State: AOAM530TKUdI8lzpDMVwofq+GNbGhKviAVpCRDSerNzRv7X+LSU+p/fT E82iowfrEQGwoeQeP5nwGd0vrQ== X-Google-Smtp-Source: ABdhPJxbT8FJfkefQNct8r1fnLwo5GotdwatKA46ZNCj44Ghck2jGtAw2L6A6tWWrFk0Rc/2fDW1Jg== X-Received: by 2002:a7b:c056:: with SMTP id u22mr8253559wmc.188.1599234408930; Fri, 04 Sep 2020 08:46:48 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:48 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 15/23] gpio: mockup: use dynamic device IDs Date: Fri, 4 Sep 2020 17:45:39 +0200 Message-Id: <20200904154547.3836-16-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski We're currently creating chips at module init time only so using a static index for dummy devices is fine. We want to support dynamically created chips however so we need to switch to dynamic device IDs. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 96976ba66598..995e37fef9c5 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,8 @@ module_param_named(gpio_mockup_named_lines, static struct dentry *gpio_mockup_dbg_dir; +static DEFINE_IDA(gpio_mockup_ida); + static int gpio_mockup_range_base(unsigned int index) { return gpio_mockup_ranges[index * 2]; @@ -480,8 +483,12 @@ static LIST_HEAD(gpio_mockup_devices); static void gpio_mockup_unregister_one_device(struct gpio_mockup_device *dev) { + int id; + list_del(&dev->list); + id = dev->pdev->id; platform_device_unregister(dev->pdev); + ida_free(&gpio_mockup_ida, id); kfree(dev); } @@ -587,12 +594,19 @@ static int __init gpio_mockup_init(void) } pdevinfo.name = "gpio-mockup"; - pdevinfo.id = i; pdevinfo.properties = properties; + pdevinfo.id = ida_alloc(&gpio_mockup_ida, GFP_KERNEL); + if (pdevinfo.id < 0) { + kfree_strarray(line_names, ngpio); + err = pdevinfo.id; + goto err_out; + } + mockup_dev = kzalloc(sizeof(*mockup_dev), GFP_KERNEL); if (!mockup_dev) { kfree_strarray(line_names, ngpio); + ida_free(&gpio_mockup_ida, pdevinfo.id); err = -ENOMEM; goto err_out; } @@ -601,6 +615,7 @@ static int __init gpio_mockup_init(void) kfree_strarray(line_names, ngpio); if (IS_ERR(mockup_dev->pdev)) { pr_err("error registering device"); + ida_free(&gpio_mockup_ida, pdevinfo.id); kfree(mockup_dev); err = PTR_ERR(mockup_dev->pdev); goto err_out; From patchwork Fri Sep 4 15:45: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: 251650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 105E6C433E2 for ; Fri, 4 Sep 2020 15:48:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8F822074D for ; Fri, 4 Sep 2020 15:48:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="DVTGoZ9/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbgIDPsY (ORCPT ); Fri, 4 Sep 2020 11:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727081AbgIDPrP (ORCPT ); Fri, 4 Sep 2020 11:47:15 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86630C06121A for ; Fri, 4 Sep 2020 08:46:52 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l9so6513543wme.3 for ; Fri, 04 Sep 2020 08:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fqNzmK12nk8xdy0PepsxrcJPk3kdW/zWD0as5Np++IA=; b=DVTGoZ9/IcG51yNk5wt6AIfbpjjgClmzQ/sB+JyYMzA1scB60f3klAUXpqyjXur7cU ceecqoA7dym9XyBOoc0KJdnwhnHizDo3L+PRneh2SVhNd3RWGVlxNWp4fb0qHEB16MUY UZZ981+PbDw/shKPxNe44u2DhQhUUonkKpnwrrBH3up1tBSsARpNhbqB1KQ0qdn4YGQv XVsC4P/nVvaAO/z3RO/B93144s06ZfVD1aZ6utVH8mAT1UxThVC9fl3XLywTHrk2F3Pb WRQ2oVF2yJ8i9/JXYBH6uosFBiLxHCTqBSgossd5IqX6hMJ4D3zpFtL5ugLmJe9Q8xrE 2QvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fqNzmK12nk8xdy0PepsxrcJPk3kdW/zWD0as5Np++IA=; b=dA6MUmFvXddXWvdEgPQoKS66OUMRE3pv6EctQOUlf6baG4iK714K2P1cm+OqOdqDet 3s4V0RTATtCH/z8ESq4x3CQPVIyalZuTFDHzD4pSzOaUaNKysc0o/JwPa67eHsarSP53 KGyraV1HL292YBamez1wmT2oahj/2SEPbn+xCqipnpsXNtt3kiL26bPbpjNViyBGPACB VAJ2le84lKgqNdLwgBlYUHlEj6DiXQ6GZuFjbdVkwHJEjFYLPkfH8TAX+NF9VoxYDI7h AUFZD4CRLoYTbX4c5MwZOrsdBjnspFKDNOENQUH/7NKQ5wkgUI4AMe7vqkJsk8nsXheI 16FA== X-Gm-Message-State: AOAM53094JJqlwF2cEwv3oz39MXum3v3R0LhvyilJTo/WP9/zhsZmV4P m6vseBYokat+3Sv/+Q0rJvx/Pw== X-Google-Smtp-Source: ABdhPJxttLkSDVoDRXzlpcTjTpigx62xH5t4We6CkvNvgq/knQn3QcMipzht5x/6b+Rm8h9SpKU0dQ== X-Received: by 2002:a1c:f402:: with SMTP id z2mr7915668wma.87.1599234411169; Fri, 04 Sep 2020 08:46:51 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:50 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 17/23] gpio: mockup: rename and move around debugfs callbacks Date: Fri, 4 Sep 2020 17:45:41 +0200 Message-Id: <20200904154547.3836-18-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski We will soon introduce new debugfs attributes for dynamically created chips. We'll reuse the gpio_mockup_debugfs_open() helper for them but the relevant write callbacks will of course be different. Let's rename gpio_mockup_debugfs_write() to gpio_mockup_debugfs_pull_write() to avoid confusion with new write callbacks and move gpio_mockup_debugfs_open() higher up in the code to separate it from the pull/value attribute which will no longer be the only user. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index eb94ddac5fee..29fbf007ab26 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -262,9 +262,14 @@ static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset) __gpio_mockup_set(chip, offset, chip->lines[offset].pull); } -static ssize_t gpio_mockup_debugfs_read(struct file *file, - char __user *usr_buf, - size_t size, loff_t *ppos) +static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, NULL, inode->i_private); +} + +static ssize_t gpio_mockup_debugfs_value_read(struct file *file, + char __user *usr_buf, + size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; struct gpio_mockup_chip *chip; @@ -287,9 +292,9 @@ static ssize_t gpio_mockup_debugfs_read(struct file *file, return simple_read_from_buffer(usr_buf, size, ppos, buf, cnt); } -static ssize_t gpio_mockup_debugfs_write(struct file *file, - const char __user *usr_buf, - size_t size, loff_t *ppos) +static ssize_t gpio_mockup_debugfs_pull_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; int rv, val; @@ -313,11 +318,6 @@ static ssize_t gpio_mockup_debugfs_write(struct file *file, return size; } -static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) -{ - return single_open(file, NULL, inode->i_private); -} - /* * Each mockup chip is represented by a directory named after the chip's device * name under /sys/kernel/debug/gpio-mockup/. Each line is represented by @@ -342,8 +342,8 @@ static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) static const struct file_operations gpio_mockup_debugfs_ops = { .owner = THIS_MODULE, .open = gpio_mockup_debugfs_open, - .read = gpio_mockup_debugfs_read, - .write = gpio_mockup_debugfs_write, + .read = gpio_mockup_debugfs_value_read, + .write = gpio_mockup_debugfs_pull_write, .llseek = no_llseek, .release = single_release, }; From patchwork Fri Sep 4 15:45:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E98C5C43461 for ; Fri, 4 Sep 2020 15:48:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB079206E7 for ; Fri, 4 Sep 2020 15:48:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="HCiTFjtP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbgIDPsj (ORCPT ); Fri, 4 Sep 2020 11:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbgIDPrO (ORCPT ); Fri, 4 Sep 2020 11:47:14 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A68C061233 for ; Fri, 4 Sep 2020 08:46:53 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id e17so6506329wme.0 for ; Fri, 04 Sep 2020 08:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=df1vNsIBtzMz3XaBeJ8Q2j/QYEAOiM6PlNqlmnkxGzE=; b=HCiTFjtPaoDptruE52sxg0PIrYN0fw4LxlnqDp18boSboMkoVyxeNy/lnftW/3B1VN St/clTzUXKDOHSQA056HKj7PuXF/g2RLwdgdIjLG4XG1olSqBHJaH7BtKBIH3CrBfDLT imWJKTRh52/m5EJlYTrb+CO3+4IWSd8rNuEeFqLMp3U8My502joushgdUehq4pMigYFC AOP5Kf5CVb4VXX4Kw1t81IoEzl31OBdvYQYB7fmnrbnAvsvNNTf6HUl/3korYBFLK59T FU4pltRDJrrAPTGx79VWKrY+5RNLNCdo1SqBKIuIwpwB5jdvB/+p+j5Z49o1MfvnBpS9 J0Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=df1vNsIBtzMz3XaBeJ8Q2j/QYEAOiM6PlNqlmnkxGzE=; b=TtiXpT5Q2YZkuyWlPDe+TXVAZaDk3VwnH3TVI03TjRWj3DpSFoYF2EE34DaLAu86wr 3VPg3moQx9QGxkdxu3DI13ATUIilWKqV60q7oBbxwWA7Klv3/5B5Xlx1Vyw9stsH1c6u 447PZoCU3huaN6dwr4KD/01s+t1StOn7UyMvRXYhpGWxTF62ipcSQmcIlASr0Vn5L6Ff u6J/qzJLryn3wy2+NV4zYT+GIu43rL41T/8y0D0IOcYHzHY1zAPtDNDTRvT1vZ12CwCo iCUfxmsS/GHlDvanSZOqoalwRFfi7jq1ScxpSfuOd3cp20Nuzo5zcbpZ4g7oB6rbnKn6 y4vQ== X-Gm-Message-State: AOAM5303QIvJhsx9dJJGPGs6fCSEw5U9k+1HqBOxFJRoz7FSc7gq8Tfs cAPjCae/LDdSSDqpxZJb+R5ebg== X-Google-Smtp-Source: ABdhPJwDF5h6MoCuJSLVRYN6V3SUPCfPtMhU02JacL8LUejcHJkWG2C2FBuxEHO5GQ0TLz1u4jgkzg== X-Received: by 2002:a05:600c:2146:: with SMTP id v6mr8004415wml.159.1599234412250; Fri, 04 Sep 2020 08:46:52 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:51 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 18/23] gpio: mockup: require debugfs to build Date: Fri, 4 Sep 2020 17:45:42 +0200 Message-Id: <20200904154547.3836-19-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski Debugfs has become the standard way of interfacing with gpio-mockup to the point where the module is not very useful without it anymore. Let's make it a hard requirement to build gpio-mockup. Let's also add error checks whenever calling debugfs routines as we now don't expect them to fail. The device sub-directories must now be removed when the device is detached to correctly support dynamically created chips. The call to debugfs_remove_recursive() in module exit must be moved to the bottom or we'd risk to remove the root directory before devices can unregister their own sub-directories. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-mockup.c | 41 ++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 8030fd91a3cc..515f345757d8 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1567,6 +1567,7 @@ config GPIO_AGGREGATOR config GPIO_MOCKUP tristate "GPIO Testing Driver" + depends on DEBUG_FS select IRQ_SIM help This enables GPIO Testing driver, which provides a way to test GPIO diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 29fbf007ab26..7df990662c17 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -348,38 +348,55 @@ static const struct file_operations gpio_mockup_debugfs_ops = { .release = single_release, }; -static void gpio_mockup_debugfs_setup(struct device *dev, - struct gpio_mockup_chip *chip) +static void gpio_mockup_remove_chip_debugfs_entry(void *data) +{ + struct dentry *entry = data; + + debugfs_remove_recursive(entry); +} + +static int gpio_mockup_debugfs_setup(struct device *dev, + struct gpio_mockup_chip *chip) { struct gpio_mockup_dbgfs_private *priv; struct gpio_chip *gc; + struct dentry *attr; const char *devname; char *name; - int i; + int i, ret; gc = &chip->gc; devname = dev_name(&gc->gpiodev->dev); chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir); + if (IS_ERR(chip->dbg_dir)) + return PTR_ERR(chip->dbg_dir); + + ret = devm_add_action_or_reset(dev, + gpio_mockup_remove_chip_debugfs_entry, chip->dbg_dir); + if (ret) + return ret; for (i = 0; i < gc->ngpio; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); if (!name) - return; + return -ENOMEM; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) - return; + return -ENOMEM; priv->chip = chip; priv->offset = i; priv->desc = &gc->gpiodev->descs[i]; - debugfs_create_file(name, 0200, chip->dbg_dir, priv, - &gpio_mockup_debugfs_ops); + attr = debugfs_create_file(name, 0200, chip->dbg_dir, priv, + &gpio_mockup_debugfs_ops); + if (IS_ERR(attr)) + return PTR_ERR(attr); } - return; + return 0; } static void gpio_mockup_dispose_mappings(void *data) @@ -462,7 +479,9 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (rv) return rv; - gpio_mockup_debugfs_setup(dev, chip); + rv = gpio_mockup_debugfs_setup(dev, chip); + if (rv) + return rv; return 0; } @@ -629,6 +648,8 @@ static int __init gpio_mockup_init(void) int ret; gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); + if (IS_ERR(gpio_mockup_dbg_dir)) + return PTR_ERR(gpio_mockup_dbg_dir); ret = platform_driver_register(&gpio_mockup_driver); if (ret) { @@ -650,9 +671,9 @@ static int __init gpio_mockup_init(void) static void __exit gpio_mockup_exit(void) { - debugfs_remove_recursive(gpio_mockup_dbg_dir); platform_driver_unregister(&gpio_mockup_driver); gpio_mockup_unregister_devices(); + debugfs_remove_recursive(gpio_mockup_dbg_dir); } module_init(gpio_mockup_init); From patchwork Fri Sep 4 15:45:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE6D3C433E2 for ; Fri, 4 Sep 2020 15:47:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9000C20829 for ; Fri, 4 Sep 2020 15:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Pph0ChKq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727794AbgIDPri (ORCPT ); Fri, 4 Sep 2020 11:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727019AbgIDPrR (ORCPT ); Fri, 4 Sep 2020 11:47:17 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3E7FC0619D1 for ; Fri, 4 Sep 2020 08:46:54 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c18so7184205wrm.9 for ; Fri, 04 Sep 2020 08:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RT9K0p4g9wsam9mtLvU8jWCbdg1QlHE5npCSk6GRJVM=; b=Pph0ChKqHgqs9PaK7532rJDYq8CCuzL49IHbUNNh8wkzPBANz7SFZRVpe8XZ6089Dv w6hesKYtcpQT4Xn0LXDDkAAwnHY8SkZfl97hmrjQg1ejNa/IDYgWLvxD72t0bCCu1ihU Kia91DKj1cbhCQ054PEtqNZgjWU4xEvuzZbzThXH6fhadPW3xJHoOT4GOeXDsdpt4B6Q w8yhwq243s79jSf7dIZgRnGMtn09vLqHQF/2Gw1s+Xxbhg4FS7Q6bC3r5oFPgFrePT8H Rkc0q0bYUHSe+Yf2WE7b+liCRpH0L24hIZ43cjEjsbBKorpi1qb4JDcLyq2SkhHPkXug aKKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RT9K0p4g9wsam9mtLvU8jWCbdg1QlHE5npCSk6GRJVM=; b=sZfiVD8XlqhEG+Kl3Iv/9BpZc3cafx3wkGZClRTF76rO6MlONYcpWy4DLMuPPEfb53 eptaZLLyokbgztqzAq4EIsqSh/bc4pfJSsqocKK2DTiw19rwuUrWJ+BPZ1xXd48cuUKF gEf2aom7E4KYATc9+nJDkZZFeAd4Os6se8FPYv3u3GQtZPaI1cUN4YnyL2gclxf3ZvIO tL9s0d+Bw04BhVW94yh3kO21/PuUXXdG41Sxr5E22jjRPjZ8VokjRFyG1NihQse1CRXi cs3VBgBErUSCRKAAAmG99S7BFNDzi4ibZSGcYAFqOB+hOcqS1e8Q20f444MIoXkEcT2u I/jg== X-Gm-Message-State: AOAM532teenSjfeyLIrU08tzDh1TDQX6THW5u2N3jycvsRrmfPPz9kJ9 dG6ZM0Q/aj0nsf2MqqUjF9qJ5A== X-Google-Smtp-Source: ABdhPJzwm1LPWjidY+W2eWt031GEhqfqEZ4XCSVhfjqUt9KC+wqwPvwzW1Xvz1lIpyZuwTS8CeLJLw== X-Received: by 2002:adf:9d44:: with SMTP id o4mr8315397wre.361.1599234413434; Fri, 04 Sep 2020 08:46:53 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:52 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 19/23] gpio: mockup: add a symlink for the per-chip debugfs directory Date: Fri, 4 Sep 2020 17:45:43 +0200 Message-Id: <20200904154547.3836-20-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski We used to have a symlink named after the chip's label linking to the per-chip directory named after the chip's name. This was removed by commit d51ee07a8de7 ("gpio: mockup: don't create the debugfs link named after the label") because there were no users of it. This changeset proposes to reintroduce debugfs symlinks but inverted: the link named after the device name points to the directory named after the label. This way user-space can dynamically create a chip (once that functionality is available), detect its creation over uevent and match the device name to the label by resolving the link. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 7df990662c17..bc4609e047ef 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -52,6 +52,7 @@ struct gpio_mockup_chip { struct gpio_mockup_line_status *lines; struct irq_domain *irq_sim_domain; struct dentry *dbg_dir; + struct dentry *dbg_link; struct mutex lock; }; @@ -355,6 +356,13 @@ static void gpio_mockup_remove_chip_debugfs_entry(void *data) debugfs_remove_recursive(entry); } +static void gpio_mockup_remove_chip_debugfs_link(void *data) +{ + struct dentry *link = data; + + debugfs_remove(link); +} + static int gpio_mockup_debugfs_setup(struct device *dev, struct gpio_mockup_chip *chip) { @@ -368,7 +376,7 @@ static int gpio_mockup_debugfs_setup(struct device *dev, gc = &chip->gc; devname = dev_name(&gc->gpiodev->dev); - chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir); + chip->dbg_dir = debugfs_create_dir(gc->label, gpio_mockup_dbg_dir); if (IS_ERR(chip->dbg_dir)) return PTR_ERR(chip->dbg_dir); @@ -377,6 +385,16 @@ static int gpio_mockup_debugfs_setup(struct device *dev, if (ret) return ret; + chip->dbg_link = debugfs_create_symlink(devname, gpio_mockup_dbg_dir, + gc->label); + if (IS_ERR(chip->dbg_link)) + return PTR_ERR(chip->dbg_link); + + ret = devm_add_action_or_reset(dev, + gpio_mockup_remove_chip_debugfs_link, chip->dbg_link); + if (ret) + return ret; + for (i = 0; i < gc->ngpio; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); if (!name) From patchwork Fri Sep 4 15:45:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 251651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BA58C2BB84 for ; Fri, 4 Sep 2020 15:48:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C48C206E7 for ; Fri, 4 Sep 2020 15:48:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="T29hggUB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727859AbgIDPsJ (ORCPT ); Fri, 4 Sep 2020 11:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbgIDPrb (ORCPT ); Fri, 4 Sep 2020 11:47:31 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12110C06123A for ; Fri, 4 Sep 2020 08:46:57 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c18so7184318wrm.9 for ; Fri, 04 Sep 2020 08:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=grMpfwJBPKz8x8JwdVkKa3ogOmUgQ5L3HbriAAtXMOE=; b=T29hggUBZSkRV9pQbFKSYoyB5ydrOKR+eklkTQqELriqTYpxPUnHKrAQ5JKk0Op74Q DCxlFEGrV8egWnu5H/c03dcSHHYXjjtqm8rjAsFcvt8PJHS4qak+49XcjgQgBcjgMiI8 qIDpYQbwqZE2cgT0bB0aDZPqm12ei0JuBbnIxH43DhRDxfoh/lX2p3N0pYHOzXJyZ1Q/ Q4s6DClwAfE/qxdvNwJgGGMk1CJwX6CFhO4oRx/5G5B4T22zAxPoaWisGxGE1YFintKM ACUm9cOFgKwYlDa0KUtbdHlwxYdxWEiIki7K6drA8WjMT3VnCj12hhleiJbWcgTF2y0N lMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=grMpfwJBPKz8x8JwdVkKa3ogOmUgQ5L3HbriAAtXMOE=; b=sB+jrRuRaQUztLK/ed3ASGIrhz001Bx4WSoUJGZs63nIGzMwWa4OANL/v6zhzkQZoP OvpVXU73DuOU1SB3FSp2rzamoy6q2OORHjJVT40blk7kUz7n4PwKGgS5dBNT0Yx7GNUK 1dEARXLqhvVTCwW4y9LMJPzJEA+2byZSzLKLoHT5eI9/CpB+RxDHts6yhEGXGKN+lSAG nMZZFPQ0VWpTBRkldzJ1dzQwlkHA7dxZerNZ+gi3+S/YeRzoJUvL2f3hDXXKhLtYEOiK B8zAA86C7v0rjxo1n2wZT2OutTMDjah4+VCHaFJwz9ftqjw3eKErcfJ0smxweuKgEh87 zIPw== X-Gm-Message-State: AOAM532AXdMcsKWAvu+xCg7UveICQZ9K7MJkOwH5nmM46zlptAzFwKLv mw00R8UdrSjmPZsWtFzmiKbKR2qgMvwmkw== X-Google-Smtp-Source: ABdhPJwF/TdbSD80yVhLNOeAq70EYhl8a4L44K/4AYYY/Rbp36+YEs1GetDpBBcfGubtwwMDMcnZNA== X-Received: by 2002:adf:ed12:: with SMTP id a18mr8803147wro.178.1599234415760; Fri, 04 Sep 2020 08:46:55 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id q4sm11983375wru.65.2020.09.04.08.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:46:55 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Mika Westerberg , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 21/23] gpio: mockup: provide a way to delete dummy chips Date: Fri, 4 Sep 2020 17:45:45 +0200 Message-Id: <20200904154547.3836-22-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200904154547.3836-1-brgl@bgdev.pl> References: <20200904154547.3836-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bartosz Golaszewski Add a new debugfs attribute 'delete_device' to which the chip label can be written to dynamically remove the associated dummy device. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 70 +++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 1353239dc315..9d2de78a45c2 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -668,14 +669,81 @@ static int __init gpio_mockup_register_chips_from_params(void) return 0; } -static int __init gpio_mockup_init(void) +static ssize_t gpio_mockup_debugfs_delete_device_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) { + struct gpio_mockup_device *mockup_dev; + char label[GPIO_MOCKUP_LABEL_SIZE]; + struct list_head *curr; + struct device *dev; + const char *prop; int ret; + if (*ppos != 0) + return -EINVAL; + + ret = getline_from_user(label, sizeof(label), usr_buf, size); + if (ret < 0) + return ret; + + mutex_lock(&gpio_mockup_devices_lock); + + list_for_each(curr, &gpio_mockup_devices) { + mockup_dev = list_entry(curr, struct gpio_mockup_device, list); + dev = &mockup_dev->pdev->dev; + + ret = device_property_read_string(dev, "chip-label", &prop); + if (ret) { + mutex_unlock(&gpio_mockup_devices_lock); + return ret; + } + + if (sysfs_streq(label, prop)) { + gpio_mockup_unregister_one_device(mockup_dev); + mutex_unlock(&gpio_mockup_devices_lock); + return size; + } + } + + mutex_unlock(&gpio_mockup_devices_lock); + return -ENODEV; +} + +static const struct file_operations gpio_mockup_debugfs_delete_device_ops = { + .owner = THIS_MODULE, + .open = gpio_mockup_debugfs_open, + .write = gpio_mockup_debugfs_delete_device_write, + .llseek = no_llseek, + .release = single_release, +}; + +static int __init gpio_mockup_debugfs_init(void) +{ + struct dentry *entry; + gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); if (IS_ERR(gpio_mockup_dbg_dir)) return PTR_ERR(gpio_mockup_dbg_dir); + entry = debugfs_create_file("delete_device", 0200, gpio_mockup_dbg_dir, + NULL, &gpio_mockup_debugfs_delete_device_ops); + if (IS_ERR(entry)) { + debugfs_remove_recursive(gpio_mockup_dbg_dir); + return PTR_ERR(entry); + } + + return 0; +} + +static int __init gpio_mockup_init(void) +{ + int ret; + + ret = gpio_mockup_debugfs_init(); + if (ret) + return ret; + ret = platform_driver_register(&gpio_mockup_driver); if (ret) { pr_err("error registering platform driver\n");