From mboxrd@z Thu Jan 1 00:00:00 1970 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 45876CA0FFF for ; Tue, 5 Sep 2023 19:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234939AbjIETMa (ORCPT ); Tue, 5 Sep 2023 15:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242011AbjIETMG (ORCPT ); Tue, 5 Sep 2023 15:12:06 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FD3419A for ; Tue, 5 Sep 2023 12:11:40 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2bd0d135ca3so48697711fa.3 for ; Tue, 05 Sep 2023 12:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1693941048; x=1694545848; 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=vqkLr0JyIMxB5faQNNXnf+zRj68nvo49fQs7ZKVuUBo=; b=m7w7hcYmLKgFVUPI6NMgy0bsueFmPjTLMQHQuA70Y9+Ogn0maiXrOZGEEO9LOVgS2J /4EDKsltcCedLdROlg/Gp5sDLN5yeXIe9JgIYRKt43V1TJ5jUsH9Sr9N2ORh+vtqILXQ uuBiD3K+XNCVOLiYETwX9AOAAcD8c3sCNErqZUan5mWlwD/dgiai58Z5rZ8twoEfNHtp D5z+3g3IRR3bIA00LPaczHKaUuMdNEdCU1i162xjXO3EMu4+OkMJQny15Xag06d8mEyk TmvIiAgEivCVUcURsaaYOMSGzRFaE+mBoeBd5FVGNr/RpJgdpxJ1uBytgPh/kOCjhmPo 1OJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693941048; x=1694545848; 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=vqkLr0JyIMxB5faQNNXnf+zRj68nvo49fQs7ZKVuUBo=; b=DnBDXRoBLcakMX4x1VhODX+ooLOlw6qz77kgLI6i0MP3SNqlg4Smb2g0RWX2Dx0K1+ oAhcq+vyHLars/t1yzjltkOGsDCCLFn586Yd0ObnEsK2EZgkq39U0nLr0LfddixOjeaP tIMGkDgDEiwVEX0IW0L70w8a2pgSx3i+zLzkg/b4nw1hPYtLSBc2IG0x4/H9OFmjOpqZ jahFOqGHXK1apUBMUgcVxTzjM/Oe06tsHaLQIOeDhuWUYawWGmjd/86P8wgLzE4AzPl2 EqQN++ThoFU9R1e+zn8p79iKlK5NoSbIhTGZMvTjFW7cTK4lP1EG/EnllSOjXeuaCDX4 SDOQ== X-Gm-Message-State: AOJu0YwHm6wvaXj2GU9GXLBQ81EX5wpBXDN6/TLr0qL3rgkHR4jpQQUc YX2t24Ol0gsx9i1pfw3wbDlKrgAlA/KQ72kR7gw= X-Google-Smtp-Source: AGHT+IG3KG15PaiG7DgNG5yZVi1RIG05HTUsTSLH76kG9iwAZEGSHThfSg45jv+oBWQBQS0UnnvYaw== X-Received: by 2002:a05:600c:2256:b0:3fe:1af6:6542 with SMTP id a22-20020a05600c225600b003fe1af66542mr449099wmm.33.1693940009775; Tue, 05 Sep 2023 11:53:29 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:7a54:5dbc:6d09:48b7]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c249100b003fbc30825fbsm17550010wms.39.2023.09.05.11.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 11:53:29 -0700 (PDT) From: Bartosz Golaszewski To: Aaro Koskinen , Janusz Krzysztofik , Tony Lindgren , Russell King , Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Dipen Patel , Thierry Reding , Jonathan Hunter , Hans de Goede , Mark Gross Cc: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, timestamp@lists.linux.dev, linux-tegra@vger.kernel.org, platform-driver-x86@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 03/21] gpiolib: provide gpio_device_find_by_label() Date: Tue, 5 Sep 2023 20:52:51 +0200 Message-Id: <20230905185309.131295-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230905185309.131295-1-brgl@bgdev.pl> References: <20230905185309.131295-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 9e083ecb8df0..74b837671d30 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1074,6 +1075,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 5c5029cec226..92f7143bad3e 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -609,6 +609,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); -- 2.39.2