[PATCH 1/2] config_odev*: Use XNF alloc functions

Peter Hutterer peter.hutterer at who-t.net
Tue Mar 11 18:13:16 PDT 2014


On Tue, Mar 11, 2014 at 12:01:22PM +0100, Hans de Goede wrote:
> config_odev* functions are called in code-paths were we already use
> XNF* functions in other places, so which are not oom safe already.
> 
> Besides that oom is something which should simply never happen, so aborting
> when it does is as good a response as any other.
> 
> While switching to XNF functions also fixup an unchecked strdup case.
> 
> Note the function prototypes are kept unchanged, as they are part of the
> server ABI.
> 
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
for both

Cheers,
   Peter

> ---
>  config/config.c                     | 18 +++---------------
>  hw/xfree86/common/xf86platformBus.h |  5 +++--
>  include/hotplug.h                   |  3 +++
>  3 files changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/config/config.c b/config/config.c
> index 46f2532..def7f16 100644
> --- a/config/config.c
> +++ b/config/config.c
> @@ -132,10 +132,7 @@ config_odev_allocate_attribute_list(void)
>  {
>      struct OdevAttributes *attriblist;
>  
> -    attriblist = malloc(sizeof(struct OdevAttributes));
> -    if (!attriblist)
> -        return NULL;
> -
> +    attriblist = XNFalloc(sizeof(struct OdevAttributes));
>      xorg_list_init(&attriblist->list);
>      return attriblist;
>  }
> @@ -168,10 +165,7 @@ config_odev_find_or_add_attribute(struct OdevAttributes *attribs, int attrib)
>      if (oa)
>          return oa;
>  
> -    oa = calloc(1, sizeof(struct OdevAttribute));
> -    if (!oa)
> -        return oa;
> -
> +    oa = XNFcalloc(sizeof(struct OdevAttribute));
>      oa->attrib_id = attrib;
>      xorg_list_append(&oa->member, &attribs->list);
>  
> @@ -185,11 +179,8 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
>      struct OdevAttribute *oa;
>  
>      oa = config_odev_find_or_add_attribute(attribs, attrib);
> -    if (!oa)
> -        return FALSE;
> -
>      free(oa->attrib_name);
> -    oa->attrib_name = strdup(attrib_name);
> +    oa->attrib_name = XNFstrdup(attrib_name);
>      oa->attrib_type = ODEV_ATTRIB_STRING;
>      return TRUE;
>  }
> @@ -201,9 +192,6 @@ config_odev_add_int_attribute(struct OdevAttributes *attribs, int attrib,
>      struct OdevAttribute *oa;
>  
>      oa = config_odev_find_or_add_attribute(attribs, attrib);
> -    if (!oa)
> -        return FALSE;
> -
>      oa->attrib_value = attrib_value;
>      oa->attrib_type = ODEV_ATTRIB_INT;
>      return TRUE;
> diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h
> index 78b5a5b..5dee4e0 100644
> --- a/hw/xfree86/common/xf86platformBus.h
> +++ b/hw/xfree86/common/xf86platformBus.h
> @@ -54,11 +54,12 @@ xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned);
>  extern int
>  xf86_remove_platform_device(int dev_index);
>  extern Bool
> +xf86_get_platform_device_unowned(int index);
> +/* Note starting with xserver 1.16 these 2 functions never fail */
> +extern Bool
>  xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_str);
>  extern Bool
>  xf86_add_platform_device_int_attrib(int index, int attrib_id, int attrib_value);
> -extern Bool
> -xf86_get_platform_device_unowned(int index);
>  
>  extern int
>  xf86platformAddDevice(int index);
> diff --git a/include/hotplug.h b/include/hotplug.h
> index 1d9364e..cefc164 100644
> --- a/include/hotplug.h
> +++ b/include/hotplug.h
> @@ -48,12 +48,14 @@ struct OdevAttributes {
>      struct xorg_list list;
>  };
>  
> +/* Note starting with xserver 1.16 this function never fails */
>  struct OdevAttributes *
>  config_odev_allocate_attribute_list(void);
>  
>  void
>  config_odev_free_attribute_list(struct OdevAttributes *attribs);
>  
> +/* Note starting with xserver 1.16 this function never fails */
>  Bool
>  config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
>                            const char *attrib_name);
> @@ -61,6 +63,7 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
>  char *
>  config_odev_get_attribute(struct OdevAttributes *attribs, int attrib_id);
>  
> +/* Note starting with xserver 1.16 this function never fails */
>  Bool
>  config_odev_add_int_attribute(struct OdevAttributes *attribs, int attrib,
>                                int attrib_value);
> -- 
> 1.9.0
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list