Re: [patch V2 32/45] genirq/manage: Rework irq_set_vcpu_affinity()

Jiri Slaby
2025-04-30T06:31:59Z

On 29. 04. 25, 8:55, Thomas Gleixner wrote:
> Use the new guards to get and lock the interrupt descriptor and tidy up the
> code.
>
> No functional change.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
>
> ---
> kernel/irq/manage.c | 40 +++++++++++++++++-----------------------
> 1 file changed, 17 insertions(+), 23 deletions(-)
>
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -627,32 +627,26 @@ int irq_setup_affinity(struct irq_desc *
> */
> int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info)
> {
> - unsigned long flags;
> - struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
> - struct irq_data *data;
> - struct irq_chip *chip;
> - int ret = -ENOSYS;
> + scoped_irqdesc_get_and_lock(irq, 0) {
> + struct irq_desc *desc = scoped_irqdesc;
> + struct irq_data *data;
> + struct irq_chip *chip;
> + int ret = -ENOSYS;
>
> - if (!desc)
> - return -EINVAL;
> + data = irq_desc_get_irq_data(desc);
> + do {
> + chip = irq_data_get_irq_chip(data);
> + if (chip && chip->irq_set_vcpu_affinity)
> + break;
>
> - data = irq_desc_get_irq_data(desc);
> - do {
> - chip = irq_data_get_irq_chip(data);
> - if (chip && chip->irq_set_vcpu_affinity)
> - break;
> -#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
> - data = data->parent_data;
> -#else
> - data = NULL;
> -#endif
> - } while (data);
> + data = irqd_get_parent_data(data);
> + } while (data);
>
> - if (data)
> - ret = chip->irq_set_vcpu_affinity(data, vcpu_info);
> - irq_put_desc_unlock(desc, flags);
> -
> - return ret;
> + if (data)
> + ret = chip->irq_set_vcpu_affinity(data, vcpu_info);
> + return ret;

What about simpler:
if (!data)
return -ENOSYS;
return chip->irq_set_vcpu_affinity(data, vcpu_info);

instead? No need for 'ret' at all then: it's always PITA to look up what
ret is set to initially.

--
js
suse labs