All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: Rasmus Villemoes <ravi@prevas.dk>, u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH 1/3] cyclic: make cyclic_unregister() idempotent
Date: Thu, 8 May 2025 09:26:00 +0200	[thread overview]
Message-ID: <490d79b4-9b06-439a-acb2-e321354e70dd@denx.de> (raw)
In-Reply-To: <20250507105821.484442-2-ravi@prevas.dk>

On 07.05.25 12:58, Rasmus Villemoes wrote:
> Make cyclic_unregister() safe to call with an already unregistered, or
> possibly never registered, struct cyclic_info. This is similar to how
> the various timer APIs in the linux kernel work (they all allow
> calling delete/cancel/... on an inactive timer object).
> 
> This means callers don't have to separately keep track of whether
> their cyclic callback is registered or not, and avoids them trying to
> peek into the struct cyclic_info for that information - which leads to
> somewhat ugly code as it would have to be guarded by ifdef
> CONFIG_CYCLIC.
> 
> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   common/cyclic.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/common/cyclic.c b/common/cyclic.c
> index b695f092f52..75662d9f613 100644
> --- a/common/cyclic.c
> +++ b/common/cyclic.c
> @@ -28,6 +28,18 @@ struct hlist_head *cyclic_get_list(void)
>   	return (struct hlist_head *)&gd->cyclic_list;
>   }
>   
> +static bool cyclic_is_registered(const struct cyclic_info *cyclic)
> +{
> +	const struct cyclic_info *c;
> +
> +	hlist_for_each_entry(c, cyclic_get_list(), list) {
> +		if (c == cyclic)
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>   void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
>   		     uint64_t delay_us, const char *name)
>   {
> @@ -43,6 +55,9 @@ void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
>   
>   void cyclic_unregister(struct cyclic_info *cyclic)
>   {
> +	if (!cyclic_is_registered(cyclic))
> +		return;
> +
>   	hlist_del(&cyclic->list);
>   }
>   

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de


  reply	other threads:[~2025-05-08  7:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 10:58 [PATCH 0/3] make cyclic_(un)register idempotent Rasmus Villemoes
2025-05-07 10:58 ` [PATCH 1/3] cyclic: make cyclic_unregister() idempotent Rasmus Villemoes
2025-05-08  7:26   ` Stefan Roese [this message]
2025-05-07 10:58 ` [PATCH 2/3] cyclic: make cyclic_register safe to call on already-registered info Rasmus Villemoes
2025-05-08  7:27   ` Stefan Roese
2025-05-07 10:58 ` [PATCH 3/3] cyclic: document new guarantees for cyclic_(un)register Rasmus Villemoes
2025-05-08  7:27   ` Stefan Roese
2025-05-16 16:41 ` [PATCH 0/3] make cyclic_(un)register idempotent Stefan Roese

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=490d79b4-9b06-439a-acb2-e321354e70dd@denx.de \
    --to=sr@denx.de \
    --cc=ravi@prevas.dk \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.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 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.