[PATCH xserver] os: don't re-remove an already removed fd

Peter Hutterer peter.hutterer at who-t.net
Fri Aug 12 00:37:01 UTC 2016


On Thu, Aug 11, 2016 at 12:39:46PM -0700, Keith Packard wrote:
> Peter Hutterer <peter.hutterer at who-t.net> writes:
> 
> > that's the plan for the driver, but for now the current behaviour is a
> > change to what used to work. And it's a bit confusing too -
> > xf86AddEnabledDevice() takes a pInfo, not just an fd. So it looks like it
> > works on a per-device level and we should emulate that behaviour as best as
> > we can. Right now you can pass two different pInfos in and then you get to
> > bet whether you remove the same device twice or not.
> 
> I went and looked at the previous version of xf86AddEnabledDevice, and
> it supports multiple calls with the same fd by replacing the callback
> and args. We can do the same thing with InputThreadRegisterDev and make
> it actually compatible with the old API. Seems like a more sane plan
> than having duplicate fds in the input device list, only one of which
> actually gets used.

thanks, that does seem like the better plan.
and it didn't crash across lots of wacom replugs.

pushed    2df2815..bf31d6f  master -> master

Cheers,
   Peter


> From 0ed596f16bde0f6df151db657c11973c457f4eb4 Mon Sep 17 00:00:00 2001
> From: Keith Packard <keithp at keithp.com>
> Date: Thu, 11 Aug 2016 12:34:54 -0700
> Subject: [PATCH xserver] os: Allow re-registering fd with
>  InputThreadRegisterDev
> 
> Calling InputThreadRegisterDev twice with the same fd should replace
> the existing function and args instead of creating a new entry with
> the same fd.
> 
> Signed-off-by: Keith Packard <keithp at keithp.com>
> ---
>  os/inputthread.c | 36 +++++++++++++++++++++++++-----------
>  1 file changed, 25 insertions(+), 11 deletions(-)
> 
> diff --git a/os/inputthread.c b/os/inputthread.c
> index cb3af06..1cd1c2a 100644
> --- a/os/inputthread.c
> +++ b/os/inputthread.c
> @@ -188,24 +188,38 @@ InputThreadRegisterDev(int fd,
>                         NotifyFdProcPtr readInputProc,
>                         void *readInputArgs)
>  {
> -    InputThreadDevice *dev;
> +    InputThreadDevice *dev, *old;
>  
>      if (!inputThreadInfo)
>          return SetNotifyFd(fd, readInputProc, X_NOTIFY_READ, readInputArgs);
>  
> -    dev = calloc(1, sizeof(InputThreadDevice));
> -    if (dev == NULL) {
> -        DebugF("input-thread: could not register device\n");
> -        return 0;
> +    input_lock();
> +
> +    dev = NULL;
> +    xorg_list_for_each_entry(old, &inputThreadInfo->devs, node) {
> +        if (old->fd == fd) {
> +            dev = old;
> +            break;
> +        }
>      }
>  
> -    dev->fd = fd;
> -    dev->readInputProc = readInputProc;
> -    dev->readInputArgs = readInputArgs;
> -    dev->state = device_state_added;
> +    if (dev) {
> +        dev->readInputProc = readInputProc;
> +        dev->readInputArgs = readInputArgs;
> +    } else {
> +        dev = calloc(1, sizeof(InputThreadDevice));
> +        if (dev == NULL) {
> +            DebugF("input-thread: could not register device\n");
> +            input_unlock();
> +            return 0;
> +        }
>  
> -    input_lock();
> -    xorg_list_append(&dev->node, &inputThreadInfo->devs);
> +        dev->fd = fd;
> +        dev->readInputProc = readInputProc;
> +        dev->readInputArgs = readInputArgs;
> +        dev->state = device_state_added;
> +        xorg_list_append(&dev->node, &inputThreadInfo->devs);
> +    }
>  
>      inputThreadInfo->changed = TRUE;
>  
> -- 
> 2.8.1
> 

> 
> -- 
> -keith





More information about the xorg-devel mailing list