All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy
  2025-04-16 11:40 [PATCH v1 0/2] genirq/irqdesc: Make " Andy Shevchenko
@ 2025-04-16 11:40 ` Andy Shevchenko
  2025-04-16 11:52   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ 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] 4+ 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 " Andy Shevchenko
@ 2025-04-16 11:52   ` Andy Shevchenko
  2025-04-16 11:53     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ 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] 4+ 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; 4+ 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] 4+ messages in thread

* Re: [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy
@ 2025-04-17 15:36 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-04-17 15:36 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Julia Lawall

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250416114122.2191820-3-andriy.shevchenko@linux.intel.com>
References: <20250416114122.2191820-3-andriy.shevchenko@linux.intel.com>
TO: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
TO: Thomas Gleixner <tglx@linutronix.de>
TO: linux-kernel@vger.kernel.org
CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Hi Andy,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tip/irq/core]
[also build test WARNING on linus/master v6.15-rc2 next-20250417]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/genirq-irqdesc-Decrease-indentation-level-in-__irq_get_desc_lock/20250416-194250
base:   tip/irq/core
patch link:    https://lore.kernel.org/r/20250416114122.2191820-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy
:::::: branch date: 28 hours ago
:::::: commit date: 28 hours ago
config: powerpc-randconfig-r062-20250417 (https://download.01.org/0day-ci/archive/20250417/202504172346.KbnCGLce-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Julia Lawall <julia.lawall@inria.fr>
| Closes: https://lore.kernel.org/r/202504172346.KbnCGLce-lkp@intel.com/

cocci warnings: (new ones prefixed by >>)
>> kernel/irq/irqdesc.c:931:18-22: ERROR: desc is NULL but dereferenced.

vim +931 kernel/irq/irqdesc.c

a98d24b71b6e22 Thomas Gleixner 2010-09-30  902  
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  903  struct irq_desc *
31d9d9b6d83030 Marc Zyngier    2011-09-23  904  __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
31d9d9b6d83030 Marc Zyngier    2011-09-23  905  		    unsigned int check)
752346dda9011a Andy Shevchenko 2025-04-16  906  	__acquires(&desc->lock)
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  907  {
cd49c072791316 Andy Shevchenko 2025-04-16  908  	struct irq_desc *desc;
cd49c072791316 Andy Shevchenko 2025-04-16  909  
cd49c072791316 Andy Shevchenko 2025-04-16  910  	desc = irq_to_desc(irq);
cd49c072791316 Andy Shevchenko 2025-04-16  911  	if (!desc)
752346dda9011a Andy Shevchenko 2025-04-16  912  		goto lock;
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  913  
31d9d9b6d83030 Marc Zyngier    2011-09-23  914  	if (check & _IRQ_DESC_CHECK) {
31d9d9b6d83030 Marc Zyngier    2011-09-23  915  		if ((check & _IRQ_DESC_PERCPU) &&
31d9d9b6d83030 Marc Zyngier    2011-09-23  916  		    !irq_settings_is_per_cpu_devid(desc))
752346dda9011a Andy Shevchenko 2025-04-16  917  			goto lock;
31d9d9b6d83030 Marc Zyngier    2011-09-23  918  
31d9d9b6d83030 Marc Zyngier    2011-09-23  919  		if (!(check & _IRQ_DESC_PERCPU) &&
31d9d9b6d83030 Marc Zyngier    2011-09-23  920  		    irq_settings_is_per_cpu_devid(desc))
752346dda9011a Andy Shevchenko 2025-04-16  921  			goto lock;
31d9d9b6d83030 Marc Zyngier    2011-09-23  922  	}
31d9d9b6d83030 Marc Zyngier    2011-09-23  923  
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  924  	if (bus)
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  925  		chip_bus_lock(desc);
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  926  	raw_spin_lock_irqsave(&desc->lock, *flags);
cd49c072791316 Andy Shevchenko 2025-04-16  927  
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  928  	return desc;
752346dda9011a Andy Shevchenko 2025-04-16  929  
752346dda9011a Andy Shevchenko 2025-04-16  930  lock:
752346dda9011a Andy Shevchenko 2025-04-16 @931  	__acquire(&desc->lock);
752346dda9011a Andy Shevchenko 2025-04-16  932  	return NULL;
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  933  }
d5eb4ad2dfb2df Thomas Gleixner 2011-02-12  934  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2025-04-17 15:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 15:36 [PATCH v1 2/2] genirq/irqdesc: Balance locking to make sparse happy kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-04-16 11:40 [PATCH v1 0/2] genirq/irqdesc: Make " Andy Shevchenko
2025-04-16 11:40 ` [PATCH v1 2/2] genirq/irqdesc: Balance locking to make " Andy Shevchenko
2025-04-16 11:52   ` Andy Shevchenko
2025-04-16 11:53     ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.