[igt-dev] [PATCH i-g-t 3/7] igt_list: Add the igt_list_empty_or_null helper

Knop, Ryszard ryszard.knop at intel.com
Thu Jun 30 13:17:16 UTC 2022


On Wed, 2022-06-29 at 18:00 +0200, Mauro Carvalho Chehab wrote:
> On Tue, 28 Jun 2022 11:44:31 +0200
> Ryszard Knop <ryszard.knop at intel.com> wrote:
> 
> > Checks if the list is empty or uninitialized.
> 
> Looking at patch 4/7, I understand why you want this function:
> 
>         static bool add_env_var(struct igt_list_head *env_vars, char
> *env_kv) {
>                 char *current_env_value, *kv_split;
>                 struct environment_variable *var = NULL;
> ...
>                 if (igt_list_empty_or_null(env_vars))
>                         IGT_INIT_LIST_HEAD(env_vars);
> 
> Yet, I don't like the idea of conditionally initializing env_vars.
> 
> IMO, the best would be to always call IGT_INIT_LIST_HEAD(env_vars),
> dropping the conditional check at add_env_var().

Makes sense, will do in v2.

Thanks, Ryszard

> 
> Regards,
> Mauro
> 
> > 
> > Signed-off-by: Ryszard Knop <ryszard.knop at intel.com>
> > ---
> >  lib/igt_list.c | 5 +++++
> >  lib/igt_list.h | 1 +
> >  2 files changed, 6 insertions(+)
> > 
> > diff --git a/lib/igt_list.c b/lib/igt_list.c
> > index 37ae139c..dc94fad8 100644
> > --- a/lib/igt_list.c
> > +++ b/lib/igt_list.c
> > @@ -81,3 +81,8 @@ bool igt_list_empty(const struct igt_list_head
> > *head)
> >  {
> >         return head->next == head;
> >  }
> > +
> > +bool igt_list_empty_or_null(const struct igt_list_head *head)
> > +{
> > +       return head->next == NULL || head->prev == NULL ||
> > igt_list_empty(head);
> > +}
> > diff --git a/lib/igt_list.h b/lib/igt_list.h
> > index be63fd80..4efb7a22 100644
> > --- a/lib/igt_list.h
> > +++ b/lib/igt_list.h
> > @@ -80,6 +80,7 @@ void igt_list_move(struct igt_list_head *elem,
> > struct igt_list_head *list);
> >  void igt_list_move_tail(struct igt_list_head *elem, struct
> > igt_list_head *list);
> >  int igt_list_length(const struct igt_list_head *head);
> >  bool igt_list_empty(const struct igt_list_head *head);
> > +bool igt_list_empty_or_null(const struct igt_list_head *head);
> >  
> >  #define igt_container_of(ptr, sample,
> > member)                          \
> >         (__typeof__(sample))((char *)(ptr) -
> >                             \



More information about the igt-dev mailing list