public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] genirq/irqdesc: Make sparse happy
@ 2025-04-16 11:40 Andy Shevchenko
  2025-04-16 11:40 ` [PATCH v1 1/2] genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock() Andy Shevchenko
  2025-04-16 11:40 ` [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy Andy Shevchenko
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-04-16 11:40 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel; +Cc: Andy Shevchenko

There is a conditional locking that sparse is not happy about.
Fix it by the respective code refactoring and using available
annotations.

Andy Shevchenko (2):
  genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock()
  genirq/irqdesc: Balance locking to make sparse happy

 kernel/irq/irqdesc.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1 1/2] genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock()
  2025-04-16 11:40 [PATCH v1 0/2] genirq/irqdesc: Make sparse happy Andy Shevchenko
@ 2025-04-16 11:40 ` Andy Shevchenko
  2025-05-05 13:36   ` [tip: irq/core] " tip-bot2 for Andy Shevchenko
  2025-04-16 11:40 ` [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2025-04-16 11:40 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel; +Cc: Andy Shevchenko

There is a conditional that covers all the code for the entire function.
Invert it and decrease indentation level. This also helps for further
changes to be clearer and tidier.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/irq/irqdesc.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 4bcc6ff81e39..0afc2b0b03be 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -900,23 +900,26 @@ struct irq_desc *
 __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
 		    unsigned int check)
 {
-	struct irq_desc *desc = irq_to_desc(irq);
+	struct irq_desc *desc;
 
-	if (desc) {
-		if (check & _IRQ_DESC_CHECK) {
-			if ((check & _IRQ_DESC_PERCPU) &&
-			    !irq_settings_is_per_cpu_devid(desc))
-				return NULL;
+	desc = irq_to_desc(irq);
+	if (!desc)
+		return NULL;
 
-			if (!(check & _IRQ_DESC_PERCPU) &&
-			    irq_settings_is_per_cpu_devid(desc))
-				return NULL;
-		}
+	if (check & _IRQ_DESC_CHECK) {
+		if ((check & _IRQ_DESC_PERCPU) &&
+		    !irq_settings_is_per_cpu_devid(desc))
+			return NULL;
 
-		if (bus)
-			chip_bus_lock(desc);
-		raw_spin_lock_irqsave(&desc->lock, *flags);
+		if (!(check & _IRQ_DESC_PERCPU) &&
+		    irq_settings_is_per_cpu_devid(desc))
+			return NULL;
 	}
+
+	if (bus)
+		chip_bus_lock(desc);
+	raw_spin_lock_irqsave(&desc->lock, *flags);
+
 	return desc;
 }
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy
  2025-04-16 11:40 [PATCH v1 0/2] genirq/irqdesc: Make sparse happy Andy Shevchenko
  2025-04-16 11:40 ` [PATCH v1 1/2] genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock() Andy Shevchenko
@ 2025-04-16 11:40 ` Andy Shevchenko
  2025-04-16 11:52   ` Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2025-04-16 11:40 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel; +Cc: Andy Shevchenko

Sparse is not happy right now about conditional locking and
complains:

  irqdesc.c:899:17: warning: context imbalance in '__irq_get_desc_lock' - wrong count at exit

Refactor the code and use __acquire() to make it happy.
Annotate the function that it acquires the lock in the
similar way how __irq_put_desc_unlock() is marked.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/irq/irqdesc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 0afc2b0b03be..cecff0cb13eb 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -899,21 +899,22 @@ unsigned int irq_get_next_irq(unsigned int offset)
 struct irq_desc *
 __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
 		    unsigned int check)
+	__acquires(&desc->lock)
 {
 	struct irq_desc *desc;
 
 	desc = irq_to_desc(irq);
 	if (!desc)
-		return NULL;
+		goto lock;
 
 	if (check & _IRQ_DESC_CHECK) {
 		if ((check & _IRQ_DESC_PERCPU) &&
 		    !irq_settings_is_per_cpu_devid(desc))
-			return NULL;
+			goto lock;
 
 		if (!(check & _IRQ_DESC_PERCPU) &&
 		    irq_settings_is_per_cpu_devid(desc))
-			return NULL;
+			goto lock;
 	}
 
 	if (bus)
@@ -921,6 +922,10 @@ __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
 	raw_spin_lock_irqsave(&desc->lock, *flags);
 
 	return desc;
+
+lock:
+	__acquire(&desc->lock);
+	return NULL;
 }
 
 void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus)
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy
  2025-04-16 11:40 ` [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy Andy Shevchenko
@ 2025-04-16 11:52   ` Andy Shevchenko
  2025-04-16 11:53     ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2025-04-16 11:52 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel

