From patchwork Fri Nov 25 18:11:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 26116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4211782wrr; Fri, 25 Nov 2022 10:22:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf5j9wEG9FqtbD/WI6OsqfB0+7hcWmgBMiqqPcnPnYf53sBCDWcCii+1fyvlTdBcy996APID X-Received: by 2002:a17:90b:154e:b0:216:bd62:8e69 with SMTP id ig14-20020a17090b154e00b00216bd628e69mr46313543pjb.205.1669400557597; Fri, 25 Nov 2022 10:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669400557; cv=none; d=google.com; s=arc-20160816; b=y4ZoeEBJ7UFVVylQV3D8MXm8rA77tZnGLQWUidJwvYJaYUMKDC0JPH7DDcxmPmXBBY jxSQ97ig+iBSyNRApsJ/JoiTjJjUm60knirGHdh6gZJzHxfXFc1qHfrY3p+kuuGGKXzK 9r4DinfBSWu/aiCfx73e4bKVvETwGiGzt1kUIKVz9oA3yKHEqbztUSu63JfmZMW+T/jp 6NV4tJtDUQiERt88LPocGy/vZVl0xvxHaVSNsS1mbUSIGU7fyUeuMI6aY75nt/qI1bxq bB3vZLQOucm4GPUnK7pOTmPZ0/ER0CBci5+/FZ4s6cMpWRCQXO/dR4VKy3IAm0wN6TkG bgCg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=bufdeu7O6f4j5OcMYl8av117pFzQIWznVNYU0Z5xyRk=; b=DVC8mje91kB7wHoQbHx4H0Rj7qGVZ0FTExABMhyb4RIdkGA975Moq9RaSlDh0mIjMo ud8ajLh2oa9Y3CQbMDkMDnH9i8GC8Ss/bXS9gtPHlem2PZkNzbAEB4mbGOZtfOJKjKVr l4Zj+bmHLf6RsZGFc4pT5fXFLnk8o5FPN3rBgA1Q4ToZSo7xcCNXiivk2CytBVGpGAog d756bDKAam9Rn7bC8hrrHGzLz3G2ast6MjA+GBHANWFcyARI8UIS6HptrdZ3W/hfzAhO 2rlOaRo80eA7+fEAsQw7ImEAkmUmXLezZeQYk6pvOtF7rvJaSsDM1dhClDRHb2GZK50h IoOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dQ9FRFth; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt21-20020a17090af01500b00213022ff9a8si7508935pjb.168.2022.11.25.10.22.17; Fri, 25 Nov 2022 10:22:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dQ9FRFth; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbiKYSLj (ORCPT + 99 others); Fri, 25 Nov 2022 13:11:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiKYSLi (ORCPT ); Fri, 25 Nov 2022 13:11:38 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BFFE31DD6; Fri, 25 Nov 2022 10:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669399897; x=1700935897; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gC1O2EpjM7tKecxBRtq3dHXj7LrD8+1bUGKq3WhcNRs=; b=dQ9FRFthbgcahnZiDc3I0fY+bFVaqUi5g3lt+ihLVp9YdRtx+nTuzkUP TephxamY0Bax4kHlHpMx6gIbw6MHsfM/Cd/vyeCK/fCEkbKPama7S9kAv jL91oaCs4ziwy/nEJOQPAHf294boOK/g4cDrDnrXbmwJfjrOvX55F1aff u4Z9wdx0VDDjAseL7bnNFlOu589aNw1q4a7ffNediR6OHZY+bjTEr0Eg/ Yo3Tfuu7Uh1VSzYEBLRf3nXrtczNbSgYNEGgrBEcbe8LG1sDt+lVxeyqM L3wD0kDrW5fb8mJzhX78SQOKPTUnUYi3ZFVGNAiHAjiV/l6N6ZF8pTxHJ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="341426383" X-IronPort-AV: E=Sophos;i="5.96,194,1665471600"; d="scan'208";a="341426383" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 10:11:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="642762582" X-IronPort-AV: E=Sophos;i="5.96,194,1665471600"; d="scan'208";a="642762582" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 25 Nov 2022 10:11:34 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 00A77128; Fri, 25 Nov 2022 20:12:00 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij Subject: [PATCH v1 1/2] gpiolib: Provide to_gpio_device() helper Date: Fri, 25 Nov 2022 20:11:57 +0200 Message-Id: <20221125181158.67265-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750493359378164466?= X-GMAIL-MSGID: =?utf-8?q?1750493359378164466?= Provide to_gpio_device() helper which can be utilized in the existing and future code. While at it, make sure it becomes no-op at compilation time. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 2 +- drivers/gpio/gpiolib.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 119c9c3a2a50..9b935288db9d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -547,7 +547,7 @@ EXPORT_SYMBOL_GPL(gpiochip_line_is_valid); static void gpiodevice_release(struct device *dev) { - struct gpio_device *gdev = container_of(dev, struct gpio_device, dev); + struct gpio_device *gdev = to_gpio_device(dev); unsigned long flags; spin_lock_irqsave(&gpio_lock, flags); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index d900ecdbac46..027674025561 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -20,9 +20,9 @@ /** * struct gpio_device - internal state container for GPIO devices - * @id: numerical ID number for the GPIO chip * @dev: the GPIO device struct * @chrdev: character device for the GPIO device + * @id: numerical ID number for the GPIO chip * @mockdev: class device used by the deprecated sysfs interface (may be * NULL) * @owner: helps prevent removal of modules exporting active GPIOs @@ -47,9 +47,9 @@ * userspace. */ struct gpio_device { - int id; struct device dev; struct cdev chrdev; + int id; struct device *mockdev; struct module *owner; struct gpio_chip *chip; @@ -72,6 +72,8 @@ struct gpio_device { #endif }; +#define to_gpio_device(_dev_) container_of(_dev_, struct gpio_device, dev) + /* gpio suffixes used for ACPI and device tree lookup */ static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; From patchwork Fri Nov 25 18:11:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 26117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4211850wrr; Fri, 25 Nov 2022 10:22:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xeCAjqcm0HCkeL3hIT/8QKhL3Wnho28zaBdK16eM3z0rKyqvGqq04hi5YrWmtNtYI65Dr X-Received: by 2002:a65:53ca:0:b0:454:21a6:7ae5 with SMTP id z10-20020a6553ca000000b0045421a67ae5mr22886348pgr.615.1669400566078; Fri, 25 Nov 2022 10:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669400566; cv=none; d=google.com; s=arc-20160816; b=wfkhuq4ZUhN/b889emDVxELEvq/jw4CY2W7HBqyrkBosvldbaJQzBeUVD+S/RBMxD3 qrgYIY197/ykBjJmetoufVY8BqWEG2g69wO3pO0ZgxRJVDhNlTkHMheQYUGhIhEE/uJX +1jl306UpTWeyEvKvDazOoaeARpBLBG0iR+AyziEh295r4UFWACJHJms9yhsp0JRz07r 44uy+UU6F9ibpSlczq7sx5zI6vOsDwC+RGi47CSo7GRkyqtMq5eHnGT+sILhWVgij7tO +LiPn1Z75xOkIKbhgepxkHtBTpJB7TlRHKctgn7KQMjnsFSAdhX9WoYXq2FIwgOxLkrP OHLA== 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=4WukVm33SnBl8Judhs1oyULIyUDGnSSVJHPI/+5Ke2M=; b=SD9CtnDWr2p1wdeClRmbVN0+QkibOywpy4SyOBwUdBJYpfmraVyUh5einhCPJb0jY6 lZu/LGvOkdyh38JrrviBbQ5QdC2XSAXPYJwaFUSUukyZIlcFw/zkUdNhNmMSTNF0c3vi cpJNw2PdsL0RnXFJtw27/tZg8Pm0WMmm2mV1p6H9leE4ueDBJYP1YimOVQvkSnxdJw9K lfhc/93OeNS7t2lx3DExJjkGapoeH7cD2zh/CJWTIwTcukNMzChBhgMo5VfRsESiixGi /uL2t4ZZ3/n0KOjB2Drx8s30E1K7Vb5a5UTQTtZKTfXOYdF6pgPKh6/ixTY1qIDrVA1u ObIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WSmbR24M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mi12-20020a17090b4b4c00b00212deed484esi5102219pjb.132.2022.11.25.10.22.32; Fri, 25 Nov 2022 10:22:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WSmbR24M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbiKYSLl (ORCPT + 99 others); Fri, 25 Nov 2022 13:11:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiKYSLj (ORCPT ); Fri, 25 Nov 2022 13:11:39 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 661B231DD8; Fri, 25 Nov 2022 10:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669399898; x=1700935898; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=McC2W34dBid4dm371TTlzsuWAfcvm6zxbkwy2w4MfyY=; b=WSmbR24MaAt0GCv8LcZGk8g4N8kaMGPZ7RAOUHE4vDtUQbB2D97bUiR6 /mKHdJeC0hFgWgl/M0ebwJDN5uDRdIC1ZEiPTV36IocqwaL0ArR1X88Xf D8VvV2Yi2cGitullCzTXCSgAeO3RN3MQs8iPEkPW78lsj4jiObX18Gm8c paaDS3pn+XMi6b8IQ0B6ke4hFPwavklE3IYcz9NA+YOnPkPGa1fsghWV7 wCfTI6W6Ilt3sDmX3RKQJAd8tk5XAHV1AzjEuIkL4E77eVqjIxdzULE2R elhehk5a221v/V7Q8tc4in8eA0u7uiNKyMXDn1m5oJ3I7KR9kJeij7S/t g==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="341426385" X-IronPort-AV: E=Sophos;i="5.96,194,1665471600"; d="scan'208";a="341426385" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 10:11:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="642762583" X-IronPort-AV: E=Sophos;i="5.96,194,1665471600"; d="scan'208";a="642762583" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 25 Nov 2022 10:11:35 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0E198F7; Fri, 25 Nov 2022 20:12:01 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij Subject: [PATCH v1 2/2] gpiolib: Introduce gpio_device_get() and gpio_device_put() Date: Fri, 25 Nov 2022 20:11:58 +0200 Message-Id: <20221125181158.67265-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221125181158.67265-1-andriy.shevchenko@linux.intel.com> References: <20221125181158.67265-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750493367739030945?= X-GMAIL-MSGID: =?utf-8?q?1750493367739030945?= Introduce gpio_device_get() and gpio_device_put() helpers and convert existing users. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-cdev.c | 21 +++++++++------------ drivers/gpio/gpiolib.c | 14 ++++++-------- drivers/gpio/gpiolib.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index f9288e41e3a7..acfb779767ed 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -265,7 +265,7 @@ static void linehandle_free(struct linehandle_state *lh) if (lh->descs[i]) gpiod_free(lh->descs[i]); kfree(lh->label); - put_device(&lh->gdev->dev); + gpio_device_put(lh->gdev); kfree(lh); } @@ -307,8 +307,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) lh = kzalloc(sizeof(*lh), GFP_KERNEL); if (!lh) return -ENOMEM; - lh->gdev = gdev; - get_device(&gdev->dev); + lh->gdev = gpio_device_get(gdev); if (handlereq.consumer_label[0] != '\0') { /* label is only initialized if consumer_label is set */ @@ -1480,7 +1479,7 @@ static void linereq_free(struct linereq *lr) } kfifo_free(&lr->events); kfree(lr->label); - put_device(&lr->gdev->dev); + gpio_device_put(lr->gdev); kfree(lr); } @@ -1550,8 +1549,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) if (!lr) return -ENOMEM; - lr->gdev = gdev; - get_device(&gdev->dev); + lr->gdev = gpio_device_get(gdev); for (i = 0; i < ulr.num_lines; i++) { lr->lines[i].req = lr; @@ -1799,7 +1797,7 @@ static void lineevent_free(struct lineevent_state *le) if (le->desc) gpiod_free(le->desc); kfree(le->label); - put_device(&le->gdev->dev); + gpio_device_put(le->gdev); kfree(le); } @@ -1965,8 +1963,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) le = kzalloc(sizeof(*le), GFP_KERNEL); if (!le) return -ENOMEM; - le->gdev = gdev; - get_device(&gdev->dev); + le->gdev = gpio_device_get(gdev); if (eventreq.consumer_label[0] != '\0') { /* label is only initialized if consumer_label is set */ @@ -2514,7 +2511,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) init_waitqueue_head(&cdev->wait); INIT_KFIFO(cdev->events); - cdev->gdev = gdev; + cdev->gdev = gpio_device_get(gdev); cdev->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify; ret = blocking_notifier_chain_register(&gdev->notifier, @@ -2522,7 +2519,6 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) if (ret) goto out_free_bitmap; - get_device(&gdev->dev); file->private_data = cdev; ret = nonseekable_open(inode, file); @@ -2535,6 +2531,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) blocking_notifier_chain_unregister(&gdev->notifier, &cdev->lineinfo_changed_nb); out_free_bitmap: + gpio_device_put(gdev); bitmap_free(cdev->watched_lines); out_free_cdev: kfree(cdev); @@ -2555,7 +2552,7 @@ static int gpio_chrdev_release(struct inode *inode, struct file *file) bitmap_free(cdev->watched_lines); blocking_notifier_chain_unregister(&gdev->notifier, &cdev->lineinfo_changed_nb); - put_device(&gdev->dev); + gpio_device_put(gdev); kfree(cdev); return 0; diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9b935288db9d..52a1b03987dc 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -874,7 +874,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, gpiochip_free_valid_mask(gc); if (gdev->dev.release) { /* release() has been registered by gpiochip_setup_dev() */ - put_device(&gdev->dev); + gpio_device_put(gdev); goto err_print_message; } err_remove_from_list: @@ -961,7 +961,7 @@ void gpiochip_remove(struct gpio_chip *gc) * gone. */ gcdev_unregister(gdev); - put_device(&gdev->dev); + gpio_device_put(gdev); } EXPORT_SYMBOL_GPL(gpiochip_remove); @@ -2052,17 +2052,15 @@ static int validate_desc(const struct gpio_desc *desc, const char *func) int gpiod_request(struct gpio_desc *desc, const char *label) { int ret = -EPROBE_DEFER; - struct gpio_device *gdev; VALIDATE_DESC(desc); - gdev = desc->gdev; - if (try_module_get(gdev->owner)) { + if (try_module_get(desc->gdev->owner)) { ret = gpiod_request_commit(desc, label); if (ret) - module_put(gdev->owner); + module_put(desc->gdev->owner); else - get_device(&gdev->dev); + gpio_device_get(desc->gdev); } if (ret) @@ -2123,7 +2121,7 @@ void gpiod_free(struct gpio_desc *desc) { if (desc && desc->gdev && gpiod_free_commit(desc)) { module_put(desc->gdev->owner); - put_device(&desc->gdev->dev); + gpio_device_put(desc->gdev); } else { WARN_ON(extra_checks); } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 027674025561..13b2c02ec328 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -74,6 +74,16 @@ struct gpio_device { #define to_gpio_device(_dev_) 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" };