diff mbox series

[1/3] cyclic: stop strdup'ing name in cyclic_register()

Message ID 20240509004714.1394547-2-rasmus.villemoes@prevas.dk
State Superseded
Delegated to: Stefan Roese
Headers show
Series cyclic/watchdog patches | expand

Commit Message

Rasmus Villemoes May 9, 2024, 12:47 a.m. UTC
We are not checking the return value of strdup(), nor
freeing the string in cyclic_unregister().

However, all current users either pass a string literal or the
dev->name of the client device. So in all cases the name string will
live at least as long as the cyclic_info is registered, so just make
that a requirement.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 common/cyclic.c  | 2 +-
 include/cyclic.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Stefan Roese May 13, 2024, 6:03 a.m. UTC | #1
On 5/9/24 02:47, Rasmus Villemoes wrote:
> We are not checking the return value of strdup(), nor
> freeing the string in cyclic_unregister().
> 
> However, all current users either pass a string literal or the
> dev->name of the client device. So in all cases the name string will
> live at least as long as the cyclic_info is registered, so just make
> that a requirement.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

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

Thanks,
Stefan

> ---
>   common/cyclic.c  | 2 +-
>   include/cyclic.h | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/common/cyclic.c b/common/cyclic.c
> index a49bfc88f5c..c62e7fa7d19 100644
> --- a/common/cyclic.c
> +++ b/common/cyclic.c
> @@ -40,7 +40,7 @@ struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us,
>   	/* Store values in struct */
>   	cyclic->func = func;
>   	cyclic->ctx = ctx;
> -	cyclic->name = strdup(name);
> +	cyclic->name = name;
>   	cyclic->delay_us = delay_us;
>   	cyclic->start_time_us = timer_get_us();
>   	hlist_add_head(&cyclic->list, cyclic_get_list());
> diff --git a/include/cyclic.h b/include/cyclic.h
> index 44ad3cb6b80..38946216fb8 100644
> --- a/include/cyclic.h
> +++ b/include/cyclic.h
> @@ -31,7 +31,7 @@
>   struct cyclic_info {
>   	void (*func)(void *ctx);
>   	void *ctx;
> -	char *name;
> +	const char *name;
>   	uint64_t delay_us;
>   	uint64_t start_time_us;
>   	uint64_t cpu_time_us;

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/common/cyclic.c b/common/cyclic.c
index a49bfc88f5c..c62e7fa7d19 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -40,7 +40,7 @@  struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us,
 	/* Store values in struct */
 	cyclic->func = func;
 	cyclic->ctx = ctx;
-	cyclic->name = strdup(name);
+	cyclic->name = name;
 	cyclic->delay_us = delay_us;
 	cyclic->start_time_us = timer_get_us();
 	hlist_add_head(&cyclic->list, cyclic_get_list());
diff --git a/include/cyclic.h b/include/cyclic.h
index 44ad3cb6b80..38946216fb8 100644
--- a/include/cyclic.h
+++ b/include/cyclic.h
@@ -31,7 +31,7 @@ 
 struct cyclic_info {
 	void (*func)(void *ctx);
 	void *ctx;
-	char *name;
+	const char *name;
 	uint64_t delay_us;
 	uint64_t start_time_us;
 	uint64_t cpu_time_us;