public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Subject: Re: [patch 02/46] genirq/irqdesc: Switch to lock guards
Date: Fri, 14 Mar 2025 11:57:24 +0100	[thread overview]
Message-ID: <1e1ffb3a-3354-4c35-b73f-787da014f758@kernel.org> (raw)
In-Reply-To: <20250313155914.010145118@linutronix.de>

On 13. 03. 25, 16:59, Thomas Gleixner wrote:
> Replace all lock/unlock pairs with lock guards and simplify the code flow.
> 
> No functional change.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>   kernel/irq/irqdesc.c |  136 +++++++++++++++------------------------------------
>   1 file changed, 42 insertions(+), 94 deletions(-)
> 
> --- a/kernel/irq/irqdesc.c
> +++ b/kernel/irq/irqdesc.c
> @@ -266,104 +266,68 @@ static ssize_t per_cpu_count_show(struct
>   }
>   IRQ_ATTR_RO(per_cpu_count);
>   
> -static ssize_t chip_name_show(struct kobject *kobj,
> -			      struct kobj_attribute *attr, char *buf)
> +static ssize_t chip_name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>   {
>   	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> -	ssize_t ret = 0;
> -
> -	raw_spin_lock_irq(&desc->lock);
> -	if (desc->irq_data.chip && desc->irq_data.chip->name) {
> -		ret = scnprintf(buf, PAGE_SIZE, "%s\n",
> -				desc->irq_data.chip->name);
> -	}
> -	raw_spin_unlock_irq(&desc->lock);
>   
> -	return ret;
> +	guard(raw_spinlock_irq)(&desc->lock);
> +	if (desc->irq_data.chip && desc->irq_data.chip->name)
> +		return scnprintf(buf, PAGE_SIZE, "%s\n", desc->irq_data.chip->name);
> +	return 0;

FWIW I consider this ^^^ ...

>   }
>   IRQ_ATTR_RO(chip_name);
>   
> -static ssize_t hwirq_show(struct kobject *kobj,
> -			  struct kobj_attribute *attr, char *buf)
> +static ssize_t hwirq_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>   {
>   	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> -	ssize_t ret = 0;
> -
> -	raw_spin_lock_irq(&desc->lock);
> -	if (desc->irq_data.domain)
> -		ret = sprintf(buf, "%lu\n", desc->irq_data.hwirq);
> -	raw_spin_unlock_irq(&desc->lock);
>   
> -	return ret;
> +	guard(raw_spinlock_irq)(&desc->lock);
> +	return desc->irq_data.domain ? sprintf(buf, "%lu\n", desc->irq_data.hwirq) : 0;

... more readable than this ^^^. (Ie. I would preserve the 'if'. Even 
though here is only a simple condition.)

>   }
>   IRQ_ATTR_RO(hwirq);

