[PATCH 2/2 v2] linux: Implement map_legacy

Guillem Jover guillem at hadrons.org
Fri Oct 7 01:43:31 PDT 2011


On Thu, 2011-10-06 at 20:51:31 -0700, Jeremy Huddleston wrote:
> diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c
> index 0ed6862..8b943a4 100644
> --- a/src/linux_sysfs.c
> +++ b/src/linux_sysfs.c
> @@ -840,6 +840,56 @@ pci_device_linux_sysfs_write8(struct pci_io_handle *handle, uint32_t port,
>      pwrite(handle->fd, &data, 1, port + handle->base);
>  }
>  
> +static int
> +pci_device_linux_sysfs_map_legacy(struct pci_device *dev, pciaddr_t base,
> +				  pciaddr_t size, unsigned map_flags, void **addr)
> +{
> +    char name[PATH_MAX];
> +    int flags = O_RDONLY;
> +    int prot = PROT_READ;
> +    int fd;
[...]
> +
> +    *addr = mmap(NULL, size, prot, MAP_SHARED, fd, base);
> +    if (*addr == MAP_FAILED) {
> +	int ret = errno;
> +	close(fd);
> +	return ret;
> +    }
> +
> +    close(fd);
> +    return 0;
> +}

How about this instead?

    int ret = 0;
[...]
    if (*addr == MAP_FAILED)
      ret = errno;

    close(fd);
    return ret;

thanks,
guillem


More information about the xorg-devel mailing list