From patchwork Wed Sep 27 14:29: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: 727154 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3759C8D2 for ; Wed, 27 Sep 2023 14:29:39 +0000 (UTC) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E82C3191 for ; Wed, 27 Sep 2023 07:29:37 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40572aeb73cso81078645e9.3 for ; Wed, 27 Sep 2023 07:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824976; x=1696429776; 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=2Be4sSYl7+rX2U8AdvQGMmIAmC4om8V069XxAlmXPmjXEBCtwzueVqzfoXra3zy6aj ci08IPZfzwTPTzvqd812mI+67Cde8gIVCAenB5rnD6Zv9we4kfFdpxgwwQ09rSem1sOt gLhE8kku/5CW0g8lzysNmOJqwLujgTFOOOf1TXIgLPbFtl7+TCAjRe1Uy/kzI9pf630p su7eBb+LeqiDJ/GOCPXZTdWmJSGlXFaHcy/UiUOkNGpd8NmhyQIiYYI5zMVIPZRxnpoL fAqfo19tSzlvtxV9qdOgJOIqyY03Ljdp9w0Y0NF+eJDVY+CcwbzGXsgTRxohY1peCrn+ q+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824976; x=1696429776; 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=ZxZqIgX5y8rlVuuvKWwMza+CDOQqgY++eVFoXXCyn5FcSeSNf1rT5KhG9Mi5xVQ0Nf Czb8rsClozcyjTxvk48yX73f2oJ0MJb+8+Wb5A4N7ICqJJ8c9tJWbqAgF4QtnVLsUU8D m0D9RokmYLFL6Lb/iDXY1nJ+FbIMNijKuFY8YRyrfEWf4WQuf43e5eLYFqOdkG2uieK4 ULffk0ru1PtvoZ6qLkAsVLzBZ5qTv5xjsUlOaP1fX1c15pNDRBtw01PUhdvtzS6nw4iM Vup39yoGHFz+CBZ9/o0850p6LL3QjqSM5JPnxaXAwnk/hGGkkfYhsM/2vmFzveX4Fqqb VRcA== X-Gm-Message-State: AOJu0YwAB3bw3OceglHRAJdIdrWi91F3+WSBFhDmRRqHXOpdnnJy4zoO ekDFl8g50As68gLbsC84Or4ICA== X-Google-Smtp-Source: AGHT+IGx1rA0IPvHwPKy+CU4d/O60W9kXir7QNg57WQfvTZGdtZM/kmFP+1VwE6jdeJBKXjUcuY8yw== X-Received: by 2002:a7b:c415:0:b0:405:377f:5417 with SMTP id k21-20020a7bc415000000b00405377f5417mr2073680wmi.39.1695824976201; Wed, 27 Sep 2023 07:29:36 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29:35 -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 v4 01/11] gpiolib: make gpio_device_get() and gpio_device_put() public Date: Wed, 27 Sep 2023 16:29:21 +0200 Message-Id: <20230927142931.19798-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 Reviewed-by: Andy Shevchenko --- 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 Wed Sep 27 14:29: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: 727153 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ADF038FAD for ; Wed, 27 Sep 2023 14:29:40 +0000 (UTC) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F0F2196 for ; Wed, 27 Sep 2023 07:29:38 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-405417465aaso103913705e9.1 for ; Wed, 27 Sep 2023 07:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824977; x=1696429777; 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=zrpKHVqqTjrma0ET7OV7WLFI0tFo3wgKkZ5ACtzRvkE=; b=nmzlb36S3PRwkaDm7sCBLiyf9gzPtuYW5+71NYnSTODLPEkvxqD6eFEDjzLV/BhDEC ZZ3HJgr/KtREJEjzG/QfVqlti7zgG5zq2NwUZX2tH2VT3DpYf4IbeepDRN8b+vHzCKLB x2XB/rWcW48Sg7zVcYZuZdcbPLOulbTGmjvLRr5Nnzg1MI+0lxf8mQHd1m6Pbb7eBrad javetCA1nJuUJuTfqd+OLM9wXAiKFJwMBUT45iq9uHWeaXR17ko5Y44xEmdIQ0ktRnlD a4jeje0kXF50jGUabgvIbPB06qJ7HQ1SjN6erZPzou/YeS1CqjfzTO2jEXGtIdQzgOWF MCWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824977; x=1696429777; 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=zrpKHVqqTjrma0ET7OV7WLFI0tFo3wgKkZ5ACtzRvkE=; b=GpK89EmZECkUT0F0sAFO5rF8CvwcX6U2oCk9Iz7Ii7mLisdYOiPUTJXmMJjJfHNaS9 F2hoYVav/UGCr/C7jRR0ehHLgOMi4gR8oU2Z8X2PdzkduNSOwpC2MO50XGMH11LZYBeC vZvbD/JJ0I4PK8pnvW21DuU+sDgwTH4o17dCEvprho7Q+skXJC1sr5d6U/PdzbEAjVSl 0s/gPyIEvIY2Rio9cIxq99YfwFWGVUdwxk9vLCrU6+vTLNpWU4pqhNZIMdI1hkPgBQl0 CfNkJGCfKC7b5I1kXI/Vrpv9gq1EtnB2tqLf4nZQREDmSZ86UE1GAL+VQ4ZW/wwINFT+ s/Bg== X-Gm-Message-State: AOJu0YzNfW/OM7RQRHKXt4Wgj4OkI8AB+SP9KJyqvgiqZLOOwq88nKh3 EyTAyGT1Y7vAzjbiUlhj1H7biA== X-Google-Smtp-Source: AGHT+IF6eg+w62/RXPj0sQUskg5id/X4SSijgtC05ghaPIfi6qFHp0AB4DGHIGyu0H2TgbfYmlDZfQ== X-Received: by 2002:a05:600c:21d4:b0:405:34e4:e756 with SMTP id x20-20020a05600c21d400b0040534e4e756mr2081697wmj.36.1695824977012; Wed, 27 Sep 2023 07:29:37 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 02/11] gpiolib: add support for scope-based management to gpio_device Date: Wed, 27 Sep 2023 16:29:22 +0200 Message-Id: <20230927142931.19798-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 Reviewed-by: Andy Shevchenko --- include/linux/gpio/driver.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index a2060dc3344b..1cedbc3d3200 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -3,6 +3,8 @@ #define __LINUX_GPIO_DRIVER_H #include +#include +#include #include #include #include @@ -609,6 +611,9 @@ 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 (IS_ERR_OR_NULL(_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 Wed Sep 27 14:29: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: 726731 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F26F38FA6 for ; Wed, 27 Sep 2023 14:29:41 +0000 (UTC) Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1F23FC for ; Wed, 27 Sep 2023 07:29:39 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4063da036c9so36486165e9.3 for ; Wed, 27 Sep 2023 07:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824978; x=1696429778; 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=AG+MBGFlKyeqAoI+zBkkhuwZdyh02KZ6W2Oat6+x/rc=; b=jkomhgG+Tbn+oHqiYbAzwP2qCyxutFq51q9Fcs/01QlhQvId6oAl7FycrwCnFlrjsP sFnHWdJplfjXkdFGs10AxABLEmXzvBcojyjCRce58rUUFnjvblmIRqem2hLSpQpZ/CSU RWKgx0Dibhagns2lZgXIXSyMlWd8KAjfr5sFc1P4RIN42SgwxOymINpdCKa3UmUj6L0w AMgRHOTp5Sg9Mp1KM6Q9d4JZycK14633XP0FZxYiZ1DGh4tpMnwhvMkgqbBztPtzhVnw DYK29q0dQlq6ncDrikvt8yTgJlZg/WOS2j24Iu2KDuUmXxmSiLZPCUbYjM1XuEUcTIo7 ZJTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824978; x=1696429778; 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=AG+MBGFlKyeqAoI+zBkkhuwZdyh02KZ6W2Oat6+x/rc=; b=imaP5D+tqkCSLgOAApNjPatdYx7LatRsLHRiehkI1xDO1ZHwDjdumnMbodvOlTxWFG ve3r9Kw6fGQRFMzXFnlPNoKEOIijnTpClTz79s8XkC7C9GD5/0YwMv/dMGzH2u7RRzTB DhoGEuE70PiwuaXLgBr4fbNHby6CJQIqoOztnaZGvs9UfZV17BUOQS5PWA7Z3ndkootJ RDqgq29FFNp8sXNEeqBrGkL1zjaMcCPwjOmTdhA+FbdBr/J/S+NpLsrIay5r2nda7c8W jy7jGLmgzDXalFXPfYRvyeFuSTDjavq9uR5AcnTj3HT6dR31YxxiVk800FhepuJEWK9T 6WlQ== X-Gm-Message-State: AOJu0Yx5BrU5FIUv3AJ2zYKFDyNwLWIqp/uVChou6eutYmMoyUz2qvd6 oVybsLSbDimXXNod1Ayu5jH0TQ== X-Google-Smtp-Source: AGHT+IF+734qHN0cowwb2rWZZ7nRSKb6cLjcj/UrCSuIQ9sXERwtpbK0/Z+jtA9CBM2mVhY8P27S2A== X-Received: by 2002:a7b:c456:0:b0:405:3ca1:f6c6 with SMTP id l22-20020a7bc456000000b004053ca1f6c6mr2188112wmi.0.1695824978053; Wed, 27 Sep 2023 07:29:38 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 03/11] gpiolib: provide gpio_device_find() Date: Wed, 27 Sep 2023 16:29:23 +0200 Message-Id: <20230927142931.19798-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 1cedbc3d3200..6ad1f1a8ef2e 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -608,6 +608,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 Wed Sep 27 14:29: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: 727152 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A423A38FB7 for ; Wed, 27 Sep 2023 14:29:42 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4658193 for ; Wed, 27 Sep 2023 07:29:40 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4054f790190so101037265e9.2 for ; Wed, 27 Sep 2023 07:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824979; x=1696429779; 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=fTcEgfPoq9MntpjrBDVs2nRvtCmOFJGrOAf8mTlZ6ic=; b=yMGNr1kd3hLtrwjjnHhdG5D7rrhYIkgDkk4BxMJ6QcP26LpenmcAAuDPnHf2x5ArVt EgoK3A847GtHVbvzEw6m7lGUfHRpOEIlkETZaMT+0uBkyCCc4cyRTx91CSDrdjS6dx7b VlMWCtmFop9dmPdfsGynvahT/rsGD39zjTGZG7j1M8Fvb/t7eVpGu2Ni5rRpS5ixnY+X WhqaNKJgs/c145/0CyW2xlyasxa8FgO3ISVEs8QG8/OwNGCUU4xeLtMiM4Pzo2mG5FKp TXYoUbHI/YlQ9AGP8ed46DMSFpQzaXCONn4HUeRWYpoMXkQJ9LXrJNn97R0Q0r+K3i++ tpjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824979; x=1696429779; 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=fTcEgfPoq9MntpjrBDVs2nRvtCmOFJGrOAf8mTlZ6ic=; b=tUOggT46o1DvgZQvLF/49w7bw1nro68q8t4owU8ratKe1uMtY8JCIMgxoOyA0FZwVY DoGqShCsxpzGKNQbkxV36yK8KTjs4P9829SFW6uKM/2WLEDPki3owGi5b617BHhfi5Rb uBjWfV2K9d/sVWgqJM05ApWNX9PH5Lz2nGla4yeP4aqdIOwlr4dhFVLdPdLQ7t9kn3Ap Jgem4Jt2QxrFG4Y0QjrRi/ZoC9ue9IeyUI2oF9MFXulKlfniDdz25gzP7Xv+j1kBDggz Vwtrd287vgmosNsMbBR0zyLjzAXO3b2wfcJbfT2R+FWbiVm5eNOr9uh5QaISdRxK+2F7 v8jw== X-Gm-Message-State: AOJu0Yw9UoCUjwkMDZcFeg3GUGrjsHbXQWDwZKom/0i+r8fK2rt9nPZA /xW63xC9e4J9szbU+Aqk+68dQDmAj5P6qt42xrA= X-Google-Smtp-Source: AGHT+IGD00aBYBGbXwpAnwYAy0l31qfM0fAkxtSPt2jFAgPU61yc4YyTZH8mLIyu6+7WPpclnEKlJg== X-Received: by 2002:a5d:5582:0:b0:31a:ddf0:93b with SMTP id i2-20020a5d5582000000b0031addf0093bmr1944891wrv.33.1695824978901; Wed, 27 Sep 2023 07:29:38 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 04/11] gpiolib: provide gpio_device_find_by_label() Date: Wed, 27 Sep 2023 16:29:24 +0200 Message-Id: <20230927142931.19798-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 6ad1f1a8ef2e..24996cba6465 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -610,6 +610,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 Wed Sep 27 14:29: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: 726730 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 662CEC8D2 for ; Wed, 27 Sep 2023 14:29:43 +0000 (UTC) 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 94EC7191 for ; Wed, 27 Sep 2023 07:29:41 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4063e3ce085so31354485e9.2 for ; Wed, 27 Sep 2023 07:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824980; x=1696429780; 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=1mbb2H4Qaojfy2/yoEXeeCLJJ5JJqMUu7q1KHHOeyZs=; b=beNfaO7vtzNB2Pyfcuez8POH8XxZ3SkjhjM/O+iNprbBoE2mXyteg9PHFMAdlkgsta fCZ7PaKf/FiQWONO8Zl52nBgtTyzJDoniLPUI9XvXpgaiILAVm3y+vCdAezAy1ZEZH2U M/ZfCaCpY7+KX8I9TUk1j9f8sanGU7HdYKMP9EaFAY7wFQxDq/nVsdtdtcVdvHswP1TX Rrkx0hUwzeVdVeSULUsYety3Jc3HqodnNO6TVYIUDoBUy0W3l3l0TgqWTraA4odR5ksl 20tDbQjpW3zQdFkPSXjeobPHjaS94j1OwcO9d0SpBwnOhLYGWiOnMgPxNCSa4QmPi1uW HWaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824980; x=1696429780; 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=1mbb2H4Qaojfy2/yoEXeeCLJJ5JJqMUu7q1KHHOeyZs=; b=v3jlFddhU/f8lAspqbN6pWQIK502yqWAmH+ATSZpReNIZtJ9d9NetPT57MJQ0iQXaF Ap0vED/VSwq/bTwsuHxl9qocMzv65EcVB1lt9gqQds05qLsBYBhidIXjXBLxG2/WvPlZ AQOmzxHRdeXtGVWy7K9LcAgrpmyQAOKJ6glwxjoOxWv/5JR46f3aUHkgjqbbOoSMGVIO QWZA5nVapX/Lm8WY0OscKP2hHubGGuCDK8VQzpnLdweni3bbj22t7T0J9J760E02UISl IeQsi9GQUXEtfZlERSVEhhx4T7MN7gngbWmaZPy6kyqyJfYDB+y5L5vCV26cAo+Hr96G A2cA== X-Gm-Message-State: AOJu0YxZPa3r93MzozkEnrpYbr6estLc9fm6mVWDmdX2d4Q7pQVqI1Ka KOIkAmgbK7J0+AgZRZIzzwJaOg== X-Google-Smtp-Source: AGHT+IGlXlUWi/1TAewgbEj8gMjflzt/5RGXON1jJP+PU12Tw6sA+naJlRxL23+NXrc0mzwg/eFcBg== X-Received: by 2002:a05:600c:151:b0:401:8225:14ee with SMTP id w17-20020a05600c015100b00401822514eemr2024171wmm.41.1695824980062; Wed, 27 Sep 2023 07:29:40 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 05/11] gpiolib: provide gpio_device_get_desc() Date: Wed, 27 Sep 2023 16:29:25 +0200 Message-Id: <20230927142931.19798-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 | 46 +++++++++++++++++++++++++++---------- include/linux/gpio/driver.h | 2 ++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9f20311e4c1a..7d2574b3dbe5 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -147,27 +147,49 @@ 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; + + /* + * FIXME: This will be locked once we protect gdev->chip everywhere + * with SRCU. + */ + gc = gdev->chip; + 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 24996cba6465..3fdf3f14bb13 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -770,6 +770,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 Wed Sep 27 14:29: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: 727151 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB7D738FA6 for ; Wed, 27 Sep 2023 14:29:43 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6943412A for ; Wed, 27 Sep 2023 07:29:42 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40537481094so114173755e9.0 for ; Wed, 27 Sep 2023 07:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824981; x=1696429781; 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=f7cnFQaXE5hgNGVsFuhD31Dbn34C6HVkTSPK79EhhMo=; b=tC786oomOp9enwi6Np8ApnZ28cXmNnrL49M8rxAn6ZaocPCrDJwgmiCuvSNBldGGdR /ptSvgYl85A90cuDupuz6zw91SEhvwPLtFfZNO0VwGUtSsseXB1sf+RoaMJ8OF6QxC5h apa8qVJVyfq7ZeQhVMZfRU+n6nKo45EC48r+4y0VfEPpH0ooiOiEfHeJe9Gs5UHSwHBD TSlsXtoXaiuqHwTHWnzc0Lk5lO9Er+Tm5X6eejMXZiTMhRK0oY6fsmUBv4MoTMZbf1vp 2fUXBdNtbwEqxrDiuBjRbqzIsOeCu2OPXxdOcN66lf+wZ98CwE2m7jhcEJDWkZ1mYQlI ecfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824981; x=1696429781; 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=f7cnFQaXE5hgNGVsFuhD31Dbn34C6HVkTSPK79EhhMo=; b=Jp7yM3ftFVqCxhyX8GT2FzJJxz09r8GmOHTIDBVjFDcFXJMhSxGqBrKK6DQmD0bKQ+ jO56mRF5gA2VxNcBc6AQw7AIpkrNFKaY2TQ1LpA9Vtvohe7MZq2G4rkVexizictQsh0R udWWLAvI23aQ1UHYjluQ67u6VjJCcrwnaQ2rEgbcIVyTJTKHKSWYCVHLaAkqNWLzQfuS Xx7vkgvmTP+kT4JTz8BTZ0oLbu0LRSAI+qisZ6K9tQhTXiXNpQHqNGGWkNgGRHPaMSqt VRy4XlNYHQ6FOyet1tFT73qPokiEy+i3NVk7Cvh883NW6/Kbl0g52I6H579DvEW4rduI xjXA== X-Gm-Message-State: AOJu0Yzc+v0yKPNqDMF5hXGhiEqf6RrBNW5Oa9/8ajLFgUZ+Ts7dtUKP igSV4NbbOTvnGnKkaqhC4ViKnQ== X-Google-Smtp-Source: AGHT+IHv5NSu6YCJ/7S57e2fsDhaAnO5tbf5QNh9VBd/TY/2Ebo1ZLGBtJSYkkd4Gw0pg4BMxRB0Fg== X-Received: by 2002:a7b:c8c7:0:b0:405:75f0:fd31 with SMTP id f7-20020a7bc8c7000000b0040575f0fd31mr2054487wml.31.1695824980880; Wed, 27 Sep 2023 07:29:40 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 06/11] gpiolib: reluctantly provide gpio_device_get_chip() Date: Wed, 27 Sep 2023 16:29:26 +0200 Message-Id: <20230927142931.19798-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 7d2574b3dbe5..e26cbd10a246 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -220,6 +220,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 3fdf3f14bb13..f8ad7f40100c 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -773,6 +773,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 Wed Sep 27 14:29: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: 726729 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F68438FBE for ; Wed, 27 Sep 2023 14:29:44 +0000 (UTC) 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 33138196 for ; Wed, 27 Sep 2023 07:29:43 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-405497850dbso92771195e9.0 for ; Wed, 27 Sep 2023 07:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824981; x=1696429781; 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=iq/2l1G2X3VlbEMC4JGFIfoN51ntSJ8lHp3eH0L/8mM=; b=Zh0x/nQ8jDWZNzIy56w3kaBAtLR+osipmo88W5sFXVC33xhvCRFVY+qQLQLZzC/ol3 28ZKDh8pc2n5a69EGixt07TL7L/R7LKHyX8MUk0l10Gt52hj9bb5rANxsC+jaUmi0DNI Nrt3yiUpII1G5b6KF0utSyif3vrpl0Y5fCgGImqPP/jHpvpLVna+ouOhPYcRkg1D4irN Mp2SO/AZUZto5GqMrb3KRJsQcFGWFd3AAIu7d7hUbGY7AHiLgBrc1xvIk9GUKN3cZGNQ f6GUivMKgotTrt2d0GhuGVkHbEiSdQqxJc7QEX1u0T3NE1HXCmDast4xGbfB4wVHvk6E 3rtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824981; x=1696429781; 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=iq/2l1G2X3VlbEMC4JGFIfoN51ntSJ8lHp3eH0L/8mM=; b=rBHBQ1aoX7x0WJxc//GCkRZ0ISTqjcqJ07pYyTqq4GU/tJ+wJt8dxYKJy8Z8MfiYH8 XX1QipnFYq5FaXWA/I+QdQYwT1BYiGUaYfwdkLC8vqxcBTqMN4olkdNYbHRcBBpiupES iG/JMBX+MBDXyR64mM7faznxxgnZm64piKUVIcP8vuy178yr/Z/XmT4PwIDgYdXWjyHl WphwQHJyUV+X7JUCgs6S05szJdwcEXCUZMRlOpoc9EoqA03409wmPVs5lbppZCmRjjQo aLuHeuqmO1Fv824vZJpAfH5K+/jzENImQ+kVmK52WeslcQRQ0yteSzgjenGMOTeL4ZRf /vkQ== X-Gm-Message-State: AOJu0YyO5iuehUgyVu5KLhTDnuTF4M4c6mFlXLrGeSfjk9+hLzgjvhba AMVJIiGLMFaiy7gBZxrfYpThNA== X-Google-Smtp-Source: AGHT+IFU9IDzdf2ZIm4nyCEV/MO/SgU3zg+UywTSBTwfjeOrDNNF5wj3OyDSLmSd/5oKq9WWO+fWrg== X-Received: by 2002:a05:600c:230b:b0:405:3955:5872 with SMTP id 11-20020a05600c230b00b0040539555872mr1986626wmo.18.1695824981656; Wed, 27 Sep 2023 07:29:41 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 07/11] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label() Date: Wed, 27 Sep 2023 16:29:27 +0200 Message-Id: <20230927142931.19798-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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, 11 insertions(+), 22 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e26cbd10a246..dcdac508dcd4 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1145,18 +1145,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 @@ -3908,7 +3896,6 @@ 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); @@ -3920,9 +3907,10 @@ void gpiod_add_hogs(struct gpiod_hog *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); + struct gpio_device *gdev __free(gpio_device_put) = + 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); @@ -3977,14 +3965,13 @@ 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; - /* idx must always match exactly */ if (p->idx != idx) continue; @@ -4005,9 +3992,9 @@ 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) { + struct gpio_device *gdev __free(gpio_device_put) = + gpio_device_find_by_label(p->key); + if (!gdev) { /* * As the lookup table indicates a chip with * p->key should exist, assume it may @@ -4020,6 +4007,8 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, return ERR_PTR(-EPROBE_DEFER); } + gc = gpio_device_get_chip(gdev); + if (gc->ngpio <= p->chip_hwnum) { dev_err(dev, "requested GPIO %u (%u) is out of range [0..%u] for chip %s\n", @@ -4028,7 +4017,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, return ERR_PTR(-EINVAL); } - desc = gpiochip_get_desc(gc, p->chip_hwnum); + desc = gpio_device_get_desc(gdev, p->chip_hwnum); *flags = p->flags; return desc; From patchwork Wed Sep 27 14:29:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 727150 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56F7038FB9 for ; Wed, 27 Sep 2023 14:29:45 +0000 (UTC) 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 0D5FB1A6 for ; Wed, 27 Sep 2023 07:29:44 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40528376459so114553945e9.3 for ; Wed, 27 Sep 2023 07:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824982; x=1696429782; 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=oE8FiVQ373WPhEqnnd0k+Q8JE+kP4cy31sdBOoqrMw8=; b=sbouSzjOVd8ltn4tAEi/FEWXTjCdMfo/mYaQjAD8QmocqofoCee9CszmOgufxFCVtr SFfMPymQLA0G8W/k7/mcZRtET+jNBkM8rX7EiZjyRaT125jzTpRbNQ67eI63mq1jXRah WuSkaaXuF9l0wTzAe1kINn/2XtV+wLSc1CWB1vRGhKxsiE8+5GDTJZJ1YQDt3dNcCyTj O9P5PLTNbfbAzdHcoS3JxAvyzq4YVaCeaLyAAdWtE1Jz0/Jfk2UN+BbJz0vniAx5Xc5M D2wxKsmbow5aOtGic4+UHZkV3PyRevTELg5eQTNEsOU0LP7PPOcwS5T4JBwn6ZIp80kQ INEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824982; x=1696429782; 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=oE8FiVQ373WPhEqnnd0k+Q8JE+kP4cy31sdBOoqrMw8=; b=W+ig2TecrIkTSazGcAE4fJoq+z1KPNSdfx4hYIBrebCJT7L7Lr3WxjrSfHmsQGNrbf a73Yr7h7/bHuZOPZOAs70yt/w7pBD1Z3Njclv/lvLYTECQ/jNmMyNULCdpDXCYKzrK4Z g9d8uGJwS2aeP1K8aQU0FliVUntUrtFmewx5v4i6zUFTWY4pd7kmapRP+P68i5yvdl59 pgcqHXM7BNjbEw2/hoXRifyo5/Rf7oWjge5XbYnWBP+v84J0L7bXwXazPilXBlWB6TRy i1AguapE/meRecOTk40oa5M+39w7wp9V4HHokX9B5p8/pnS1/BI155OZ2TUPgGX67h4f jNCA== X-Gm-Message-State: AOJu0YxRug2Dvk8iQIQNcTAwK4BoVqs2XuXIP2QSGL73jAc0wLfFs++P bP7uOvy0B6gD1SosLJr3vGqN6Q== X-Google-Smtp-Source: AGHT+IENPJmvmWp0g+dGS8v34l0Gtx+t4X9kF9+AMSE7rr76Glskj8nT9+aAmH3ht7mwRdRjm2lEug== X-Received: by 2002:a1c:4c13:0:b0:401:be77:9a50 with SMTP id z19-20020a1c4c13000000b00401be779a50mr2103103wmf.8.1695824982520; Wed, 27 Sep 2023 07:29:42 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 08/11] gpio: of: replace gpiochip_find_* with gpio_device_find_* Date: Wed, 27 Sep 2023 16:29:28 +0200 Message-Id: <20230927142931.19798-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 58c0bbe9d569..5ea97c14d77a 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, @@ -372,7 +372,6 @@ 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 of_phandle_args gpiospec; - struct gpio_chip *chip; struct gpio_desc *desc; int ret; @@ -384,13 +383,15 @@ 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) { + struct gpio_device *gdev __free(gpio_device_put) = + 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(gpio_device_get_chip(gdev), + &gpiospec, flags); if (IS_ERR(desc)) goto out; @@ -822,16 +823,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; /* @@ -848,11 +849,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); @@ -865,11 +866,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 Wed Sep 27 14:29:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 726728 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3F4E38FB4 for ; Wed, 27 Sep 2023 14:29:46 +0000 (UTC) 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 2B1DC1A8 for ; Wed, 27 Sep 2023 07:29:45 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40594697600so61976125e9.1 for ; Wed, 27 Sep 2023 07:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824983; x=1696429783; 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=NLhg+4lYTY7FPYRXcNep77vyeRRzOTuTNwtgzvDeQR4=; b=HO1mAQU6tmaCPTS9JAZrlTTnCInqtgPEMjxrsAIbYIe3YO4W5jK/aCM/aW1bczfu7x 9m6S8G9Hyw2njR5JiKPkM7LrtGvV7oERGBSk8Fmfby6PDlV7AiErJCDg8ejwri6yZ0Kj R8KTIGiuVevz9Jk66B3amISn3JjvA5bZvGITWr92Map+b6cj4C4Nz+tslvN9FMtMA+T3 8Mf4wWPX7LbwEqsjkY9orVPhPLn3IWvMFCqxWQYMZd8xEfCB3CIMMx387x6OR4wFs/Hm if/P3XPbOBWH1VRfrXNohBGBlHHLzyn6Q9bUs6pWBgSDnR/P/ZeZ2/Y38ZSMen3fI5yh qXFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824983; x=1696429783; 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=NLhg+4lYTY7FPYRXcNep77vyeRRzOTuTNwtgzvDeQR4=; b=YmrgCBiA98X40bcsqvOegIj0ygLi25EX+UmfdubZRxfxATdvteaYt2waLmsP17AYD7 AnRVMJF4BKXv3ghBDAVpyfI2Sd18qM4seZ4UxaeyE0Vj5CFsQeZlKH0rc2UjhMa4KuFB TUpjUj/1+JofB0DBzpWl4uSe1FKs+rayxXHSbCxTa+d1+DmRpT8ucb8yvlKnuHwtO/ZZ m/nMCaqYmoNW7PD6ZUUw0umV4SGMG4B699I9DYfMm8QRTTmXj8DnBeA+zX0w6hRkTqd8 FzeLL3/FkvudVyhoUVVYa03bONzz/goENcCT7F51RhtsfnIKFBkN3WmihaKJCkC/NQcJ uLzw== X-Gm-Message-State: AOJu0YxcyDFKT+fiv3a4JoTsWQdAf9Wlpqwqtk06slGhLIB//vAukUnp h49ZhHwnIYowLnrg1WNlBltOoQ== X-Google-Smtp-Source: AGHT+IHgX6kn5gQqg+82iM+KQ1iq+581c3IjMNjxD4MgKLxeaVlxoJ47mm9EuWENM8e9XcnMPTtOig== X-Received: by 2002:a7b:c4cb:0:b0:403:8fb9:8d69 with SMTP id g11-20020a7bc4cb000000b004038fb98d69mr2229061wmk.25.1695824983655; Wed, 27 Sep 2023 07:29:43 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 09/11] gpio: acpi: replace gpiochip_find() with gpio_device_find() Date: Wed, 27 Sep 2023 16:29:29 +0200 Message-Id: <20230927142931.19798-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 Reviewed-by: Mika Westerberg --- 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..2ad21f34ee62 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -143,7 +143,6 @@ 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; acpi_handle handle; acpi_status status; @@ -151,11 +150,16 @@ 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) + struct gpio_device *gdev __free(gpio_device_put) = + gpio_device_find(handle, acpi_gpiochip_find); + if (!gdev) return ERR_PTR(-EPROBE_DEFER); - return gpiochip_get_desc(chip, pin); + /* + * FIXME: keep track of the reference to the GPIO device somehow + * instead of putting it here. + */ + return gpio_device_get_desc(gdev, pin); } /** From patchwork Wed Sep 27 14:29:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 727149 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92C8F38FB9 for ; Wed, 27 Sep 2023 14:29:47 +0000 (UTC) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0040E1AB for ; Wed, 27 Sep 2023 07:29:45 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4064876e8b8so8612675e9.0 for ; Wed, 27 Sep 2023 07:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824984; x=1696429784; 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=gEkEuyWHPwtkJqqx/zp65rsN/kW+vWLAZiPV4yAfo60=; b=T53P/S8/9T02hxwplxxwI5HIC6fr8wFlqdkgtP2ngolZGGyetwJ2OesfrNIJvamTYS 1KidFj6uhuN1LYs8XhqPz5ftp/0k6f366XXwijR2Qf4JWqPqN5wyCrv74tQ62c0diTdQ NsVzgg2zhYJ3wN8S/odCzkspPbl76jzMgml5pMqbUFwkxZ/AB1VlA9/oCQxwwzNCfOlV klGOy0zium87DDvTYfDBzoeas+R4ddkY2mOYSlIUJSptOk8nanwVOEZMDIDTeI7xi1o8 hvr8x787z1GFZz/bpcaWZsK39DcIgUnU9kbEE9XJy1RfF3wiy5cVAlNl4Pw+zBE/H4Rb kWsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824984; x=1696429784; 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=gEkEuyWHPwtkJqqx/zp65rsN/kW+vWLAZiPV4yAfo60=; b=KW4RuhFhEV/Mcdqar35yvdbaUviPaDzJ4vrJ1MOa+DZMdqNVjIhgShrLMMg3hA3YEK 51JadH3cGZb86u6a8A89Ced8rCrzHqBJ5w/BmTAalxC8BEf/zfngGn8BeGQnqsHPwNpm u/azYm8qHMSHYn0NLSVb9/Q0MMSBKx0Nr7dl2YIjELIPSm1fIxn+tO2eLH3/oVSjGnHI K9VZTy09+W+Ip8MX0iCfCAkitvvqNRF9JOEF0PhoxvtrmxK/+vi0gEVzb834a29JFNt3 HUGHRikO09yIV8ryutY1ghfQkvhBoIXsZcb06urIQq64ed0OAvKXMlHEy3eGf5LQeUBS WIvQ== X-Gm-Message-State: AOJu0Yym2OcfaRN5L/JLXJOQH2S2B+oDovdqz8pNMaZQWBsWSdX4LAi2 6WPClh4WflzUWJxlH4KF/5Mdtg== X-Google-Smtp-Source: AGHT+IFNb8l5Y6LCipefds19t5fIoqseWun2vJIxoTJoGFcSPsfaLd8QhwvSbDrL6X4lB0QT/ACnZg== X-Received: by 2002:a5d:67cd:0:b0:323:306e:65cf with SMTP id n13-20020a5d67cd000000b00323306e65cfmr2124281wrw.10.1695824984517; Wed, 27 Sep 2023 07:29:44 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 10/11] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label() Date: Wed, 27 Sep 2023 16:29:30 +0200 Message-Id: <20230927142931.19798-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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..fa52bdb1a29a 100644 --- a/drivers/gpio/gpiolib-swnode.c +++ b/drivers/gpio/gpiolib-swnode.c @@ -31,22 +31,17 @@ 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(gdev_node->name); + return gdev ?: ERR_PTR(-EPROBE_DEFER); } struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, @@ -55,7 +50,6 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, { 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 +71,17 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, return ERR_PTR(error); } - chip = swnode_get_chip(args.fwnode); + struct gpio_device *gdev __free(gpio_device_put) = + 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 Wed Sep 27 14:29:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 726727 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4CF5C8D2 for ; Wed, 27 Sep 2023 14:29:48 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B939F1B5 for ; Wed, 27 Sep 2023 07:29:46 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-405621baba7so83776955e9.0 for ; Wed, 27 Sep 2023 07:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824985; x=1696429785; 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=LRr+WyT+pJrvtzeFl3/fK+ENRQ+D1e0hsD+RYczEWKCCDSfkFSRWt4FSYjeXCZD9Kp GyWvm2X6/1LKNL6TZAYKYS6ht5cszmolglAiC/8c4D6CgAjxPZUVvb4Ro7F7jIN+mJr9 9QUrTlbND7s6NJlmOzLc404VWq8LDsLHYi2qsK1qIuybIH8JoBqrVW+voJmD1lTJVYQw pYeAx+hjxY8RSBKSOlL3x3lB8jAFSTB8w9OO3qTLr40WSgcZXQ8aNLNlpHYX33BtsNo2 W12MVKhQ/RaB15Oij4eRJm/nbjabyZ3ifwQTuom524ifc/F+xiRgd124dftTVaLC2Uz1 0nDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824985; x=1696429785; 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=pa7VTSR4KZsatK6z/wrSYQQ21HnBGFgOvHqfT+St7qS9YKfNppXrXrLO57dwo8wIll BvDeGFDehSdopQ/U9gLdGQ0N5nMmHgJN8EZesF5y74g1HaI4KJoP512gFeNHiZVbO0eP D6URED/Sza+BJJsLbE+vThIwBHcd/bbtuefzUMARX+1Rja5mxLAsC8c2YeJ5C6HX6ova QrFs/fJZtSX7QNgCz/4bz41U5Q16NqL8Lkqel6+lDvqw17Z1CQfjMA/xKbyiftaIj8FB rY5+uWfgsbzR0hevPhp66GNeg1qxQvu48U0n/ZK5Vh2vspNDQsLw8LvV9RuT2ABSvtY1 YZ/g== X-Gm-Message-State: AOJu0YxZ6c6AZ6gtsCitdj6tZ4m8GBlu0imHYq0whI5oytIBgwNHb4/j pONtsujBKK8/JkKidF6ZYRsQ3Q== X-Google-Smtp-Source: AGHT+IEXsLCf66wrsjqsyNP3LGPoGey7JEWXQQyftq4Pcl8llIG+MXA78yj2kb3tXjDQEhKuOHbqGg== X-Received: by 2002:a7b:c3d1:0:b0:405:3d27:70e8 with SMTP id t17-20020a7bc3d1000000b004053d2770e8mr2265430wmj.36.1695824985281; Wed, 27 Sep 2023 07:29:45 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29: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 v4 11/11] gpio: sysfs: drop the mention of gpiochip_find() from sysfs code Date: Wed, 27 Sep 2023 16:29:31 +0200 Message-Id: <20230927142931.19798-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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. */