From patchwork Wed Jun 21 17:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 695116 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 BB7C0EB64D7 for ; Wed, 21 Jun 2023 17:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjFURtt (ORCPT ); Wed, 21 Jun 2023 13:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbjFURtq (ORCPT ); Wed, 21 Jun 2023 13:49:46 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9FE1731; Wed, 21 Jun 2023 10:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687369785; x=1718905785; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=UcbQzh/QfOhvEjVYIh628xUqEPTf7XQWOJPKRRENFlQ=; b=AvEmWQPFlSEaJHw05r1oH/rLykS+/0cVsbEtzYbzd6/VZMqin5X7htSf h+9jcYEIbRc4nK80aIpA3enD0WxT79cZ06F6WQBKfOn4DrVf1anm+u5YX 1V5cg18pcx9qiPJJkXSVcm4a3wIe2KHA8/vBNySKIGT3EksPdpjpPAant kHanXyEGozh239wRSn+ziprWzEPvIpUOLARMlciAhwIaUu+ggWm95FN+1 3Sp9L52o6E7kuJCeBw7PMQ/a0Tf9J+hI0D+MqNuRPINVUpB1LpPUCtgGB 0QWBRWQJV02Jl3q6qibmJ8SeHwCNPDVunVDCCXa7tyoV362QbFKgMm8Za w==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="389819298" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="389819298" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 10:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="691928085" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="691928085" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 21 Jun 2023 10:49:39 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 73CD9195; Wed, 21 Jun 2023 20:49:49 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 1/5] gpiolib: Make gpiochip_hierarchy_add_domain() return domain Date: Wed, 21 Jun 2023 20:49:39 +0300 Message-Id: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org As a preparatory patch and for the sake of consistency, make gpiochip_hierarchy_add_domain() return IRQ domain. While at it, rename it to gpiochip_hierarchy_create_domain() to show the change. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0d25d9d439a2..058deaa1aa36 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1289,12 +1289,14 @@ static void gpiochip_hierarchy_setup_domain_ops(struct irq_domain_ops *ops) ops->free = irq_domain_free_irqs_common; } -static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) +static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc) { + struct irq_domain *domain; + if (!gc->irq.child_to_parent_hwirq || !gc->irq.fwnode) { chip_err(gc, "missing irqdomain vital data\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } if (!gc->irq.child_offset_to_irq) @@ -1306,7 +1308,7 @@ static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops); - gc->irq.domain = irq_domain_create_hierarchy( + domain = irq_domain_create_hierarchy( gc->irq.parent_domain, 0, gc->ngpio, @@ -1314,12 +1316,12 @@ static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) &gc->irq.child_irq_domain_ops, gc); - if (!gc->irq.domain) - return -ENOMEM; + if (!domain) + return ERR_PTR(-ENOMEM); gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip); - return 0; + return domain; } static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc) @@ -1363,9 +1365,9 @@ EXPORT_SYMBOL_GPL(gpiochip_populate_parent_fwspec_fourcell); #else -static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) +static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc) { - return -EINVAL; + return ERR_PTR(-EINVAL); } static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc) @@ -1664,9 +1666,9 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, /* If a parent irqdomain is provided, let's build a hierarchy */ if (gpiochip_hierarchy_is_hierarchical(gc)) { - int ret = gpiochip_hierarchy_add_domain(gc); - if (ret) - return ret; + gc->irq.domain = gpiochip_hierarchy_create_domain(gc); + if (IS_ERR(gc->irq.domain)) + return PTR_ERR(gc->irq.domain); } else { gc->irq.domain = irq_domain_create_simple(fwnode, gc->ngpio, From patchwork Wed Jun 21 17:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 694803 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 9CFA5EB64D8 for ; Wed, 21 Jun 2023 17:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbjFURtn (ORCPT ); Wed, 21 Jun 2023 13:49:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230371AbjFURtm (ORCPT ); Wed, 21 Jun 2023 13:49:42 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC3811718; Wed, 21 Jun 2023 10:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687369781; x=1718905781; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kdcUcjY6P739bulIvEkWeV/vSYtThvEuSEz95gNk9Zw=; b=XJObtDWvvw/ga0sMmuK91gESfw48jbl9XYWALd1P5jcGqzSXLngK03LW 3qV/PBFX3pFHXgi0WgBiasPutU8LwxfJb9gZWz4oMAu0oTYj4lAdzk2KT F1FzFELyxqWKydkKAyzX0DiNUyH6rN7f0gSwBX8tOARLjq6Bm1oQF1Xr7 jmzz38slUaPmuN1GhNUDUs1EXO+PTYf8sI8jaY2r0OI4rQX/JvTY+fRbL cuWUbjkmTfPcUJpRldllAVWW0gEfuVhJNfXyZyxCc5x+YEL7ZI85qJ/U2 4xIvof1bm37ag46Jmioh8d0IIooEMH4bp4OWKqHZ5CNzVJ3O2DK1L1qts g==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="389819283" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="389819283" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 10:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="691928082" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="691928082" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 21 Jun 2023 10:49:39 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7D689193; Wed, 21 Jun 2023 20:49:49 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 2/5] gpiolib: Factor out gpiochip_simple_create_domain() Date: Wed, 21 Jun 2023 20:49:40 +0300 Message-Id: <20230621174943.30302-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> References: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org As a preparatory patch and for the sake of consistency, factor out gpiochip_simple_create_domain(). Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 058deaa1aa36..fac1124d5016 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1444,6 +1444,19 @@ static const struct irq_domain_ops gpiochip_domain_ops = { .xlate = irq_domain_xlate_twocell, }; +static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc) +{ + struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev); + struct irq_domain *domain; + + domain = irq_domain_create_simple(fwnode, gc->ngpio, gc->irq.first, + &gpiochip_domain_ops, gc); + if (!domain) + return ERR_PTR(-EINVAL); + + return domain; +} + /* * TODO: move these activate/deactivate in under the hierarchicial * irqchip implementation as static once SPMI and SSBI (all external @@ -1670,13 +1683,9 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, if (IS_ERR(gc->irq.domain)) return PTR_ERR(gc->irq.domain); } else { - gc->irq.domain = irq_domain_create_simple(fwnode, - gc->ngpio, - gc->irq.first, - &gpiochip_domain_ops, - gc); - if (!gc->irq.domain) - return -EINVAL; + gc->irq.domain = gpiochip_simple_create_domain(gc); + if (IS_ERR(gc->irq.domain)) + return PTR_ERR(gc->irq.domain); } if (gc->irq.parent_handler) { From patchwork Wed Jun 21 17:49:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 694801 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 E200DEB64D7 for ; Wed, 21 Jun 2023 17:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbjFURuR (ORCPT ); Wed, 21 Jun 2023 13:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbjFURty (ORCPT ); Wed, 21 Jun 2023 13:49:54 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C7A1BC3; Wed, 21 Jun 2023 10:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687369790; x=1718905790; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MGD3tk/qL1WcZv7h1naypCRcwmKu0ejHb+zaSupSua4=; b=VZZtPqFf3pVdiiAF8njYL2CJbWrufuHyp65jOfg4x60PMPSXh/pdkhSF FKlGqDyXiZg7YypEXuNeQU60xjTO3zar32DSi3lsxYrKJgU1/hqHUNkA8 rM+mHyn4s3w4+79Z8c+tie2RO2DOQufUTnHtC3qRJdlkLoiUz1IBEGO8l B91OSM2ZTrCZIP5mA4UusHX+lUtnvEI1gg2DtOOITDhH8hO3jaHYtctEe Yovlizl9AtmSpU0i/AVoSasS9VucVxWVXxhGOD/geiUzG6G2ptB9J4Sq1 8rufD7F3GAL19MTBYnC9Lg2UhQGpZRFYGTMB5YJwOTFJN4Shi6T+9vwVk Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="344988562" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="344988562" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 10:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="888775360" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="888775360" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 21 Jun 2023 10:49:39 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 84880241; Wed, 21 Jun 2023 20:49:49 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 3/5] gpiolib: Do not assign error pointer to the GPIO IRQ chip domain Date: Wed, 21 Jun 2023 20:49:41 +0300 Message-Id: <20230621174943.30302-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> References: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Check domain for being an error pointer before assigning it to the GPIO IRQ chip domain. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index fac1124d5016..0e40f9a44519 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1647,6 +1647,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, { struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev); struct irq_chip *irqchip = gc->irq.chip; + struct irq_domain *domain; unsigned int type; unsigned int i; @@ -1679,14 +1680,13 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, /* If a parent irqdomain is provided, let's build a hierarchy */ if (gpiochip_hierarchy_is_hierarchical(gc)) { - gc->irq.domain = gpiochip_hierarchy_create_domain(gc); - if (IS_ERR(gc->irq.domain)) - return PTR_ERR(gc->irq.domain); + domain = gpiochip_hierarchy_create_domain(gc); } else { - gc->irq.domain = gpiochip_simple_create_domain(gc); - if (IS_ERR(gc->irq.domain)) - return PTR_ERR(gc->irq.domain); + domain = gpiochip_simple_create_domain(gc); } + if (IS_ERR(domain)) + return PTR_ERR(domain); + gc->irq.domain = domain; if (gc->irq.parent_handler) { for (i = 0; i < gc->irq.num_parents; i++) { From patchwork Wed Jun 21 17:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 694802 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 D22E9EB64DD for ; Wed, 21 Jun 2023 17:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbjFURts (ORCPT ); Wed, 21 Jun 2023 13:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjFURtq (ORCPT ); Wed, 21 Jun 2023 13:49:46 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87503E41; Wed, 21 Jun 2023 10:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687369785; x=1718905785; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YP5QjbCjQUTAvk5hMhdqtzeImdCvYuUXEySMOpba5Mw=; b=OqmVu7Q66+2sbiw2uQOy4m1b+D4DTg8mDzR5TYCxv6YOwgIpvSvoEIA0 oX3DTqBEhgnDc6gPAfc50xfXega4/2Vap0rLMqsL56jjt0vWwrf+ZweIF e6zOHKYT4Uof0b35TmjrIehw1NvKVWGQQQK4eUuNFYhspzHFo12qhT7o3 g0TEyOSZ30liOzwvt5pcKZPzgh2XiQeoGWYkxepMIobsTaZ/AiRJRnTsm 4qO5sNI9kimHdqHgpE2t8uW1BTABoXKDQmweX2FTta4A2nbdBIj/GUstI QQ0uamSvtKPom7f918GGZRbp8o6YCOv/mAgI03TVLwbzxHY4GkrAucbno w==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="389819294" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="389819294" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 10:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="691928084" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="691928084" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 21 Jun 2023 10:49:39 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8B3902C7; Wed, 21 Jun 2023 20:49:49 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 4/5] gpiolib: Split out gpiochip_irqchip_add_allocated_domain() helper Date: Wed, 21 Jun 2023 20:49:42 +0300 Message-Id: <20230621174943.30302-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> References: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The gpiochip_irqchip_add_allocated_domain() can be used in another place in the code. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0e40f9a44519..59d87e60b108 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1635,6 +1635,28 @@ static void gpiochip_set_irq_hooks(struct gpio_chip *gc) } } +static int gpiochip_irqchip_add_allocated_domain(struct gpio_chip *gc, + struct irq_domain *domain, + bool allocated_externally) +{ + if (!domain) + return -EINVAL; + + gc->to_irq = gpiochip_to_irq; + gc->irq.domain = domain; + gc->irq.domain_is_allocated_externally = allocated_externally; + + /* + * Using barrier() here to prevent compiler from reordering + * gc->irq.initialized before adding irqdomain. + */ + barrier(); + + gc->irq.initialized = true; + + return 0; +} + /** * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip * @gc: the GPIO chip to add the IRQ chip to @@ -1788,22 +1810,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc) int gpiochip_irqchip_add_domain(struct gpio_chip *gc, struct irq_domain *domain) { - if (!domain) - return -EINVAL; - - gc->to_irq = gpiochip_to_irq; - gc->irq.domain = domain; - gc->irq.domain_is_allocated_externally = true; - - /* - * Using barrier() here to prevent compiler from reordering - * gc->irq.initialized before adding irqdomain. - */ - barrier(); - - gc->irq.initialized = true; - - return 0; + return gpiochip_irqchip_add_allocated_domain(gc, domain, true); } EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_domain); From patchwork Wed Jun 21 17:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 695117 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 66515EB64DC for ; Wed, 21 Jun 2023 17:49:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbjFURtq (ORCPT ); Wed, 21 Jun 2023 13:49:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbjFURtp (ORCPT ); Wed, 21 Jun 2023 13:49:45 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C91F81733; Wed, 21 Jun 2023 10:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687369782; x=1718905782; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N75xiFEB2l7sDxs1N2ykos/S0hCXGE4VnACWdbw7VI8=; b=Zqlqvaks/91GNYVJOgsnKR0T7jdDpb9cPmH1rnvkxcgM2YwhYeoYo9NB rTPYS4Xpx1TNH48vXOExYsDsBQ+/4Eg9ho4OS/xShY/BbNc67HsDjYV0U ZsuzVntAnsPBMquD0439gGBqw9pZKII458BXMGOUgOA7CJzZacqxi+KkQ gedDk4CVwiJ2cF1ntt6OK81QszzwPFUTkwA7y7Xqnv7G4wkp+DzAXg2KD kHlcr/OKzZHDZfjnAROPa+eBU/zPaIHga/UrVJZn7Gg84Orh5IGFZSS2P CHQtNqmhBxkeGakdEd6Yv5urzybaELouc8V3j5HGoVbWjYvz3KhdlYh6i Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="389819289" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="389819289" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 10:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="691928081" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="691928081" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 21 Jun 2023 10:49:39 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8FCDA1FD; Wed, 21 Jun 2023 20:49:49 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 5/5] gpiolib: Replace open coded gpiochip_irqchip_add_allocated_domain() Date: Wed, 21 Jun 2023 20:49:43 +0300 Message-Id: <20230621174943.30302-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> References: <20230621174943.30302-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace open coded variant of gpiochip_irqchip_add_allocated_domain() in gpiochip_add_irqchip(). Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 59d87e60b108..bc8b9d6afe0e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1642,6 +1642,9 @@ static int gpiochip_irqchip_add_allocated_domain(struct gpio_chip *gc, if (!domain) return -EINVAL; + if (gc->to_irq) + chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__); + gc->to_irq = gpiochip_to_irq; gc->irq.domain = domain; gc->irq.domain_is_allocated_externally = allocated_externally; @@ -1672,6 +1675,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, struct irq_domain *domain; unsigned int type; unsigned int i; + int ret; if (!irqchip) return 0; @@ -1692,10 +1696,6 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, "%pfw: Ignoring %u default trigger\n", fwnode, type)) type = IRQ_TYPE_NONE; - if (gc->to_irq) - chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__); - - gc->to_irq = gpiochip_to_irq; gc->irq.default_type = type; gc->irq.lock_key = lock_key; gc->irq.request_key = request_key; @@ -1708,7 +1708,6 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, } if (IS_ERR(domain)) return PTR_ERR(domain); - gc->irq.domain = domain; if (gc->irq.parent_handler) { for (i = 0; i < gc->irq.num_parents; i++) { @@ -1732,14 +1731,9 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, gpiochip_set_irq_hooks(gc); - /* - * Using barrier() here to prevent compiler from reordering - * gc->irq.initialized before initialization of above - * GPIO chip irq members. - */ - barrier(); - - gc->irq.initialized = true; + ret = gpiochip_irqchip_add_allocated_domain(gc, domain, false); + if (ret) + return ret; acpi_gpiochip_request_interrupts(gc);