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: 145471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2762938vqu; Wed, 27 Sep 2023 09:53:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSp8J+zZOhZ4uDsoCzNLnHPqeMGZV0KMxqKM1U6tZ9LjwgLNCe0MO5lJhMHmHckVXmu1Kz X-Received: by 2002:a05:6a20:a103:b0:13f:8153:7e31 with SMTP id q3-20020a056a20a10300b0013f81537e31mr2665749pzk.20.1695833629889; Wed, 27 Sep 2023 09:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695833629; cv=none; d=google.com; s=arc-20160816; b=n/DoHxn9u46Zj8APDA8EX7FjAjmyebEQwzACe6BcsPfFmVXF4yF4/zd3DW4TCF2BVO Qy0epMLdeh49I/Mr2pPM6kAV4aLrrcs8z/Ot0jiXy1sJN6N+pDB2We+thUKQi7V9eoJM 9Aq8zBcHHSryYyL1UbOYmZFaNhWRFgd3TFQtqFqhA+tXfEdFkqPEc8EZ54t6eROp29xN e2MoZOxOCx04M2xpzrxmpPavM+ffNgj4AzWvxa2IgA7DLClJvmNgItF7CT7ppHy0JYQ1 YIlhoxyaBeFovkxlRx4y6jvP9Qh1yWooq5RCBV6uFolEqd8JLeJhw0HkFO1+ganHB+Kt tzOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nxu4Stw3TnchTs3E1ZMW4avWovvpHjhxTZTeZz76j+U=; fh=sKfwLbYyGsqFA9J5964tfV31zxizqPhzkdLiyF/udjc=; b=Iw9o4nArt5wMBu6hesCmUEiwvU/v4ZAXqYpPHUq5HwMd5hYIPInF4bbfTIBoTKRMTZ t1F+oLzJu84BlksRhom5AE/qoZTJqAwcMRBeLeDBnumpSxu/aall91RPxDmobqjV0Wrn 3aG02UH8yl4eLpJivihkCyrV/XSn4LWYuse5iOZSyXI+kfsEinFQlkxGnZupYJQCixPS mJYlbvPfApIshTn12zz/JFhjb3A4i/Gh6jQk6O2Lv2h2YC1vHYAQdhncJx30+KBZtFMb a1bszjWBiguZ0+L/ClWPhIgCqkVqu2swVGCDoYc9yZVLVqeKx45EKGoKpU3hs+O386BO PXtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=2Be4sSYl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id ef7-20020a056a002c8700b00689f1186cfdsi16231213pfb.29.2023.09.27.09.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 09:53:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=2Be4sSYl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 7A8C4805C3D9; Wed, 27 Sep 2023 07:29:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232130AbjI0O3m (ORCPT + 21 others); Wed, 27 Sep 2023 10:29:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232097AbjI0O3j (ORCPT ); Wed, 27 Sep 2023 10:29:39 -0400 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 E3002139 for ; Wed, 27 Sep 2023 07:29:37 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so114648565e9.2 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=SeqNj97hQs/AvrCIbZeXCoMgpjr4371jHL7/KJYEdY9ozkP4qCgXEhly4ByWJMhuGm wWQEAMDe0KmA/Crjkjy+ZHZHN+wv2913815ZoiHnWQGuoSK9El+aqNWtECTpvAIL4xHn ybgfe8yn/M5Wz3x2JXaC3sFUOU2FTxUoZ5kclHfNl2C/PnLLw0jkoVNjFbzyuuKt7CfH 4+1wlp+0BlhVNGsdKeXjowEXvKYeHk7APXnrATIpXmvO61xfUVKSoF/AhXZK+Z2p8ziQ yVg74csX9NUdU3HtGO4CV50SuLTrJSx3oorpNRcOCpLYl6CNBgv5sC8DGL/CI3o7amGQ P8BQ== X-Gm-Message-State: AOJu0YwizKyDJw+lGnQnccqXXcKtk7PNFuanChgAM4e46LSn0FvWS4FR 6LcF41Nr3jtM332soF/LP/0qHQ== 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> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 07:29:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778210444399745571 X-GMAIL-MSGID: 1778210444399745571 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);