[PATCH] rtems: Simplify rtems_scheduler_ident()

Gedare Bloom gedare at rtems.org
Wed Jul 6 18:15:35 UTC 2022


ok

On Tue, Jul 5, 2022 at 2:19 AM Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
> Use early returns to simplify rtems_scheduler_ident().
> ---
>  cpukit/rtems/src/schedulerident.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/cpukit/rtems/src/schedulerident.c b/cpukit/rtems/src/schedulerident.c
> index e73d3d743a..60e7765ccd 100644
> --- a/cpukit/rtems/src/schedulerident.c
> +++ b/cpukit/rtems/src/schedulerident.c
> @@ -10,7 +10,7 @@
>   */
>
>  /*
> - * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
> + * Copyright (C) 2014, 2022 embedded brains GmbH
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -46,25 +46,20 @@ rtems_status_code rtems_scheduler_ident(
>    rtems_id   *id
>  )
>  {
> -  rtems_status_code sc;
> +  size_t i;
>
> -  if ( id != NULL ) {
> -    size_t n = _Scheduler_Count;
> -    size_t i;
> -
> -    sc = RTEMS_INVALID_NAME;
> +  if ( id == NULL ) {
> +    return RTEMS_INVALID_ADDRESS;
> +  }
>
> -    for ( i = 0 ; i < n && sc == RTEMS_INVALID_NAME ; ++i ) {
> -      const Scheduler_Control *scheduler = &_Scheduler_Table[ i ];
> +  for ( i = 0; i < _Scheduler_Count; ++i ) {
> +    const Scheduler_Control *scheduler = &_Scheduler_Table[ i ];
>
> -      if ( scheduler->name == name ) {
> -        *id = _Scheduler_Build_id( i );
> -        sc = RTEMS_SUCCESSFUL;
> -      }
> +    if ( scheduler->name == name ) {
> +      *id = _Scheduler_Build_id( i );
> +      return RTEMS_SUCCESSFUL;
>      }
> -  } else {
> -    sc = RTEMS_INVALID_ADDRESS;
>    }
>
> -  return sc;
> +  return RTEMS_INVALID_NAME;
>  }
> --
> 2.35.3
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list