> -static ssize_t name_show(struct kobject *kobj,
> -			 struct kobj_attribute *attr, char *buf)
> +static ssize_t name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>   {
>   	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> -	ssize_t ret = 0;
>   
> -	raw_spin_lock_irq(&desc->lock);
> -	if (desc->name)
> -		ret = scnprintf(buf, PAGE_SIZE, "%s\n", desc->name);
> -	raw_spin_unlock_irq(&desc->lock);
> -
> -	return ret;
> +	guard(raw_spinlock_irq)(&desc->lock);

You do guard() ...

> +	return desc->name ? scnprintf(buf, PAGE_SIZE, "%s\n", desc->name) : 0;
>   }
>   IRQ_ATTR_RO(name);
>   
> -static ssize_t actions_show(struct kobject *kobj,
> -			    struct kobj_attribute *attr, char *buf)
> +static ssize_t actions_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>   {
>   	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
>   	struct irqaction *action;
>   	ssize_t ret = 0;
>   	char *p = "";
>   
> -	raw_spin_lock_irq(&desc->lock);
> -	for_each_action_of_desc(desc, action) {
> -		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%s",
> -				 p, action->name);
> -		p = ",";
> +	scoped_guard (raw_spinlock_irq, &desc->lock) {

... but scoped_guard<space>(). Unlike in internals.h where you do 
scoped_guard(). Any reason for that?

> +		for_each_action_of_desc(desc, action) {
> +			ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%s", p, action->name);
> +			p = ",";
> +		}
>   	}
> -	raw_spin_unlock_irq(&desc->lock);
> -
> -	if (ret)
> -		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n");
>   
> -	return ret;
> +	return ret ? ret + scnprintf(buf + ret, PAGE_SIZE - ret, "\n") : 0;
>   }
>   IRQ_ATTR_RO(actions);
...
> @@ -573,12 +532,12 @@ static int alloc_descs(unsigned int star
>   	return -ENOMEM;
>   }
>   
> -static int irq_expand_nr_irqs(unsigned int nr)
> +static bool irq_expand_nr_irqs(unsigned int nr)
>   {
>   	if (nr > MAX_SPARSE_IRQS)
> -		return -ENOMEM;
> +		return false;
>   	nr_irqs = nr;
> -	return 0;
> +	return true;

This is sort of unrelated to $SUBJ ^^^. In any case:

> @@ -681,14 +638,13 @@ static inline int alloc_descs(unsigned i
>   
>   static int irq_expand_nr_irqs(unsigned int nr)

s/int/bool/ here too.

>   {
> -	return -ENOMEM;
> +	return false;
>   }

thanks,
-- 
js
suse labs

  reply	other threads:[~2025-03-14 10:57 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 15:59 [patch 00/46] genirq: Cleanups and conversion to lock guards Thomas Gleixner
2025-03-13 15:59 ` [patch 01/46] genirq: Provide conditional " Thomas Gleixner
2025-03-13 15:59 ` [patch 02/46] genirq/irqdesc: Switch to " Thomas Gleixner
2025-03-14 10:57   ` Jiri Slaby [this message]
2025-03-13 15:59 ` [patch 03/46] genirq/autoprobe: " Thomas Gleixner
2025-03-13 15:59 ` [patch 04/46] genirq/pm: " Thomas Gleixner
2025-03-13 15:59 ` [patch 05/46] genirq/resend: " Thomas Gleixner
2025-03-17  8:22   ` Shrikanth Hegde
2025-03-13 15:59 ` [patch 06/46] genirq/proc: " Thomas Gleixner
2025-03-13 15:59 ` [patch 07/46] genirq/spurious: Cleanup code Thomas Gleixner
2025-03-13 15:59 ` [patch 08/46] genirq/spurious: Switch to lock guards Thomas Gleixner
2025-03-13 15:59 ` [patch 09/46] genirq/cpuhotplug: Convert " Thomas Gleixner
2025-03-13 15:59 ` [patch 10/46] genirq/debugfs: " Thomas Gleixner
2025-03-13 16:00 ` [patch 11/46] genirq/chip: Prepare for code reduction Thomas Gleixner
2025-03-13 16:00 ` [patch 12/46] genirq/chip: Rework handle_nested_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 13/46] genirq/chip: Rework handle_simple_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 14/46] genirq/chip: Rework handle_untracked_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 15/46] genirq/chip: Rework handle_level_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 16/46] genirq/chip: Rework handle_eoi_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 17/46] genirq/chip: Rework handle_edge_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 18/46] genirq/chip: Rework handle_edge_eoi_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 19/46] genirq/chip: Rework handle_fasteoi_ack_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 20/46] genirq/chip: Rework handle_fasteoi_mask_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 21/46] genirq/chip: Use lock guards where applicable Thomas Gleixner
2025-03-13 16:00 ` [patch 22/46] genirq/chip: Rework irq_set_chip() Thomas Gleixner
2025-03-13 16:00 ` [patch 23/46] genirq/chip: Rework irq_set_irq_type() Thomas Gleixner
2025-03-13 16:00 ` [patch 24/46] genirq/chip: Rework irq_set_handler_data() Thomas Gleixner
2025-03-13 16:00 ` [patch 25/46] genirq/chip: Rework irq_set_msi_desc_off() Thomas Gleixner
2025-03-13 16:00 ` [patch 26/46] genirq/chip: Rework irq_set_chip_data() Thomas Gleixner
2025-03-13 16:00 ` [patch 27/46] genirq/chip: Rework irq_set_handler() variants Thomas Gleixner
2025-03-13 16:00 ` [patch 28/46] genirq/chip: Rework irq_modify_status() Thomas Gleixner
2025-03-13 16:00 ` [patch 29/46] genirq/manage: Cleanup kernel doc comments Thomas Gleixner
2025-03-13 16:00 ` [patch 30/46] genirq/manage: Convert to lock guards Thomas Gleixner
2025-03-13 16:00 ` [patch 31/46] genirq/manage: Rework irq_update_affinity_desc() Thomas Gleixner
2025-03-13 16:00 ` [patch 32/46] genirq/manage: Rework __irq_apply_affinity_hint() Thomas Gleixner
2025-03-13 16:00 ` [patch 33/46] genirq/manage: Rework irq_set_vcpu_affinity() Thomas Gleixner
2025-03-13 16:00 ` [patch 34/46] genirq/manage: Rework __disable_irq_nosync() Thomas Gleixner
2025-03-13 16:00 ` [patch 35/46] genirq/manage: Rework enable_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 36/46] genirq/manage: Rework irq_set_irq_wake() Thomas Gleixner
2025-03-13 16:00 ` [patch 37/46] genirq/manage: Rework can_request_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 38/46] genirq/manage: Rework irq_set_parent() Thomas Gleixner
2025-03-13 16:00 ` [patch 39/46] genirq/manage: Rework enable_percpu_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 40/46] genirq/manage: Rework irq_percpu_is_enabled() Thomas Gleixner
2025-03-13 16:00 ` [patch 41/46] genirq/manage: Rework disable_percpu_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 42/46] genirq/manage: Rework prepare_percpu_nmi() Thomas Gleixner
2025-03-13 16:00 ` [patch 43/46] genirq/manage: Rework teardown_percpu_nmi() Thomas Gleixner
2025-03-13 16:00 ` [patch 44/46] genirq/manage: Rework irq_get_irqchip_state() Thomas Gleixner
2025-03-13 16:01 ` [patch 45/46] genirq/manage: Rework irq_set_irqchip_state() Thomas Gleixner
2025-03-13 16:01 ` [patch 46/46] genirq: Remove irq_[get|put]_desc*() Thomas Gleixner
2025-03-14  9:04 ` [patch 00/46] genirq: Cleanups and conversion to lock guards Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1e1ffb3a-3354-4c35-b73f-787da014f758@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox