From nobody Mon Dec 15 22:08:06 2025 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 0066DCA0ED3 for ; Tue, 12 Sep 2023 10:08:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233904AbjILKID (ORCPT ); Tue, 12 Sep 2023 06:08:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234020AbjILKHm (ORCPT ); Tue, 12 Sep 2023 06:07:42 -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 50D231722 for ; Tue, 12 Sep 2023 03:07:38 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-401da71b83cso61693355e9.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=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=DSoRE7aqxwimPeNnFHvWY3PPedMQdGb5FB4R/kOdTWw9WGccGJTlZ6BYV6vnarkjWc dbrqnO6IP+WY3rKv7sp+qYhP7a/gj6OQQ44KJP1bakKRLn90ZnT6hPo7uMMkF/Qg+CNY X/2RVCbJl80YHiKTD+XRX9lYTal8hCHuEN01ChyHj/rwDbmnLUenhMqw+rddKKqRu3il NeiphoROsRsvKuD1FBzOawxswbOZFZVbERcRAtGwZsR9tbaalOHOOBcTBoQofvMPFTw8 GG/Nf5wDn2AGOkRAMdXvUT6gMneaZ+6/ks8lAvot95LdnrId96GjRQKMdVh/X0KYknrj wddA== X-Gm-Message-State: AOJu0Yy5T7ip9bFw8aiofGd7WhIAxyCxd5bswJ9pbHwwkffHyuieLM1W zX6V+WQG4oi9llcXTmAQwwwMNA== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 cha= r *name) return gpiochip_find((void *)name, gpiochip_match_name); } =20 +/** + * 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 =20 /* 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); } =20 -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[] =3D { "gpios", "g= pio" }; =20 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)); =20 +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); --=20 2.39.2