[PATCH v1] mfd: twl4030-irq: Fix unused variable warning when CONFIG_OF disabled

Haofeng Li posted 1 patch 3 months, 3 weeks ago
drivers/mfd/twl4030-irq.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
[PATCH v1] mfd: twl4030-irq: Fix unused variable warning when CONFIG_OF disabled
Posted by Haofeng Li 3 months, 3 weeks ago
From: Haofeng Li <lihaofeng@kylinos.cn>

With compile testing on non-OF platforms, compiler reports:
../drivers/mfd/twl4030-irq.c:679:46: error: unused variable 'node' [-Werror=unused-variable]
  679 |         struct                  device_node *node = dev->of_node;

This occurs because:
1. of_fwnode_handle() is unavailable without CONFIG_OF
2. The 'node' variable becomes unused
3. -Werror flags the unused variable as an error

Fix by:
1. Replace device_node pointer with fwnode_handle pointer,
   initialized to NULL
2. Only setting fwnode when CONFIG_OF is enabled
3. Passing fwnode to irq_domain_create_legacy()

Passing NULL fwnode is safe:
- irq_domain_create_legacy() accepts NULL fwnode_handle
- The function has appropriate NULL checks in its implementation
- Equivalent to original behavior when CONFIG_OF is disabled

Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
---
 drivers/mfd/twl4030-irq.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
index 232c2bfe8c18..8297966bd957 100644
--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -676,7 +676,7 @@ int twl4030_init_irq(struct device *dev, int irq_num)
 	static struct irq_chip	twl4030_irq_chip;
 	int			status, i;
 	int			irq_base, irq_end, nr_irqs;
-	struct			device_node *node = dev->of_node;
+	struct fwnode_handle    *fwnode = NULL;
 
 	/*
 	 * TWL core and pwr interrupts must be contiguous because
@@ -690,8 +690,10 @@ int twl4030_init_irq(struct device *dev, int irq_num)
 		dev_err(dev, "Fail to allocate IRQ descs\n");
 		return irq_base;
 	}
-
-	irq_domain_create_legacy(of_fwnode_handle(node), nr_irqs, irq_base, 0,
+#ifdef CONFIG_OF
+	fwnode = of_fwnode_handle(dev->of_node);
+#endif
+	irq_domain_create_legacy(fwnode, nr_irqs, irq_base, 0,
 				 &irq_domain_simple_ops, NULL);
 
 	irq_end = irq_base + TWL4030_CORE_NR_IRQS;
-- 
2.25.1
Re: [PATCH v1] mfd: twl4030-irq: Fix unused variable warning when CONFIG_OF disabled
Posted by Thomas Gleixner 4 weeks ago
On Tue, Jun 17 2025 at 10:41, Haofeng Li wrote:
> -
> -	irq_domain_create_legacy(of_fwnode_handle(node), nr_irqs, irq_base, 0,
> +#ifdef CONFIG_OF
> +	fwnode = of_fwnode_handle(dev->of_node);
> +#endif

This #ifdeffery is horrible.

> +	irq_domain_create_legacy(fwnode, nr_irqs, irq_base, 0,

        irq_domain_create_legacy(dev_fwnode(dev), ....

Makes all of those problems go away.
Re: [PATCH v1] mfd: twl4030-irq: Fix unused variable warning when CONFIG_OF disabled
Posted by Haofeng Li 3 weeks, 6 days ago
>This #ifdeffery is horrible.

> +	irq_domain_create_legacy(fwnode, nr_irqs, irq_base, 0,

>        irq_domain_create_legacy(dev_fwnode(dev), ....

>Makes all of those problems go away.


Thank you very much for your valuable feedback. Your suggestion to use dev_fwnode(dev) to simplify the code and avoid unnecessary #ifdef conditionals is highly appreciated. This approach indeed makes the code cleaner and more maintainable.

I have noticed that this issue has already been addressed in the latest commit, and the changes have been implemented . Therefore, I am closing this submission.

Once again, thank you for your guidance and support. If you have any further suggestions or require additional input, please feel free to let me know. I look forward to continuing to learn from your insights in future developments.

Best regards,
	lihaofeng