Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

serial: 8250: extract serial_get_or_create_irq_info()

This find-or-create-irq part of the serial_link_irq_chain()'s code is
logically bounded and self-standing. For easier-to-follow code flow,
extract the code to a separate function:
serial_get_or_create_irq_info().

This allows for an easier found-an-irq handling -- simple jump to the
'unlock' label and return. That results in one less 'if' levels.

Note when using guard()s in the upcoming patchset, the label can dropped
altogether.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20250611100319.186924-28-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
99fc860f 465fd2fc

+26 -11
+26 -11
drivers/tty/serial/8250/8250_core.c
··· 129 129 } 130 130 } 131 131 132 - static int serial_link_irq_chain(struct uart_8250_port *up) 132 + /* 133 + * Either: 134 + * - find the corresponding info in the hashtable and return it, or 135 + * - allocate a new one, add it to the hashtable and return it. 136 + */ 137 + static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_port *up) 133 138 { 134 139 struct hlist_head *h; 135 140 struct irq_info *i; 136 - int ret; 137 141 138 142 mutex_lock(&hash_mutex); 139 143 ··· 145 141 146 142 hlist_for_each_entry(i, h, node) 147 143 if (i->irq == up->port.irq) 148 - break; 144 + goto unlock; 149 145 146 + i = kzalloc(sizeof(*i), GFP_KERNEL); 150 147 if (i == NULL) { 151 - i = kzalloc(sizeof(struct irq_info), GFP_KERNEL); 152 - if (i == NULL) { 153 - mutex_unlock(&hash_mutex); 154 - return -ENOMEM; 155 - } 156 - spin_lock_init(&i->lock); 157 - i->irq = up->port.irq; 158 - hlist_add_head(&i->node, h); 148 + i = ERR_PTR(-ENOMEM); 149 + goto unlock; 159 150 } 151 + spin_lock_init(&i->lock); 152 + i->irq = up->port.irq; 153 + hlist_add_head(&i->node, h); 154 + unlock: 160 155 mutex_unlock(&hash_mutex); 156 + 157 + return i; 158 + } 159 + 160 + static int serial_link_irq_chain(struct uart_8250_port *up) 161 + { 162 + struct irq_info *i; 163 + int ret; 164 + 165 + i = serial_get_or_create_irq_info(up); 166 + if (IS_ERR(i)) 167 + return PTR_ERR(i); 161 168 162 169 spin_lock_irq(&i->lock); 163 170