[Mesa-dev] [PATCH 04/11] Loader: Add gpu selection code with DRI_PRIME.

Emil Velikov emil.l.velikov at gmail.com
Wed May 28 05:33:54 PDT 2014


On 28/05/14 01:55, Axel Davy wrote:
> Signed-off-by: Axel Davy <axel.davy at ens.fr>
> ---
>  src/loader/loader.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/loader/loader.h |   7 ++
>  2 files changed, 195 insertions(+)
> 
> diff --git a/src/loader/loader.c b/src/loader/loader.c
> index 666d015..3d504f7 100644
> --- a/src/loader/loader.c
> +++ b/src/loader/loader.c
[snip]
> +int loader_get_user_preferred_fd(int default_fd, int *different_device)
> +{
> +   struct udev *udev;
> +   const char *dri_prime = getenv("DRI_PRIME");
> +   char *prime = NULL;
> +   int is_different_device = 0, fd = default_fd;
> +   char *default_device_id_path_tag;
> +   char *device_name = NULL;
> +   char another_tag = 0;
> +   UDEV_SYMBOL(struct udev *, udev_new, (void));
> +   UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
> +
> +   if (dri_prime)
> +      prime = strdup(dri_prime);
> +
> +   if (prime == NULL) {
> +      *different_device = 0;
> +      return default_fd;
> +   }
> +
> +   udev = udev_new();
> +   if (!udev)
> +      goto prime_clean;
> +
> +   default_device_id_path_tag = get_id_path_tag_from_fd(udev, default_fd);
> +   if (!default_device_id_path_tag)
> +      goto udev_clean;
> +
> +   is_different_device = 1;
> +   /* two format are supported:
> +    * "1": choose any other card than the card used by default.
> +    * id_path_tag: (for example "pci-0000_02_00_0") choose the card
> +    * with this id_path_tag.
> +    */
> +   if (!strcmp(prime,"1")) {
> +      free(prime);
> +      prime = strdup(default_device_id_path_tag);
> +      /* request a card with a different card than the default card */
> +      another_tag = 1;
> +   } else if (!strcmp(default_device_id_path_tag, prime))
> +      /* we are to get a new fd (render-node) of the same device */
> +      is_different_device = 0;
> +
> +   device_name = get_render_node_from_id_path_tag(udev,
> +                                                  prime,
> +                                                  another_tag);
> +   if (device_name == NULL) {
> +      is_different_device = 0;
> +      goto default_device_clean;
> +   }
> +
> +   fd = drm_open_device(device_name);
> +   if (fd > 0) {
> +      close(default_fd);
> +   } else {
> +      fd = default_fd;
> +      is_different_device = 0;
> +   }
> +
Hi Axel,

AFAICS we're leaking device_name.

FYI I'm about to push a few patches for non libudev users which may cause
merge conflicts when applying this series.

Cheers
Emil



More information about the mesa-dev mailing list