[PATCH] cleanup: Move NULL check into conditional guard unlock expressions
From: Dmitry Ilvokhin
Date: Tue May 12 2026 - 09:59:04 EST
irqdesc_lock and tty_port_tty use __DEFINE_UNLOCK_GUARD() directly
with custom constructors that can set .lock to NULL. Move the NULL
check from the generic __DEFINE_UNLOCK_GUARD() destructor into their
_unlock expressions, making the NULL handling explicit at the call
site.
Signed-off-by: Dmitry Ilvokhin <d@xxxxxxxxxxxx>
---
include/linux/tty_port.h | 2 +-
kernel/irq/internals.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
index d2a7882c0b58..cbbff6aabdad 100644
--- a/include/linux/tty_port.h
+++ b/include/linux/tty_port.h
@@ -286,7 +286,7 @@ static inline void tty_port_tty_vhangup(struct tty_port *port)
#ifdef CONFIG_TTY
void tty_kref_put(struct tty_struct *tty);
__DEFINE_CLASS_IS_CONDITIONAL(tty_port_tty, true);
-__DEFINE_UNLOCK_GUARD(tty_port_tty, struct tty_struct, tty_kref_put(_T->lock));
+__DEFINE_UNLOCK_GUARD(tty_port_tty, struct tty_struct, if (_T->lock) tty_kref_put(_T->lock));
static inline class_tty_port_tty_t class_tty_port_tty_constructor(struct tty_port *tport)
{
class_tty_port_tty_t _t = {
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
index 9412e57056f5..347cb333b9fe 100644
--- a/kernel/irq/internals.h
+++ b/kernel/irq/internals.h
@@ -171,7 +171,7 @@ void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus)
__DEFINE_CLASS_IS_CONDITIONAL(irqdesc_lock, true);
__DEFINE_UNLOCK_GUARD(irqdesc_lock, struct irq_desc,
- __irq_put_desc_unlock(_T->lock, _T->flags, _T->bus),
+ if (_T->lock) __irq_put_desc_unlock(_T->lock, _T->flags, _T->bus),
unsigned long flags; bool bus);
static inline class_irqdesc_lock_t class_irqdesc_lock_constructor(unsigned int irq, bool bus,
--
2.53.0-Meta