The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: filipp.dunsky@gmail.com, Radu Rendec <radu@rendec.net>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6 2/2] irqchip: Add Cortina Systems CS75xx peripheral interrupt controller
Date: Tue, 01 Dec 2026 22:00:22 +0100	[thread overview]
Message-ID: <87zeuoogwp.ffs@fw13> (raw)
In-Reply-To: <20261201-cs75xx-intc-v6-2-bcd0a80afd62@gmail.com>

On Tue, Dec 01 2026 at 19:32, Fil Dunsky via wrote:
> +
> +static int __init cs75xx_intc_domain_init(struct irq_domain *domain)
> +{
> +	const struct cs75xx_intc_setup *setup = domain->host_data;
> +	struct irq_chip_generic *gc;
> +
> +	gc = irq_get_domain_generic_chip(domain, 0);
> +	gc->reg_base = setup->base;
> +	gc->chip_types[0].regs.mask = CS75XX_INTC_ENABLE;
> +	gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit;
> +	gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit;
> +
> +	/* The setup data lives on the stack and is only needed before publication. */
> +	domain->host_data = NULL;
> +	irq_set_chained_handler_and_data(setup->parent_irq, cs75xx_intc_handler, domain);
> +	return 0;
> +}

irq_domain_chip_generic_info has its own init() callback for a
reason. The point is that the chip has to be ready and complete after
irq_domain_alloc_generic_chips() returns.

Your admittedly clever abuse of the domain_info::init() callback relies
on the behavior of the current core code.

That's not really clever as it is prone to hard to diagnose failures
down the road if the core code changes.

I pointed you to an example which got it right, no?

> +static int __init cs75xx_intc_init(struct device_node *np, struct device_node *parent)
> +{
> +	struct cs75xx_intc_setup setup;

Handing host data in with a pointer to stack memory and then clearing it
in the domain somewhere else is the other "clever" thing which makes me
cringe.

I can see the "charm" of your approach, but then it want's to be done
right. Something like the uncompiled below should work. You get the
idea. Feel free to turn it into a proper patch.

Thanks,

        tglx
---
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -149,6 +149,12 @@ struct irq_domain_chip_generic;
  * @gc:		Pointer to a list of generic chips. There is a helper function for
  *		setting up one or more generic chips for interrupt controllers
  *		drivers using the generic chip library which uses this pointer.
+ * @init_data:	Controller private data pointer for the init callbacks of the domain
+ *		and the generic chips. Can safely point to stack memory. It is NULL'ed
+ *		after the callbacks have completed and before the domain is published.
+ *		The init() callbacks are not allowed to store the pointer. It's only
+ *		there to provide data for domain and chip initialization to avoid carrying
+ *		unused allocated memory around in @host_data forever.
  * @dev:	Pointer to the device which instantiated the irqdomain
  *		With per device irq domains this is not necessarily the same
  *		as @pm_dev.
@@ -188,6 +194,7 @@ struct irq_domain {
 	const struct msi_parent_ops	*msi_parent_ops;
 #endif
 	void				(*exit)(struct irq_domain *d);
+	void				*init_data;
 
 	/* reverse map data. The linear map gets appended to the irq_domain */
 	irq_hw_number_t			hwirq_max;
@@ -325,6 +332,8 @@ struct irq_domain_chip_generic_info;
  *			domains are added using same fwnode
  * @ops:		Domain operation callbacks
  * @host_data:		Controller private data pointer
+ * @init_data:		Controller private data pointer for the init callbacks
+ *			of the domain and generic chips. Can safely point to stack memory.
  * @dev:		Device which creates the domain
  * @dgc_info:		Geneneric chip information structure pointer used to
  *			create generic chips for the domain if not NULL.
@@ -345,6 +354,7 @@ struct irq_domain_info {
 	const char				*name_suffix;
 	const struct irq_domain_ops		*ops;
 	void					*host_data;
+	void					*init_data;
 	struct device				*dev;
 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
 	/**
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -332,6 +332,7 @@ static struct irq_domain *__irq_domain_i
 	domain->flags |= info->domain_flags;
 	domain->exit = info->exit;
 	domain->dev = info->dev;
+	domain->init_data = info->init_data;
 
 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
 	if (info->parent) {
@@ -352,6 +353,8 @@ static struct irq_domain *__irq_domain_i
 		if (err)
 			goto err_domain_gc_remove;
 	}
+	/* info::init_data can point to stack memory. Don't leak the pointer */
+	domain->init_data = NULL;
 
 	__irq_domain_publish(domain);
 


      reply	other threads:[~2026-12-01 21:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:32 [PATCH v6 0/2] irqchip: Add Cortina Systems CS75xx peripheral interrupt controller Fil Dunsky via B4 Relay
2026-12-01 16:32 ` [PATCH v6 1/2] dt-bindings: interrupt-controller: Add Cortina Systems CS7542 " Fil Dunsky via B4 Relay
2026-12-01 16:32 ` [PATCH v6 2/2] irqchip: Add Cortina Systems CS75xx " Fil Dunsky via B4 Relay
2026-12-01 21:00   ` Thomas Gleixner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zeuoogwp.ffs@fw13 \
    --to=tglx@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=filipp.dunsky@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=radu@rendec.net \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox