From patchwork Fri Sep 15 15:03:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 140721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1341409vqi; Fri, 15 Sep 2023 14:58:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXnq7NWXEZHkpvSJQE4I5ByaWVYLYONwVxmCRaEYpsQLjdBb4/9a4g6zGsI/vt3aPkXx9z X-Received: by 2002:a17:903:41c2:b0:1b8:6a09:9cf9 with SMTP id u2-20020a17090341c200b001b86a099cf9mr3769349ple.26.1694815132521; Fri, 15 Sep 2023 14:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694815132; cv=none; d=google.com; s=arc-20160816; b=N6p+NFs0X3784GJwqWFEfIOkY9B0bCNrX2/B0BjGW25F06GcEjOVtLArH1/mXp0jGE eM26WcBdKNHW+Pb3Mr5EgkKLt5PlGGxWn7h+9BS41/3kBWdsXFQ5515u8B+m4TJW/Jfd cw3ubCr3nubEiv1ah/Rwtmo+b9jmNuzoQQixXH8XgJd9NAEDEg/eSKse/4QSXryMNNob 88ULy0xYssLxVxaINunn8odaTETitvT3yc/XfKAsRIjwwgY8ODZnNnlsb2ksm0cGTKI0 /AcKcA7vn4sLhConY8gN5K/Y3MFytKq7YADDWnZGkHO0NdBkxh1QYTd8dm9eaqbmRMqP gqiA== 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=EwcFiXqSe9Ibi/9pcxNPtbib6rMgKb4QJbQ4Tu3YDqFa1W9cab98/bXhG4K/Ms1v1s 9Je7sUyPVStbnvkRLrlFOJJwsLc0PVbUwKCfXuFNAkXsOmTffHkOHwI2xoUDO4FQdafb x2Qj6sOGE8kDGUcOTrHxMCLZN5GryLCx64NgZ+8mKb7zs4qHdMudjPT4Z8ohcpIeefJK 8XNbv2ko3+fVYZnhjfHeMW6c/f0COvt8pjySZ55OjP474O1FfJVkOudSk2EvfsmSKgzM BPqkcx8CW8ZSTQvkAzvITSvpVBQ+NP7B8bhdcWkvofQT2PYr62chDeEwd6s9pBnHqg6x RM0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=KgZsQgba; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d16-20020a170903231000b001b9da7af2c0si4201066plh.214.2023.09.15.14.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 14:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=KgZsQgba; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 5A960831E373; Fri, 15 Sep 2023 08:03:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235900AbjIOPDw (ORCPT + 31 others); Fri, 15 Sep 2023 11:03:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235489AbjIOPDj (ORCPT ); Fri, 15 Sep 2023 11:03:39 -0400 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 4976A268A for ; Fri, 15 Sep 2023 08:03:33 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40472c3faadso19934865e9.2 for ; Fri, 15 Sep 2023 08:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694790211; x=1695395011; 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=KgZsQgbaJxxknrew3W1dWx0u4Kyp/JlGh5TB440VWDQPUGXDMBCYVMTU5KHA3ndDf0 IsEn6f+SpJaS+riGd5ASGo1SEL9MYiM9qnInMYQhmHZEsfVoJQ+ro1BnrHnUzuMTkW4+ tagAZsxXh9s+bt0vv5uQZLiFT2eHwytY8QYeF65U9kxU3ac/vS5mx8drDw+9Ar/mTd+I dxpzAnF3YrxHqoJTHZBwfG9/4M4Yij8r4QfoJKkHNONxeNPqLXFe3R1H8hHWv3bHDkOO WdGxoZdghmu1bIVbo1xvD4rK9L/9WnHoacnoDfV+3nOfnJbvKLfJCSI1whOu7bjBzgME LQKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694790211; x=1695395011; 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=jbT+IsZSthctz3G28uAMje2XxyI2eOf/nKJIQUR1YnnQmYRQ6BidBLr1F9esP1Jg1i iG5PMHWnjhkfGmruFSSlboeY9drV6IY5Lq69yzm/QaaRdTD+rKq8lacx3PBnFaX4kvBc ziIGAtIqnmYFXkdQ6ShUtz47qSdBDBjZ1GQPxRRdTAgKHjLSCos0LkpNeB5dnQ6VQcDN II8kPEY2JOEl6Ewjz/XRGwBME2HtphaQvIgjS2YlbluSRguFMddVw5NuFO2DLqS0pDMy a6KHPPYmYas3bjt/W3s++s2MlNoOh99gOp5ptVODZoyRjY4B69mzT75NiJK9HNwEkZ7K nPwA== X-Gm-Message-State: AOJu0YyItdKLwZltDiQFCe2X/hpx5EHHi8XJUKMMe3wkyjbPuUcgycZ8 YhWuorK5L4uBGo0do98mguKiOQ== X-Received: by 2002:a1c:ed10:0:b0:401:daf2:2737 with SMTP id l16-20020a1ced10000000b00401daf22737mr1945005wmh.30.1694790211489; Fri, 15 Sep 2023 08:03:31 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:aa19:4569:aeeb:c0d3]) by smtp.gmail.com with ESMTPSA id hn40-20020a05600ca3a800b003fef19bb55csm4853369wmb.34.2023.09.15.08.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:03:30 -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 v3 01/11] gpiolib: make gpio_device_get() and gpio_device_put() public Date: Fri, 15 Sep 2023 17:03:16 +0200 Message-Id: <20230915150327.81918-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230915150327.81918-1-brgl@bgdev.pl> References: <20230915150327.81918-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 08:03:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777142472383490810 X-GMAIL-MSGID: 1777142472383490810 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);