[PATCH v4 15/15] lib/igt_device_scan: reuse igt hash

Badrappan, Jeevaka jeevaka.badrappan at intel.com
Thu May 15 18:23:33 UTC 2025


>  #include <libudev.h>
>  #ifdef __linux__
>  #include <linux/limits.h>
> @@ -224,8 +224,8 @@ struct igt_device {
>        /* Point to vendor spec if can be found */
>
>        /* Properties / sysattrs rewriten from udev lists */
> -     GHashTable *props_ht;
> -     GHashTable *attrs_ht;
> +     struct igt_map *props_map;
> +     struct igt_map *attrs_map;
>
>        /* Most usable variables from udev device */
>        char *subsystem;
> @@ -464,6 +464,11 @@ static bool is_on_blacklist(const char *what)
>
>  }
>
> +static int key_equals(const void *key1, const void *key2)
> +{
> +     return strcmp((char *)key1, (char *)key2) == 0;
> +}
> +
>  static struct igt_device *igt_device_new(void)
>  {
>        struct igt_device *dev;
> @@ -472,14 +477,14 @@ static struct igt_device *igt_device_new(void)
>        if (!dev)
>                return NULL;
>
> -     dev->attrs_ht = g_hash_table_new_full(g_str_hash, g_str_equal,
> -                                           free, free);
> -     dev->props_ht = g_hash_table_new_full(g_str_hash, g_str_equal,
> -                                           free, free);
> +     dev->attrs_map = igt_map_create(igt_map_hash_32, key_equals);
> +     dev->props_map = igt_map_create(igt_map_hash_32, key_equals);
>
> -     if (dev->attrs_ht && dev->props_ht)
> +     if (dev->attrs_map && dev->props_map)
>                return dev;
>
> +     igt_map_destroy(dev->attrs_map, NULL);
> +     igt_map_destroy(dev->props_map, NULL);

> What for are you freeing the map here?
map and also device is freed if creation of attrs_map  or props_map fails.

Thanks and Regards,
Jeevaka
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/igt-dev/attachments/20250515/353bcdaf/attachment.htm>


More information about the igt-dev mailing list