diff --git a/input/common/udev_common.c b/input/common/udev_common.c index 5a265b1d16..6cd24345cc 100644 --- a/input/common/udev_common.c +++ b/input/common/udev_common.c @@ -6,7 +6,7 @@ static bool udev_mon_inited; static struct udev_monitor *g_udev_mon; -struct udev *g_udev; +static struct udev *g_udev; bool udev_mon_new(void) { @@ -61,3 +61,15 @@ struct udev_device *udev_mon_receive_device(void) { return udev_monitor_receive_device(g_udev_mon); } + +struct udev_enumerate *udev_mon_enumerate(void) +{ + return udev_enumerate_new(g_udev); +} + +/* Get the filename of the /sys entry for the device + * and create a udev_device object (dev) representing it. */ +struct udev_device *udev_mon_device_new(const char *name) +{ + return udev_device_new_from_syspath(g_udev, name); +} diff --git a/input/common/udev_common.h b/input/common/udev_common.h index aa1574c196..83af7142f6 100644 --- a/input/common/udev_common.h +++ b/input/common/udev_common.h @@ -21,8 +21,6 @@ #include -extern struct udev *g_udev; - bool udev_mon_new(void); void udev_mon_free(bool is_joypad); @@ -31,4 +29,8 @@ bool udev_mon_hotplug_available(void); struct udev_device *udev_mon_receive_device(void); +struct udev_enumerate *udev_mon_enumerate(void); + +struct udev_device *udev_mon_device_new(const char *name); + #endif diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 40ff1bc9f3..c0fd7d4012 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -580,7 +580,7 @@ static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb { struct udev_list_entry *devs = NULL; struct udev_list_entry *item = NULL; - struct udev_enumerate *enumerate = udev_enumerate_new(g_udev); + struct udev_enumerate *enumerate = udev_mon_enumerate(); if (!enumerate) return false; @@ -591,12 +591,9 @@ static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb for (item = devs; item; item = udev_list_entry_get_next(item)) { - const char *name = udev_list_entry_get_name(item); - - /* Get the filename of the /sys entry for the device - * and create a udev_device object (dev) representing it. */ - struct udev_device *dev = udev_device_new_from_syspath(g_udev, name); - const char *devnode = udev_device_get_devnode(dev); + const char *name = udev_list_entry_get_name(item); + struct udev_device *dev = udev_mon_device_new(name); + const char *devnode = udev_device_get_devnode(dev); if (devnode) { diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c index f5d55877f8..3557eda111 100644 --- a/input/drivers_joypad/udev_joypad.c +++ b/input/drivers_joypad/udev_joypad.c @@ -518,7 +518,7 @@ static bool udev_joypad_init(void *data) if (!udev_mon_new()) goto error; - enumerate = udev_enumerate_new(g_udev); + enumerate = udev_mon_enumerate(); if (!enumerate) goto error; @@ -529,7 +529,7 @@ static bool udev_joypad_init(void *data) for (item = devs; item; item = udev_list_entry_get_next(item)) { const char *name = udev_list_entry_get_name(item); - struct udev_device *dev = udev_device_new_from_syspath(g_udev, name); + struct udev_device *dev = udev_mon_device_new(name); const char *devnode = udev_device_get_devnode(dev); if (devnode)