On Wed, Apr 16, 2025 at 02:40:34PM +0300, Andy Shevchenko wrote:
> Sparse is not happy right now about conditional locking and
> complains:
> 
>   irqdesc.c:899:17: warning: context imbalance in '__irq_get_desc_lock' - wrong count at exit
> 
> Refactor the code and use __acquire() to make it happy.
> Annotate the function that it acquires the lock in the
> similar way how __irq_put_desc_unlock() is marked.

Oh, scratch this, it basically will diminish the idea for the users.

…

>  __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
>  		    unsigned int check)
> +	__acquires(&desc->lock)

This is correct annotation, but it doesn't help alone.
We need __cond_acquires() to be supported by sparse...

...

It can be still fixed by using macros, but this is not probably what we want.
For the reference: d795e38df4b7 ("iio: core: Rework claim and release of direct
mode to work with sparse.")


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy
  2025-04-16 11:52   ` Andy Shevchenko
@ 2025-04-16 11:53     ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-04-16 11:53 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel

On Wed, Apr 16, 2025 at 02:52:18PM +0300, Andy Shevchenko wrote:
> On Wed, Apr 16, 2025 at 02:40:34PM +0300, Andy Shevchenko wrote:
> > Sparse is not happy right now about conditional locking and
> > complains:
> > 
> >   irqdesc.c:899:17: warning: context imbalance in '__irq_get_desc_lock' - wrong count at exit
> > 
> > Refactor the code and use __acquire() to make it happy.
> > Annotate the function that it acquires the lock in the
> > similar way how __irq_put_desc_unlock() is marked.
> 
> Oh, scratch this, it basically will diminish the idea for the users.

That said, the first patch is okay, in case you want it.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip: irq/core] genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock()
  2025-04-16 11:40 ` [PATCH v1 1/2] genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock() Andy Shevchenko
@ 2025-05-05 13:36   ` tip-bot2 for Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Andy Shevchenko @ 2025-05-05 13:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Andy Shevchenko, Thomas Gleixner, x86, linux-kernel, maz

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     e5032ead8599affac5d8b816ea3c9d63ebeec6b4
Gitweb:        https://git.kernel.org/tip/e5032ead8599affac5d8b816ea3c9d63ebeec6b4
Author:        Andy Shevchenko <andriy.shevchenko@linux.intel.com>
AuthorDate:    Wed, 16 Apr 2025 14:40:33 +03:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 05 May 2025 15:24:06 +02:00

genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock()

There is a conditional that covers all the code for the entire function.
Invert it and decrease indentation level. This also helps for further
changes to be clearer and tidier.

[ tglx: Removed line breaks ]

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250416114122.2191820-2-andriy.shevchenko@linux.intel.com
---
 kernel/irq/irqdesc.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 4bcc6ff..5b3aee2 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -896,27 +896,27 @@ unsigned int irq_get_next_irq(unsigned int offset)
 	return irq_find_at_or_after(offset);
 }
 
-struct irq_desc *
-__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
-		    unsigned int check)
+struct irq_desc *__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
+				     unsigned int check)
 {
-	struct irq_desc *desc = irq_to_desc(irq);
+	struct irq_desc *desc;
 
-	if (desc) {
-		if (check & _IRQ_DESC_CHECK) {
-			if ((check & _IRQ_DESC_PERCPU) &&
-			    !irq_settings_is_per_cpu_devid(desc))
-				return NULL;
-
-			if (!(check & _IRQ_DESC_PERCPU) &&
-			    irq_settings_is_per_cpu_devid(desc))
-				return NULL;
-		}
+	desc = irq_to_desc(irq);
+	if (!desc)
+		return NULL;
+
+	if (check & _IRQ_DESC_CHECK) {
+		if ((check & _IRQ_DESC_PERCPU) && !irq_settings_is_per_cpu_devid(desc))
+			return NULL;
 
-		if (bus)
-			chip_bus_lock(desc);
-		raw_spin_lock_irqsave(&desc->lock, *flags);
+		if (!(check & _IRQ_DESC_PERCPU) && irq_settings_is_per_cpu_devid(desc))
+			return NULL;
 	}
+
+	if (bus)
+		chip_bus_lock(desc);
+	raw_spin_lock_irqsave(&desc->lock, *flags);
+
 	return desc;
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-05 13:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 11:40 [PATCH v1 0/2] genirq/irqdesc: Make sparse happy Andy Shevchenko
2025-04-16 11:40 ` [PATCH v1 1/2] genirq/irqdesc: Decrease indentation level in __irq_get_desc_lock() Andy Shevchenko
2025-05-05 13:36   ` [tip: irq/core] " tip-bot2 for Andy Shevchenko
2025-04-16 11:40 ` [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy Andy Shevchenko
2025-04-16 11:52   ` Andy Shevchenko
2025-04-16 11:53     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox