From patchwork Tue Sep 12 10:07:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DDEACA0EC3 for ; Tue, 12 Sep 2023 10:07:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233853AbjILKH5 (ORCPT ); Tue, 12 Sep 2023 06:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234022AbjILKHm (ORCPT ); Tue, 12 Sep 2023 06:07:42 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 538581723 for ; Tue, 12 Sep 2023 03:07:38 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-401b393ddd2so62025045e9.0 for ; Tue, 12 Sep 2023 03:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513257; x=1695118057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nxu4Stw3TnchTs3E1ZMW4avWovvpHjhxTZTeZz76j+U=; b=AtrjjIg9WYqKwYlv2HfqwZBwRphvWtXRewX8yoTx5o0NR8oz1RpgcCNVOQ2yHdkMRR t1XcLcWN0x2hSsZVSfVoGKqAc2WrCFqBKqH6+mVJJ2vWyeVj4iMM8TYLKTzNn1yw/5ce tsfXF4Mzi7oGFjRtpCQYAxIh+/8INA5SPIpwQdK8AoF8vEfkctYcoha/b7zk+xS6mtW9 yHAr7PItgUc+smMqtFZqk6uZ9EE4ba8bFxg9D/qzpjpKssipt/6JfaHD+mUTlQsb5t0U IXv675OIutArLUiA43mJGfOw4R61OcvLjBVNUITxI0kzvQGkd0CT1b6KNMlGL7mozeRH nT6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513257; x=1695118057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nxu4Stw3TnchTs3E1ZMW4avWovvpHjhxTZTeZz76j+U=; b=aE5nAt04nFTg1LSF3aNOpraR8O3MKPev9QEMUpsUVbFqHovT9jKp1BF2Sy9icxUsax z4Fzc0wWBwpbtVHXLi17eKfOpy6EiNpa7Ugbz4+aGQQq58YrPyfzB4FsEJZf43F3+FI4 2IiQnTOqwe0zaxhP8TqOzA8G9SRTFiaOue8df/AXC+5T8zZOxdYFFtSWJAojc7JFOim2 2Q5SaHKedAx/hXLDZKn6/EagB03S5bfxLdWy11MGLvpKuaYxylUO1OxZvSxk8iwN8zuO Jly7BFRmSxedZz/GP9yT0KWs4iPseOkk94GANa2FbCZPnCNgku7oOE4sNSgzQkky6GsC iKzQ== X-Gm-Message-State: AOJu0YxPMj80ktrVMLW/LLGEbEmszOvBE2duq9uOWb1T5pKf16nr7C1c csykbkAEFWXPyxHjsx8a3I94/A== X-Google-Smtp-Source: AGHT+IGLzNu4ChI04vmQevgdWMpO0C8hfinlC+kV30zBWFLYXflzUjnkU2eq+lCTqP+ARJQkXjtk1Q== X-Received: by 2002:a05:600c:214e:b0:401:eb0:a980 with SMTP id v14-20020a05600c214e00b004010eb0a980mr11277365wml.14.1694513256719; Tue, 12 Sep 2023 03:07:36 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:36 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 01/11] gpiolib: make gpio_device_get() and gpio_device_put() public Date: Tue, 12 Sep 2023 12:07:17 +0200 Message-Id: <20230912100727.23197-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski In order to start migrating away from accessing struct gpio_chip by users other than their owners, let's first make the reference management functions for the opaque struct gpio_device public in the driver.h header. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 24 ++++++++++++++++++++++++ drivers/gpio/gpiolib.h | 10 ---------- include/linux/gpio/driver.h | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index edffa0d2acaa..f84ad54d8dbd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1058,6 +1058,30 @@ static struct gpio_chip *find_chip_by_name(const char *name) return gpiochip_find((void *)name, gpiochip_match_name); } +/** + * gpio_device_get() - Increase the reference count of this GPIO device + * @gdev: GPIO device to increase the refcount for + * + * Returns: + * Pointer to @gdev. + */ +struct gpio_device *gpio_device_get(struct gpio_device *gdev) +{ + return to_gpio_device(get_device(&gdev->dev)); +} +EXPORT_SYMBOL_GPL(gpio_device_get); + +/** + * gpio_device_put() - Decrease the reference count of this GPIO device and + * possibly free all resources associated with it. + * @gdev: GPIO device to decrease the reference count for + */ +void gpio_device_put(struct gpio_device *gdev) +{ + put_device(&gdev->dev); +} +EXPORT_SYMBOL_GPL(gpio_device_put); + #ifdef CONFIG_GPIOLIB_IRQCHIP /* diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 9bff5c2cf720..3ccacf3c1288 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -86,16 +86,6 @@ static inline struct gpio_device *to_gpio_device(struct device *dev) return container_of(dev, struct gpio_device, dev); } -static inline struct gpio_device *gpio_device_get(struct gpio_device *gdev) -{ - return to_gpio_device(get_device(&gdev->dev)); -} - -static inline void gpio_device_put(struct gpio_device *gdev) -{ - put_device(&gdev->dev); -} - /* gpio suffixes used for ACPI and device tree lookup */ static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 8f0859ba7065..a2060dc3344b 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -606,6 +606,9 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *gc, void *data)); +struct gpio_device *gpio_device_get(struct gpio_device *gdev); +void gpio_device_put(struct gpio_device *gdev); + bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset); From patchwork Tue Sep 12 10:07:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9B18CA0EC3 for ; Tue, 12 Sep 2023 10:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233894AbjILKIB (ORCPT ); Tue, 12 Sep 2023 06:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234033AbjILKHn (ORCPT ); Tue, 12 Sep 2023 06:07:43 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DA20172A for ; Tue, 12 Sep 2023 03:07:39 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31fa15f4cc6so2158414f8f.2 for ; Tue, 12 Sep 2023 03:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513257; x=1695118057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ooPiibuin/T1BXM3ci9G/toRB2k62lYI6dDd6XnUFKA=; b=JzQ9L+NIMBtxp4S6so12CVzTrS6VMV+PvLooJ2BjBkgHqO1plgvKW8RCbgKEloeGFD 046DZjmXeH5knUu9bc6eutPrKq0yni51vumVr6ShmB12dLDrWw/MQWZC5vkBNr20ItW/ DBy00PvwvdN24+s5uxIPwJp0PLfkcByOuT4FFQswwlY/y/ZzRb44/2u0nMMgFUII/hxt ACkRhcuQ0bjVj2RKBtnEM/ZYLN/UzbxefyZBSccVGY9MEZronwaft3F6VI9IYd6erjCW O6F5FWTIEJI2zKBrpUKG/6QK6+jY8ABAp3BzHUt9fCydufEMWx3OjW00/AemRiE4TOZB 79LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513257; x=1695118057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ooPiibuin/T1BXM3ci9G/toRB2k62lYI6dDd6XnUFKA=; b=Dtl5ZMcsSJp4I6oMcqdtKumHeuX5Z8NE29FYXUgo70KMc5ox8rsZT6+0q5TYcw9gYx tueU4/jVLdEqkwC7aAZ0nCjmk62Tz4+hljIec+YqyAi1Q5380/6/bFzfD5G2KYQTc9aC rZBzzF7ObicRRlHYPDyzXePbXGdPynUcTOQ0N8xD6iQdtykajjQUwuliGNMjGSX2O7rr eXTgeJpfzX6s8kFJm+EbXOL57TMDjZYS5S98s9xec09EvvWGhFI32nwIERIWjzJsoWtr eCGs4uylkizbch6lz2veLQhOAITDGFVEoF7Ps5YyqvZWReO6vc5tt+w7O6I/n+4rG1fO S6mQ== X-Gm-Message-State: AOJu0YzttxfItHUjMFQ/KJeLovQf6ii7sfWdwDcQ925zVvn6Gd+imRBa iOan4zeXYoGGJFd+XShpyIST9Q== X-Google-Smtp-Source: AGHT+IH6XDJfFYmBXwiNkL8kyXELSWjOJy6fzQulJyqX2CBJnihIyCKZaM/CWTqAl/+JXOsrNEi6LA== X-Received: by 2002:a5d:560e:0:b0:314:1ebc:6e19 with SMTP id l14-20020a5d560e000000b003141ebc6e19mr9289691wrv.64.1694513257604; Tue, 12 Sep 2023 03:07:37 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:37 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 02/11] gpiolib: add support for scope-based management to gpio_device Date: Tue, 12 Sep 2023 12:07:18 +0200 Message-Id: <20230912100727.23197-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski As the few users that need to get the reference to the GPIO device often release it right after inspecting its properties, let's add support for the automatic reference release to struct gpio_device. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- include/linux/gpio/driver.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index a2060dc3344b..a52c6cc5162b 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -609,6 +609,8 @@ struct gpio_chip *gpiochip_find(void *data, struct gpio_device *gpio_device_get(struct gpio_device *gdev); void gpio_device_put(struct gpio_device *gdev); +DEFINE_FREE(gpio_device_put, struct gpio_device *, if (_T) gpio_device_put(_T)); + bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset); From patchwork Tue Sep 12 10:07:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 721892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFAB0CA0ED4 for ; Tue, 12 Sep 2023 10:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233890AbjILKIA (ORCPT ); Tue, 12 Sep 2023 06:08:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234060AbjILKHo (ORCPT ); Tue, 12 Sep 2023 06:07:44 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1486C173D for ; Tue, 12 Sep 2023 03:07:40 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-401b3ea0656so57309985e9.0 for ; Tue, 12 Sep 2023 03:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513258; x=1695118058; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7MZjUI/NMnfmyOh6OB1AvMuCk2YD5ixBKSLX4RZNWFc=; b=qfwr1EkMM8qFs8wNofM6jBgK9fFkV3MPMU+Q8/fKY2o/+wI0K/2CebokXwXJTdnH5w cAbq9UJfrg1z38pceJjUck0bprWQfkFVI68DHZFUB0Y1wA35WytvmrGQr8KnXvHEQBs3 8AkgxfWlDOyNxqf7suSWqPW5Q9EVNlonr6SBuEoajWnUBKoDH5afBcep67SNzypjNVsK TcFYKvCrLgYMGjCac0VhTtQQA4Pt9atNDFdakrPv0TryclhX0goNVclPDJVoFQu654Xk 4Sa5Ep12GAYEiFHD3VSIbwLzB4I1/dI0ENiMqgAmt449aNtOBnxL+DC0WuGGhfbpMD2W XHjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513258; x=1695118058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7MZjUI/NMnfmyOh6OB1AvMuCk2YD5ixBKSLX4RZNWFc=; b=nNxD6KJXCy2FEm2WoeniIGBh/nLHK/WgHwkRb2NxiCXbAFAPInfO4xzizgnsZk/Cq5 bpikMK3A47GMJcK0sC9+XPTmVwMGo+yOYw0nA+6BGNZnet+pYo4qGWGB0tw8BnVv6vs9 XK3gcJmAHhbMiQtdyvkOdQK5dLGJTfgTVvpo9Wwe88dWyMO9syQMGPAOH8BLIHI/pS4J QwP6WMJ/bT52tFkexAjlO5xNikSmLRplScYF/3PzjS2jbo2S6XobKsu9FnIuEa7cED3e bv8pUOxrT6TcJiFuBxnCzUheY1uUcHg9/M9d/NgABCNxwIOR5fp59s3d4Nvk3hHFoHQ4 jgGA== X-Gm-Message-State: AOJu0Yyob9f2DSzYEDtR9mUTAamozUtmJLPnqzsM4RXZdgZrIAhz9JBz IXEl3xuv9saIc+wn2bTzEmn6FQ== X-Google-Smtp-Source: AGHT+IHF/iMMmGOTrGuo7KDLPpHqEn+YLF3zk+Y31h6l72Ks1fJ9rEJA68eUo8lhYHd+mAmgCiL5JQ== X-Received: by 2002:a05:600c:2294:b0:401:b204:3b98 with SMTP id 20-20020a05600c229400b00401b2043b98mr10678033wmf.19.1694513258428; Tue, 12 Sep 2023 03:07:38 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:38 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 03/11] gpiolib: provide gpio_device_find() Date: Tue, 12 Sep 2023 12:07:19 +0200 Message-Id: <20230912100727.23197-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski gpiochip_find() is wrong and its kernel doc is misleading as the function doesn't return a reference to the gpio_chip but just a raw pointer. The chip itself is not guaranteed to stay alive, in fact it can be deleted at any point. Also: other than GPIO drivers themselves, nobody else has any business accessing gpio_chip structs. Provide a new gpio_device_find() function that returns a real reference to the opaque gpio_device structure that is guaranteed to stay alive for as long as there are active users of it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 71 +++++++++++++++++++++++++++---------- include/linux/gpio/driver.h | 3 ++ 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f84ad54d8dbd..0371d23f0a46 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1014,16 +1014,10 @@ void gpiochip_remove(struct gpio_chip *gc) } EXPORT_SYMBOL_GPL(gpiochip_remove); -/** - * gpiochip_find() - iterator for locating a specific gpio_chip - * @data: data to pass to match function - * @match: Callback function to check gpio_chip +/* + * FIXME: This will be removed soon. * - * Similar to bus_find_device. It returns a reference to a gpio_chip as - * determined by a user supplied @match callback. The callback should return - * 0 if the device doesn't match and non-zero if it does. If the callback is - * non-zero, this function will return to the caller and not iterate over any - * more gpio_chips. + * This function is depracated, don't use. */ struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *gc, @@ -1031,21 +1025,62 @@ struct gpio_chip *gpiochip_find(void *data, { struct gpio_device *gdev; struct gpio_chip *gc = NULL; - unsigned long flags; - spin_lock_irqsave(&gpio_lock, flags); - list_for_each_entry(gdev, &gpio_devices, list) - if (gdev->chip && match(gdev->chip, data)) { - gc = gdev->chip; - break; - } - - spin_unlock_irqrestore(&gpio_lock, flags); + gdev = gpio_device_find(data, match); + if (gdev) { + gc = gdev->chip; + gpio_device_put(gdev); + } return gc; } EXPORT_SYMBOL_GPL(gpiochip_find); +/** + * gpio_device_find() - find a specific GPIO device + * @data: data to pass to match function + * @match: Callback function to check gpio_chip + * + * Returns: + * New reference to struct gpio_device. + * + * Similar to bus_find_device(). It returns a reference to a gpio_device as + * determined by a user supplied @match callback. The callback should return + * 0 if the device doesn't match and non-zero if it does. If the callback + * returns non-zero, this function will return to the caller and not iterate + * over any more gpio_devices. + * + * The callback takes the GPIO chip structure as argument. During the execution + * of the callback function the chip is protected from being freed. TODO: This + * actually has yet to be implemented. + * + * If the function returns non-NULL, the returned reference must be freed by + * the caller using gpio_device_put(). + */ +struct gpio_device *gpio_device_find(void *data, + int (*match)(struct gpio_chip *gc, + void *data)) +{ + struct gpio_device *gdev; + + /* + * Not yet but in the future the spinlock below will become a mutex. + * Annotate this function before anyone tries to use it in interrupt + * context like it happened with gpiochip_find(). + */ + might_sleep(); + + guard(spinlock_irqsave)(&gpio_lock); + + list_for_each_entry(gdev, &gpio_devices, list) { + if (gdev->chip && match(gdev->chip, data)) + return gpio_device_get(gdev); + } + + return NULL; +} +EXPORT_SYMBOL_GPL(gpio_device_find); + static int gpiochip_match_name(struct gpio_chip *gc, void *data) { const char *name = data; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index a52c6cc5162b..bf27cc8392fb 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -606,6 +606,9 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *gc, void *data)); +struct gpio_device *gpio_device_find(void *data, + int (*match)(struct gpio_chip *gc, void *data)); + struct gpio_device *gpio_device_get(struct gpio_device *gdev); void gpio_device_put(struct gpio_device *gdev); From patchwork Tue Sep 12 10:07:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 721891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC2A8CA0EC3 for ; Tue, 12 Sep 2023 10:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233997AbjILKIF (ORCPT ); Tue, 12 Sep 2023 06:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233892AbjILKHo (ORCPT ); Tue, 12 Sep 2023 06:07:44 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3577173F for ; Tue, 12 Sep 2023 03:07:40 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-401d80f4ef8so58252475e9.1 for ; Tue, 12 Sep 2023 03:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513259; x=1695118059; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BCDUk9FL9Q692ddNjdMXT5ENU2BFc69rKKghpfXciCM=; b=poGu0EP8lj+w4zbeuEzRBK6ITBxCWpNXEyUP6ifqtEhX/o9MhFQsAFi+6cobT1Yi36 cHvgIR14G9Hr+ij1G8IFoOS9NiDBjfQgdLhbP5XEmsqrnEDVESxhf7l806npe6wtVkdl 2qusW8WEBB2Vm3a1oOyiMh9wpVKRfB/GZPPQliPZGd5UTjerNLtf/fm3Tlng1t6RQnNF +2aHQ20LCScs93M3zr5/q8VGZvXP8dzgJBPAvYdH+CBLhUxLb6bIYBQAeJTqj1oS97g/ uUOn6D7VrGo7G+BAM7ZRnSucoGyGacGVLz7xPfQbuHojVOXdqwm4OKJs6aOo8qfdAbvu vH8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513259; x=1695118059; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BCDUk9FL9Q692ddNjdMXT5ENU2BFc69rKKghpfXciCM=; b=anavSlLrv+LYW5/Bxrl8LDh1Ekbluzu/bVkYUd1+zJSjxDuj8Zn9oCqjNkDGzl4lw5 ArTwk0FkljxpGaAddubMnzc+ol/i6HajF5bCt0Uz0IdJ8GRJWqmey5Mqz/4VFkg18Vzn MJjKVV0DOdF9EBTo2DTZRwuRWKnTzYDUvJW6ghKGtpmpwaOrL9aXvQjAT9jzIg3biagX CySQM2Ycrc2hI9v91QiEDIV/jm60HZG9gFjEzReAZKOVzP65mRrFhKpA7u23q4ffVSAF qKCN5qmkBxM9eKhryevrEFKIG8OiyfzyFxHYeHzWGFh57qjzCACrzp5GTGlgL5nWwVSg fPWA== X-Gm-Message-State: AOJu0Yx3LIWlGtiyDvg3eBbVSq6IG7ZuCmbEqMoyy/o6Aouw6EtnL5Ej Ucvpkn9rO3KhN0S8MUfcYB8IoA== X-Google-Smtp-Source: AGHT+IHonzMB2+V21JxFk2G89bW7yRBbI8iwIHB8aj8JCPZvn5vupWvvr6zj/Tl3xtbb6FaYGD/jfQ== X-Received: by 2002:a7b:cd82:0:b0:401:b6f6:d8fd with SMTP id y2-20020a7bcd82000000b00401b6f6d8fdmr10899242wmj.6.1694513259338; Tue, 12 Sep 2023 03:07:39 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:38 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 04/11] gpiolib: provide gpio_device_find_by_label() Date: Tue, 12 Sep 2023 12:07:20 +0200 Message-Id: <20230912100727.23197-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski By far the most common way of looking up GPIO devices is using their label. Provide a helpers for that to avoid every user implementing their own matching function. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0371d23f0a46..9f20311e4c1a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1081,6 +1082,26 @@ struct gpio_device *gpio_device_find(void *data, } EXPORT_SYMBOL_GPL(gpio_device_find); +static int gpio_chip_match_by_label(struct gpio_chip *gc, void *label) +{ + return gc->label && !strcmp(gc->label, label); +} + +/** + * gpio_device_find_by_label() - wrapper around gpio_device_find() finding the + * GPIO device by its backing chip's label + * @label: Label to lookup + * + * Returns: + * Reference to the GPIO device or NULL. Reference must be released with + * gpio_device_put(). + */ +struct gpio_device *gpio_device_find_by_label(const char *label) +{ + return gpio_device_find((void *)label, gpio_chip_match_by_label); +} +EXPORT_SYMBOL_GPL(gpio_device_find_by_label); + static int gpiochip_match_name(struct gpio_chip *gc, void *data) { const char *name = data; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index bf27cc8392fb..bcf418441ef2 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -608,6 +608,7 @@ struct gpio_chip *gpiochip_find(void *data, struct gpio_device *gpio_device_find(void *data, int (*match)(struct gpio_chip *gc, void *data)); +struct gpio_device *gpio_device_find_by_label(const char *label); struct gpio_device *gpio_device_get(struct gpio_device *gdev); void gpio_device_put(struct gpio_device *gdev); From patchwork Tue Sep 12 10:07:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC0A3CA0EC3 for ; Tue, 12 Sep 2023 10:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234018AbjILKIH (ORCPT ); Tue, 12 Sep 2023 06:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233958AbjILKHp (ORCPT ); Tue, 12 Sep 2023 06:07:45 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7841988 for ; Tue, 12 Sep 2023 03:07:41 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-402c46c49f4so58077795e9.1 for ; Tue, 12 Sep 2023 03:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513260; x=1695118060; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A6yCpRsJ9YDulO6YNUQQZrVJSWHh877hWXgywBs804o=; b=TpQxjVY+ICyqKwIHOyu+x0bHKtufJJxchZCIdaAx/ZI5LUYQE6fVKZJQojUOqIQsOz jB83+T/Bo0uv8S0/yRNnktVNbjtgHn6UpQycN4Yh6XyQR0sIWoGp1iUftf3u356UjWNS J2KJNUP76h6SHcIWOg7/cE6lf3A7WDSBoODGyRIvDGuxiOFKgGxMrYVYEYd80DYdykhm h+Bo/ItDxUOXtt3kiOjhBJaE4CC8EEenjZgroYoZBxCnJXZuG87MdtTScxU64xhF4+rh +cGObF+eiIt41IQjc9/syUcmMNYVdyLFZcUEJQTqetWKhru4PPNue5X7oEudDb68x1Mv htpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513260; x=1695118060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A6yCpRsJ9YDulO6YNUQQZrVJSWHh877hWXgywBs804o=; b=eP3k7VZpfJfyjj2J58ZOBu5W4n+mBVbR5M/Qu5OlO4et/uPdcsFpry8kKXxENxgRcK GC1J9thQHSPgEPvn/eAnEM3htXmJ+t3t0ktq+Oaste37/U6tVWXzuMDZ0JPPvQ0yF6Tb iYp5MYb4mdPa8N7uzfiNlVcIwInBqJZAUIImHWpW2GDWPXtsMwyJRz8pmI9CX09O3CfL lAFbzOdXWQD4j9RsCN955qQ0t5PLFRaBf5TNONpAJ4aDn4g0cPxeZ218UOdI0FXZbE7+ gkaYOgzAY3DpmL8Gk8DmjADFQ5d1XVMktXnddcj5cWyvTUJCMI2JR3pGRsFb4j0KdJB5 BFPQ== X-Gm-Message-State: AOJu0YxOJAzsz7tnQPIS8CXvkYjcPbOewyz7o7kQtiIbnAIpw+nQ44Nw HufbHPIKG9nn4oMl1cDwVJk7mg== X-Google-Smtp-Source: AGHT+IFcT7aRuxPokXUdCiwhobRYyRamsHE6NPEllDWPFOmdrpuZSdnUT0Q8AdVtMC65mNulQccRLA== X-Received: by 2002:a05:600c:204c:b0:401:23fc:1f92 with SMTP id p12-20020a05600c204c00b0040123fc1f92mr10852185wmg.25.1694513260155; Tue, 12 Sep 2023 03:07:40 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:39 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 05/11] gpiolib: provide gpio_device_get_desc() Date: Tue, 12 Sep 2023 12:07:21 +0200 Message-Id: <20230912100727.23197-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Getting the GPIO descriptor directly from the gpio_chip struct is dangerous as we don't take the reference to the underlying GPIO device. In order to start working towards removing gpiochip_get_desc(), let's provide a safer variant that works with an existing reference to struct gpio_device. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 45 +++++++++++++++++++++++++++---------- include/linux/gpio/driver.h | 2 ++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9f20311e4c1a..e413136d1566 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -147,27 +147,48 @@ struct gpio_desc *gpio_to_desc(unsigned gpio) } EXPORT_SYMBOL_GPL(gpio_to_desc); -/** - * gpiochip_get_desc - get the GPIO descriptor corresponding to the given - * hardware number for this chip - * @gc: GPIO chip - * @hwnum: hardware number of the GPIO for this chip - * - * Returns: - * A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists - * in the given chip for the specified hardware number. - */ +/* This function is deprecated and will be removed soon, don't use. */ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum) { - struct gpio_device *gdev = gc->gpiodev; + return gpio_device_get_desc(gc->gpiodev, hwnum); +} +EXPORT_SYMBOL_GPL(gpiochip_get_desc); + +/** + * gpio_device_get_desc() - get the GPIO descriptor corresponding to the given + * hardware number for this GPIO device + * @gdev: GPIO device to get the descriptor from + * @hwnum: hardware number of the GPIO for this chip + * + * Returns: + * A pointer to the GPIO descriptor or %EINVAL if no GPIO exists in the given + * chip for the specified hardware number or %ENODEV if the underlying chip + * already vanished. + * + * The reference count of struct gpio_device is *NOT* increased like when the + * GPIO is being requested for exclusive usage. It's up to the caller to make + * sure the GPIO device will stay alive together with the descriptor returned + * by this function. + */ +struct gpio_desc * +gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) +{ + struct gpio_chip *gc = gdev->chip; + + /* + * FIXME: This will be locked once we protect gdev->chip everywhere + * with SRCU. + */ + if (!gc) + return ERR_PTR(-ENODEV); if (hwnum >= gdev->ngpio) return ERR_PTR(-EINVAL); return &gdev->descs[hwnum]; } -EXPORT_SYMBOL_GPL(gpiochip_get_desc); +EXPORT_SYMBOL_GPL(gpio_device_get_desc); /** * desc_to_gpio - convert a GPIO descriptor to the integer namespace diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index bcf418441ef2..5c0f2ccfd51b 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -767,6 +767,8 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, void gpiochip_free_own_desc(struct gpio_desc *desc); struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); +struct gpio_desc * +gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum); #ifdef CONFIG_GPIOLIB From patchwork Tue Sep 12 10:07:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 721890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A9ECA0ECA for ; Tue, 12 Sep 2023 10:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233833AbjILKIR (ORCPT ); Tue, 12 Sep 2023 06:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234070AbjILKHq (ORCPT ); Tue, 12 Sep 2023 06:07:46 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77F0C198C for ; Tue, 12 Sep 2023 03:07:42 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-402d499580dso57439335e9.1 for ; Tue, 12 Sep 2023 03:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513261; x=1695118061; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yjw2Sx7Aq1HDg3hSjQzpJvKG22q88QmH6ugiYX5BMXI=; b=gn6MQKLQwHECLcrK0PWXrM4E1AH349KTmcy0Fq5UGSE7OP+q4MuhoKFjwOX4jCioSv G2nNKuHafWzy/PvuJh0r+hUGic/F/3s+Bt6EGzvVU58kUlbhtC0xDKwTzUJzWNymnWm7 K3tYZqZRSdkWVpSj6mv4YvdZSkqeaTQgswJCDyZ1nvLKf5HJHzu3oM1+FpfFSNr6K6y2 7OmWmQcGRW4N9A7VokoJx7mhcwCPr9KZ9MgXuBXlakLoTy6x0JK9f7/iG1++3chN3mYi Tb2otc/Ycqh19MKhGZlHecqeudkpsPztVQYE/x2Vm6LvxR1mA7GFQALXD/yxSWLqS1/D Bf5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513261; x=1695118061; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yjw2Sx7Aq1HDg3hSjQzpJvKG22q88QmH6ugiYX5BMXI=; b=niEAZfFB+rgqQvrQzl7ARAPKRnFiIGs4Sl/uBLbFax07Li9UTOyT+xJXilkhBiSQjH AYTsWLV/zKA68Rjjo4WGDnlAaW3zVjiR+2mkwv9GT+Z1u6elpUGhXtJjo089R82eb9WP bK0hU9Q0gneLbK3lX/j6bNIS6PudRIAYhv76W03T1k9TONsM9s5DdFjy+PXgEWHma5eN WGW9u+fXhfNK5uECJMIc6q1cuQsrB3D5TQgmtJ1V6AFX95+NyV/KfXoXfRXK4scw+lU4 7c976IzeDs7BqD2Fg30IS5KEVGiPfdl1qFv5Z7WjzUYkshocp2dXJxnieaJ/BhXSWBRF oJtA== X-Gm-Message-State: AOJu0Yx6RmfFEK23OEhNwh90wwxT8zO8WQRaTB85pVlRhuH0aOfXv5HD YrDHNWYZAe+UZR2RSUAWuaTwqc7BBvRu6L5unTE= X-Google-Smtp-Source: AGHT+IHGPSa2JUipRzSqKipXpdiSn+a7Tbfpw/9aU9Pk43iaDiaKJin4lOiQ5XXdbJN9KVtTdNY/eQ== X-Received: by 2002:a7b:c412:0:b0:3fb:df34:176e with SMTP id k18-20020a7bc412000000b003fbdf34176emr10913436wmi.31.1694513260984; Tue, 12 Sep 2023 03:07:40 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:40 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 06/11] gpiolib: reluctantly provide gpio_device_get_chip() Date: Tue, 12 Sep 2023 12:07:22 +0200 Message-Id: <20230912100727.23197-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski The process of converting all unauthorized users of struct gpio_chip to using dedicated struct gpio_device function will be long so in the meantime we must provide a way of retrieving the pointer to struct gpio_chip from a GPIO device. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ include/linux/gpio/driver.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e413136d1566..224e0d330009 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -219,6 +219,27 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(gpiod_to_chip); +/** + * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device + * @gdev: GPIO device + * + * Returns: + * Address of the GPIO chip backing this device. + * + * Until we can get rid of all non-driver users of struct gpio_chip, we must + * provide a way of retrieving the pointer to it from struct gpio_device. This + * is *NOT* safe as the GPIO API is considered to be hot-unpluggable and the + * chip can dissapear at any moment (unlike reference-counted struct + * gpio_device). + * + * Use at your own risk. + */ +struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) +{ + return gdev->chip; +} +EXPORT_SYMBOL_GPL(gpio_device_get_chip); + /* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base(int ngpio) { diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 5c0f2ccfd51b..a583e539263e 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -770,6 +770,8 @@ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); struct gpio_desc * gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum); +struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev); + #ifdef CONFIG_GPIOLIB /* lock/unlock as IRQ */ From patchwork Tue Sep 12 10:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53726CA0EC3 for ; Tue, 12 Sep 2023 10:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233687AbjILKIS (ORCPT ); Tue, 12 Sep 2023 06:08:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233947AbjILKHr (ORCPT ); Tue, 12 Sep 2023 06:07:47 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D761BB for ; Tue, 12 Sep 2023 03:07:43 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31f737b8b69so4949948f8f.3 for ; Tue, 12 Sep 2023 03:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513262; x=1695118062; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lK3han4CVz5LHUOmuD0tfQkarnpldPL2EDThSOp4uoo=; b=hKkpj9ebeywUDPpZfqGwEIXFBQG+IhXqeLEzQJ9UHbyxA+lMwhhFu56ute+bcz9UFy 7TcTbGdAlXpHOjFqRn95P/fTqi7YqHot1pScejxHLqoEa9VrPINyM7SIiSESr2cUwYjQ UNgIBM/P9BwBFa5IJyAaEAUbx5ae4dQrYCKDPzMl0/b5IkijYDqJMWzISZmpXq6xZph7 AHoegF2nXvUvs7kVPfHqEuVsElkLKDkmvUf7EuJPdotUqYOQAD75WmlxP2h1MSvmuuRU 9LNnX4ejEWkf/Tu3uDxtI4YQp7zb2H8pzc4yVa3cCps3iOmKTbAqaGPcTk/+wrdpnn/D 4phg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513262; x=1695118062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lK3han4CVz5LHUOmuD0tfQkarnpldPL2EDThSOp4uoo=; b=fdLWFvg8e7MKJEtGXi+mPLrW8BAbYy1pAjCxhF4KGmPp9fTOcwUB7t0U4WPAb4YGV2 I4JFeWN8WjNoAXAmRcNG8XHXLl3Uqt56ac+SISONNX8EVNvwtsgdtTNS4q5o7dqQKRpC AcoSNcF+Dav/0of2kkxF9baIiT3SOPVlY4HSDJ1J8TQFwfDQnIYy//knkzkdrdoCrfDA 1gKbpx5A4vvgop1CGro8ypw2SIu5RtN+VR3phtv71rhLCYu7IetGsjdVgGDqLaR9FhNV NXNoWjA/2+As1dXOeF0U0c6iXiXDSVf6jaHDFsrPODaKND7dL9QX6CjCOieBB6ZqLnYF xCiw== X-Gm-Message-State: AOJu0YwasWb2MMV9XYvpv6QOpRccv1gnV2n5ARREDasiEwSo84VDew8A ZLRpNyF7tug+9cgivsi5UEVtTg== X-Google-Smtp-Source: AGHT+IHQaoqjxtbbCR/GgutlU02aJZq/Tzbxpk5PviNsqzIRCPSQARYZbf/TjHfrpO4UdF1ds2ob1Q== X-Received: by 2002:a5d:4ac3:0:b0:317:6cc7:6b21 with SMTP id y3-20020a5d4ac3000000b003176cc76b21mr9864728wrs.69.1694513261863; Tue, 12 Sep 2023 03:07:41 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:41 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 07/11] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label() Date: Tue, 12 Sep 2023 12:07:23 +0200 Message-Id: <20230912100727.23197-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Remove all remaining uses of find_chip_by_name() (and subsequently: gpiochip_find()) from gpiolib.c and use the new gpio_device_find_by_label() instead. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 224e0d330009..a10d1d663524 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1144,18 +1144,6 @@ struct gpio_device *gpio_device_find_by_label(const char *label) } EXPORT_SYMBOL_GPL(gpio_device_find_by_label); -static int gpiochip_match_name(struct gpio_chip *gc, void *data) -{ - const char *name = data; - - return !strcmp(gc->label, name); -} - -static struct gpio_chip *find_chip_by_name(const char *name) -{ - return gpiochip_find((void *)name, gpiochip_match_name); -} - /** * gpio_device_get() - Increase the reference count of this GPIO device * @gdev: GPIO device to increase the refcount for @@ -3907,21 +3895,22 @@ EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table); */ void gpiod_add_hogs(struct gpiod_hog *hogs) { - struct gpio_chip *gc; struct gpiod_hog *hog; mutex_lock(&gpio_machine_hogs_mutex); for (hog = &hogs[0]; hog->chip_label; hog++) { + struct gpio_device *gdev __free(gpio_device_put) = NULL; + list_add_tail(&hog->list, &gpio_machine_hogs); /* * The chip may have been registered earlier, so check if it * exists and, if so, try to hog the line now. */ - gc = find_chip_by_name(hog->chip_label); - if (gc) - gpiochip_machine_hog(gc, hog); + gdev = gpio_device_find_by_label(hog->chip_label); + if (gdev) + gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); } mutex_unlock(&gpio_machine_hogs_mutex); @@ -3976,13 +3965,16 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, struct gpio_desc *desc = ERR_PTR(-ENOENT); struct gpiod_lookup_table *table; struct gpiod_lookup *p; + struct gpio_chip *gc; table = gpiod_find_lookup_table(dev); if (!table) return desc; for (p = &table->table[0]; p->key; p++) { - struct gpio_chip *gc; + struct gpio_device *gdev __free(gpio_device_put) = NULL; + + gc = gpio_device_get_chip(gdev); /* idx must always match exactly */ if (p->idx != idx) @@ -4004,9 +3996,8 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, return ERR_PTR(-EPROBE_DEFER); } - gc = find_chip_by_name(p->key); - - if (!gc) { + gdev = gpio_device_find_by_label(p->key); + if (!gdev) { /* * As the lookup table indicates a chip with * p->key should exist, assume it may @@ -4022,7 +4013,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, if (gc->ngpio <= p->chip_hwnum) { dev_err(dev, "requested GPIO %u (%u) is out of range [0..%u] for chip %s\n", - idx, p->chip_hwnum, gc->ngpio - 1, + idx, p->chip_hwnum, gdev->chip->ngpio - 1, gc->label); return ERR_PTR(-EINVAL); } From patchwork Tue Sep 12 10:07:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 721889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59EFCCA0EC3 for ; Tue, 12 Sep 2023 10:08:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234055AbjILKI2 (ORCPT ); Tue, 12 Sep 2023 06:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233979AbjILKHs (ORCPT ); Tue, 12 Sep 2023 06:07:48 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B25B10F4 for ; Tue, 12 Sep 2023 03:07:44 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-401d10e3e54so58968805e9.2 for ; Tue, 12 Sep 2023 03:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513262; x=1695118062; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wn0WZO6Z9Iv9tVXCCKVBW/P7aG4mocAlzskQGft1Ggk=; b=roarD3Np9PPSsurYw9g0+mefrC+xDObkFL0TUzFSFRKILUDa6LD7jYaQmDd9s4u8Fl MZnE2fmLJTakPxydcaYEKXF+gXD4tXPrZ18YugPE+K1GTl/8lylBj3xAYFuZu+NcRyyG 85Pmdroa97bgDazsWJjkorEVmJsvir51Q6cmlpQQb1FYV/YFFpbzXaVaLaM23n45iTza ECTNfgKrvu6WIW5CO5aOxw22jF8Aht1T1jDDkKwD4U2TIWB218+g3GKnqSkC7aVmjU5P V9al6W2XX7mFmgyjptVGWAglovNL8Xkhiv9kH93G9UGYqitItJPAOmQXg31pDsjg7pqT t/Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513262; x=1695118062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wn0WZO6Z9Iv9tVXCCKVBW/P7aG4mocAlzskQGft1Ggk=; b=OaW+aZliwErfyXV+xnNP45v6QCMUVs+SKTPSRmn3WAajzlBSv/uRPMAcjbCZxlCHRv 6LMzZbFoe9LMDfMcOmLkT1+yX9rbbq4liB/ESae9Cxt16hbvti3J7+yXKyG0hw6LEMIg OnZTwi42cPmlZYlUX1ij1OFs3ffYg4fHexgntQOffkWPdNzDElL51Qk5z4pe78F6rH3P UoQRDvT2B0zHyBL6apoyzY+8rxxEshYnC091vwucvJ3hUz4iCSgaMRhuhFeV1V5zZFA8 vrZjdTQn3XVUgNZDHF6LlzPayXJNB9TuZDB3cov3N6qmUU2gN720kYv9c3f6M2ao8nUO uR2w== X-Gm-Message-State: AOJu0Yw9ue1POaEpVYMQc0xjfD79hX/Y1ISN9Psnb6Bw+pQ8+1Hx55lO KGNuj0Bh2QE586dUDFcbNx5vyg== X-Google-Smtp-Source: AGHT+IH2daZg8uXPJjhCYIl6GfQ86zNLYz2ol3af+dz2gM+RSOisg+3ShVkHoECGNO+/nJOnpRG5eg== X-Received: by 2002:adf:fe8c:0:b0:317:c2a9:9b0c with SMTP id l12-20020adffe8c000000b00317c2a99b0cmr10362258wrr.50.1694513262659; Tue, 12 Sep 2023 03:07:42 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:42 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 08/11] gpio: of: replace gpiochip_find_* with gpio_device_find_* Date: Tue, 12 Sep 2023 12:07:24 +0200 Message-Id: <20230912100727.23197-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We're porting all users of gpiochip_find() to using gpio_device_find(). Update the OF GPIO code. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-of.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 5515f32cf19b..ff13aa079a22 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -127,10 +127,10 @@ static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data) chip->of_xlate(chip, gpiospec, NULL) >= 0; } -static struct gpio_chip *of_find_gpiochip_by_xlate( - struct of_phandle_args *gpiospec) +static struct gpio_device * +of_find_gpio_device_by_xlate(struct of_phandle_args *gpiospec) { - return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate); + return gpio_device_find(gpiospec, of_gpiochip_match_node_and_xlate); } static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, @@ -362,8 +362,8 @@ static void of_gpio_flags_quirks(const struct device_node *np, static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np, const char *propname, int index, enum of_gpio_flags *flags) { + struct gpio_device *gdev __free(gpio_device_put) = NULL; struct of_phandle_args gpiospec; - struct gpio_chip *chip; struct gpio_desc *desc; int ret; @@ -375,13 +375,13 @@ static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np, return ERR_PTR(ret); } - chip = of_find_gpiochip_by_xlate(&gpiospec); - if (!chip) { + gdev = of_find_gpio_device_by_xlate(&gpiospec); + if (!gdev) { desc = ERR_PTR(-EPROBE_DEFER); goto out; } - desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags); + desc = of_xlate_and_get_gpiod_flags(gdev->chip, &gpiospec, flags); if (IS_ERR(desc)) goto out; @@ -813,16 +813,16 @@ static int of_gpiochip_match_node(struct gpio_chip *chip, void *data) return device_match_of_node(&chip->gpiodev->dev, data); } -static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np) +static struct gpio_device *of_find_gpio_device_by_node(struct device_node *np) { - return gpiochip_find(np, of_gpiochip_match_node); + return gpio_device_find(np, of_gpiochip_match_node); } static int of_gpio_notify(struct notifier_block *nb, unsigned long action, void *arg) { + struct gpio_device *gdev __free(gpio_device_put) = NULL; struct of_reconfig_data *rd = arg; - struct gpio_chip *chip; int ret; /* @@ -839,11 +839,11 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action, if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) return NOTIFY_DONE; - chip = of_find_gpiochip_by_node(rd->dn->parent); - if (chip == NULL) + gdev = of_find_gpio_device_by_node(rd->dn->parent); + if (!gdev) return NOTIFY_DONE; /* not for us */ - ret = of_gpiochip_add_hog(chip, rd->dn); + ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn); if (ret < 0) { pr_err("%s: failed to add hogs for %pOF\n", __func__, rd->dn); @@ -856,11 +856,11 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action, if (!of_node_check_flag(rd->dn, OF_POPULATED)) return NOTIFY_DONE; /* already depopulated */ - chip = of_find_gpiochip_by_node(rd->dn->parent); - if (chip == NULL) + gdev = of_find_gpio_device_by_node(rd->dn->parent); + if (!gdev) return NOTIFY_DONE; /* not for us */ - of_gpiochip_remove_hog(chip, rd->dn); + of_gpiochip_remove_hog(gpio_device_get_chip(gdev), rd->dn); of_node_clear_flag(rd->dn, OF_POPULATED); return NOTIFY_OK; } From patchwork Tue Sep 12 10:07:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC68BCA0ECF for ; Tue, 12 Sep 2023 10:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233987AbjILKIp (ORCPT ); Tue, 12 Sep 2023 06:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233988AbjILKHt (ORCPT ); Tue, 12 Sep 2023 06:07:49 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6CCB1701 for ; Tue, 12 Sep 2023 03:07:44 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31f853f2f3aso2160721f8f.0 for ; Tue, 12 Sep 2023 03:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513263; x=1695118063; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vuDRdpEcQdOPJO6ECwwAIvUZv3DHwFUskaWy08I+lxE=; b=R+pdXZJsbg36bQS1IruCjbSCZYbDuBqAePFsDwMNtU+HYxXzxTzsvwl1OO6VhRPnQ4 j9TiBLLmFlzEMZ2Apyz5XnHZJgSkzjPB2vbaT/X5gHDKej6KL0CSdFwYITThK3ojrRoF +keT6Fyg2/WrzL2wuuugSin5ZHdZtCqhbHwFXCAh9gLtreUKHEKO6aRGmeWvAsu3wRzx V1zd3uNPJd6umy4UdJaFbEEWRX3q8ZmefA/aO3mT+Q5eEhAhgOU6ScK/irf+xxUAsjml BHwe2e2QvsW0sN1AIhiYoYhSa7vODFkCXvCXJnfmUD9oPvxaKr7/WOyr+nIn0y7eAqkR EsmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513263; x=1695118063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vuDRdpEcQdOPJO6ECwwAIvUZv3DHwFUskaWy08I+lxE=; b=pNIpt/aeN4xzlu/oQ2BCt+qHEKQpChdpCqikFX3/uyRwFwryQBB6V7ltGja660INsE 9B5Yg1i+6+rwYQ/Pl01iPh3l1kPSwOhYzqOW0HgqEqsS9EpbFEw0sYv1KHPCwND9c2i/ 0nfo6DxHq1CYsSAxXbLnJ8ktNTySKZ02ZmJxbWmFv7lD0aMZOoh5LMDb0+yV2ZGi6LJc n57pE5h1qfXc2lIAdR/oyWn0rlAlTe5lNWXgJvDwnTkQ/cgvSBGnW94fgkQHrKRk1630 R13regEVHcbeoEMLz123gTFZ5/GOii/lZMWn/yWXZWqy945eRwri8Ry5wBk498jX5c9x h8mA== X-Gm-Message-State: AOJu0YwmfeecMkDguK3dcLQeZTRG7+jMcFLYIoSiDppAI6NH9YoePkrZ R2+nH1SDo4hktOPgIDqBD/CDHw== X-Google-Smtp-Source: AGHT+IHcZIGJJ9r3+wTUOrgnZTM/fZOZHsWqZAXQxLGYEGgNMLSjHxrTMHQMpFSrR8HRTFvJP12vHw== X-Received: by 2002:a5d:525c:0:b0:318:720c:bb3 with SMTP id k28-20020a5d525c000000b00318720c0bb3mr1373602wrc.20.1694513263436; Tue, 12 Sep 2023 03:07:43 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:43 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 09/11] gpio: acpi: replace gpiochip_find() with gpio_device_find() Date: Tue, 12 Sep 2023 12:07:25 +0200 Message-Id: <20230912100727.23197-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We're porting all users of gpiochip_find() to using gpio_device_find(). Update the ACPI GPIO code. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-acpi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 17a86bdd9609..ec618962a5cb 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -143,7 +143,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) */ static struct gpio_desc *acpi_get_gpiod(char *path, unsigned int pin) { - struct gpio_chip *chip; + struct gpio_device *gdev __free(gpio_device_put) = NULL; acpi_handle handle; acpi_status status; @@ -151,11 +151,15 @@ static struct gpio_desc *acpi_get_gpiod(char *path, unsigned int pin) if (ACPI_FAILURE(status)) return ERR_PTR(-ENODEV); - chip = gpiochip_find(handle, acpi_gpiochip_find); - if (!chip) + gdev = gpio_device_find(handle, acpi_gpiochip_find); + if (!gdev) return ERR_PTR(-EPROBE_DEFER); - return gpiochip_get_desc(chip, pin); + /* + * FIXME: keep track of this reference somehow instead of putting it + * here. + */ + return gpio_device_get_desc(gdev, pin); } /** From patchwork Tue Sep 12 10:07:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 722352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48CF4CA0EC3 for ; Tue, 12 Sep 2023 10:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234045AbjILKIq (ORCPT ); Tue, 12 Sep 2023 06:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234074AbjILKHt (ORCPT ); Tue, 12 Sep 2023 06:07:49 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7121994 for ; Tue, 12 Sep 2023 03:07:45 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-31fa15f4cc6so2158519f8f.2 for ; Tue, 12 Sep 2023 03:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513264; x=1695118064; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MflPL+QKb28SLjr67nvfLFxWVRN50mSzldVQJo+IR1w=; b=iEP3Lt9EyU3b2KrO+GJiN3Yb+RnNRx9ciCxuP8MsS0SLIwrXRgZReq+a+AI0zrL9V7 0LBWGMbRNHMxTXkfQnwT017RVqEdKmc/0AmjGU7L0SAOsZoKUxzHxqjxwt+KA39kZ9pv oYPIXhmZ7+tnEopx5gT4xFuixVS/ZrCGmmN+i5VaAtC01rQ5M+/xBve8WRvAuRPVAdwr wNYLVvFjkRo0htsKHWWmO8YTSb09vxMcsTjd10qQ8/QOHo8plK6gn6qWZTZsjwJKGOEl jXLRkelujB/imquKTyodR6+wGMdpCSQlVA4bVnIFjbK7GSTUpKgso8izMW6B7hVA1PNU Knbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513264; x=1695118064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MflPL+QKb28SLjr67nvfLFxWVRN50mSzldVQJo+IR1w=; b=WMeMYcKOElSXWz/kARHK3KmxGtrTi03OMRo1x02szErC+yk5xyhXIL+bHkDQe9zACg p2UTdaQtAu+wlEbVC71Z4aDuW/s03I3XJ+ahomm6CrxpWaAZCaiyUo8sGpgM8M2RGJwT D26StyysWmpw+w92TNhRUjMXqY1nwpn4BbrbsHNVTeoNyfwczzBcFMDA7XH4LMSQ92xH QcEuBBVgSVsFHzTRIdPTPe9IRLfl9yP2tfctHRovpX2GQtd4kOVDg04QlIl20zmWEuk/ j6+MaoDLwBEISGEa2if5IRFQ4wUu5u8uCvgtGD9xsltEeUm22omV4Rgp06SMmmegEqMz hEMA== X-Gm-Message-State: AOJu0Yx4uKBgfW1CGhpdAH8dwyt45mvuFD5scE8I+OW0YjZ/HhW8Wjt2 SWEm5SeXrsKPWTF1Cj5ooFL4aA== X-Google-Smtp-Source: AGHT+IF6appF+Bc1SNs12WHBJet/EEUF/e9LtN/Bq72htXDMX5lzxciYf3JqP47+0WwTHb5z1IuJEA== X-Received: by 2002:adf:eb46:0:b0:317:5a99:4549 with SMTP id u6-20020adfeb46000000b003175a994549mr9000560wrn.0.1694513264267; Tue, 12 Sep 2023 03:07:44 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:43 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 10/11] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label() Date: Tue, 12 Sep 2023 12:07:26 +0200 Message-Id: <20230912100727.23197-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We're porting all users of gpiochip_find() to using gpio_device_find(). Update the swnode GPIO code. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-swnode.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c index b5a6eaf3729b..33c4b1a6c3c1 100644 --- a/drivers/gpio/gpiolib-swnode.c +++ b/drivers/gpio/gpiolib-swnode.c @@ -31,31 +31,26 @@ static void swnode_format_propname(const char *con_id, char *propname, strscpy(propname, "gpios", max_size); } -static int swnode_gpiochip_match_name(struct gpio_chip *chip, void *data) +static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode) { - return !strcmp(chip->label, data); -} + const struct software_node *gdev_node; + struct gpio_device *gdev; -static struct gpio_chip *swnode_get_chip(struct fwnode_handle *fwnode) -{ - const struct software_node *chip_node; - struct gpio_chip *chip; - - chip_node = to_software_node(fwnode); - if (!chip_node || !chip_node->name) + gdev_node = to_software_node(fwnode); + if (!gdev_node || !gdev_node->name) return ERR_PTR(-EINVAL); - chip = gpiochip_find((void *)chip_node->name, swnode_gpiochip_match_name); - return chip ?: ERR_PTR(-EPROBE_DEFER); + gdev = gpio_device_find_by_label((void *)gdev_node->name); + return gdev ?: ERR_PTR(-EPROBE_DEFER); } struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int idx, unsigned long *flags) { + struct gpio_device *gdev __free(gpio_device_put) = NULL; const struct software_node *swnode; struct fwnode_reference_args args; - struct gpio_chip *chip; struct gpio_desc *desc; char propname[32]; /* 32 is max size of property name */ int error; @@ -77,12 +72,16 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, return ERR_PTR(error); } - chip = swnode_get_chip(args.fwnode); + gdev = swnode_get_gpio_device(args.fwnode); fwnode_handle_put(args.fwnode); - if (IS_ERR(chip)) - return ERR_CAST(chip); + if (IS_ERR(gdev)) + return ERR_CAST(gdev); - desc = gpiochip_get_desc(chip, args.args[0]); + /* + * FIXME: The GPIO device reference is put at return but the descriptor + * is passed on. Find a proper solution. + */ + desc = gpio_device_get_desc(gdev, args.args[0]); *flags = args.args[1]; /* We expect native GPIO flags */ pr_debug("%s: parsed '%s' property of node '%pfwP[%d]' - status (%d)\n", From patchwork Tue Sep 12 10:07:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 721888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA7DDCA0ED2 for ; Tue, 12 Sep 2023 10:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbjILKIr (ORCPT ); Tue, 12 Sep 2023 06:08:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233257AbjILKHw (ORCPT ); Tue, 12 Sep 2023 06:07:52 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C29170B for ; Tue, 12 Sep 2023 03:07:46 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31dd10c2b8bso5319479f8f.3 for ; Tue, 12 Sep 2023 03:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694513265; x=1695118065; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MZXaGIIfZuiGEdZwV32Js1I7wu0xbFZLpMopu8S/63c=; b=CBcLKpVmpJjHh2XVmijaPTM/EXPaXhgsBZpC8keybf9lw22n79aDUGIEcVTYDPSAak IrChIbIqM2FYT1SzMUao7fDqX0feTaXnihtECI1rcBhcYqcak25R+u6uLcfcyVQsvRBG 7ivY1TP1nAl9Zjv1uybaFM5n0dtkl7S2U7L5G8XDI08kn3P8h6QtAZwKsoULMG1FY53u 0Rzjnb0beQH4vF7dKbxC9yXNb8iWqdFhGz+lbrcE7DhnDSPVDRq9xGLFmhSj5CuNPFie VR9BGsii67PjsNhwDqcpsffeCfoRo9BpBjfafK+cSg3e2ozTywwrjUzkFdspOgkpEe40 Hl7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694513265; x=1695118065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MZXaGIIfZuiGEdZwV32Js1I7wu0xbFZLpMopu8S/63c=; b=qpyNnf6T6SAGvXbANmbzZcsQSPF2X/9xaxBKqlYhAYdavMijo+R6nhlH1DLODz65z9 soOjNWW14KmeMOaFY9BRpV47KQ1GuguTWpGbTqDQCaYdF6ilrVNKKDpSapXNrF41ERjs RdRprTG+cwHsbcR3cxVoSyhtvzy+QM6FH/zlzNqpAam3Q9/aSYWUDmSCGflpSv1T/Xr2 YAkG2BfK+NcrfFDy3X/Y3lHNznfJXVeYkt/mq+nYHgzifPbJwQp4l+OCP2sewBJZwrSP D9IiDTE/B8lBFmGWowHjO5IQM2FwQ5p83y7N7KiKdpzuEPVj55jUuL/YuCti9GsYE/O4 yCTQ== X-Gm-Message-State: AOJu0YzCgzu8CRIA7Nuq7TIansgdQ05ogigCqt3OCiWUzu3xzCmEMkPr 6i9LWUZGszqtq5pQMNCVblqrPQ== X-Google-Smtp-Source: AGHT+IGZflhMvOl/dEeCICiYZ6lX6s/c7XUmqeokfy0VRtRYkBJuPqHSImz1gPZLf27bK6JsQEwdmg== X-Received: by 2002:adf:e485:0:b0:319:6c90:5274 with SMTP id i5-20020adfe485000000b003196c905274mr9384628wrm.30.1694513265100; Tue, 12 Sep 2023 03:07:45 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:907f:4cd7:f0ae:6b2a]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b0031ae8d86af4sm12351417wrm.103.2023.09.12.03.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 03:07:44 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 11/11] gpio: sysfs: drop the mention of gpiochip_find() from sysfs code Date: Tue, 12 Sep 2023 12:07:27 +0200 Message-Id: <20230912100727.23197-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912100727.23197-1-brgl@bgdev.pl> References: <20230912100727.23197-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We have removed all callers of gpiochip_find() so don't mention it in gpiolib-sysfs.c. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 50503a4525eb..6f309a3b2d9a 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -814,7 +814,7 @@ static int __init gpiolib_sysfs_init(void) * gpiochip_sysfs_register() acquires a mutex. This is unsafe * and needs to be fixed. * - * Also it would be nice to use gpiochip_find() here so we + * Also it would be nice to use gpio_device_find() here so we * can keep gpio_chips local to gpiolib.c, but the yield of * gpio_lock prevents us from doing this. */