[RFT PATCH v2 04/14] gpio: rtd1625: create the IRQ domain from the gpio-regmap callback

Andy Shevchenko andriy.shevchenko at linux.intel.com
Fri Nov 27 10:30:58 PST 2026


On Fri, Nov 27, 2026 at 03:52:21PM +0100, Michael Walle wrote:
> Use the new .create_irq_domain() to actually create the domain. This
> way, there is no window where a NULL pointer could be dereferenced.
> 
> Switch the irq host_data to the gpio_regmap pointer because it will
> already be needed in the irq domain callbacks. Otherwise the
> .create_irq_domain() callback would have to set the data->gpio_reg
> pointer which looks odd.
> 
> Split the interrupt handling into two steps: first fill in the
> interrupts and in the callback attach the handler.
> 
> Don't use device managed resources anymore. Instead use the new
> .remove_irq_domain() callback. The driver didn't dispose any of the IRQ
> mappings before, although irq_domain_remove() mandates that. Thus add
> that to this callback, too.

...

> +static struct irq_domain *rtd1625_gpio_create_irq_domain(struct gpio_regmap *gpio_reg)
> +{
> +	struct rtd1625_gpio *data = gpio_regmap_get_drvdata(gpio_reg);
> +	struct device *dev = regmap_get_device(data->regmap);
> +	struct irq_domain_info d_info = {};
> +
> +	d_info.fwnode = dev_fwnode(dev);
> +	d_info.size = data->info->num_gpios;
> +	d_info.hwirq_max = data->info->num_gpios;
> +	d_info.ops = &rtd1625_gpio_irq_domain_ops;
> +	d_info.host_data = gpio_reg;
> +
> +	data->domain = irq_domain_instantiate(&d_info);
> +	if (IS_ERR(data->domain))
> +		return data->domain;

This is open coded irq_domain_create_linear(). The only difference is that we
propagate the underneath error code instead of decoding NULL as ENOMEM or
EINVAL or something like that. If this is the case, add a comment explaining
why, otherwise somebody will change that in the future w/o much thinking.

Note, it was open coded since there is no devm_*() helper for that.

> +	for (unsigned int i = 0; i < RTD1625_MAX_IRQS; i++) {
> +		if (data->irqs[i])
> +			irq_set_chained_handler_and_data(data->irqs[i],
> +							 rtd1625_gpio_irq_handle,
> +							 data);
> +	}
> +
> +	return data->domain;
> +}

...

> +static void rtd1625_gpio_remove_irq_domain(struct gpio_regmap *gpio_reg)
> +{
> +	struct rtd1625_gpio *data = gpio_regmap_get_drvdata(gpio_reg);
> +
> +	for (unsigned int i = 0; i < RTD1625_MAX_IRQS; i++) {

> +		if (data->irqs[i])

Do you need this? It seems to me that irq_to_desc() returns NULL
and scoped_irqdesc_get_and_buslock() does nothing. Yes, I know
it's a tricky code.

> +			irq_set_chained_handler_and_data(data->irqs[i], NULL, NULL);
> +	}
> +
> +	for (irq_hw_number_t hwirq = 0; hwirq < data->info->num_gpios; hwirq++)
> +		irq_dispose_mapping(irq_find_mapping(data->domain, hwirq));
> +
> +	irq_domain_remove(data->domain);
> +}

-- 
With Best Regards,
Andy Shevchenko





More information about the linux-arm-kernel mailing list