From 91a033f157e5de7040e5a71c96b0d9826a69b6f7 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 26 Aug 2015 13:58:09 +1000 Subject: [PATCH] Don't create a button when requesting one The drivers are responsible for initializing the buttons during probe(), then we just return the one we found Signed-off-by: Peter Hutterer --- src/libratbag.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 3e16d254..631a2c4f 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -715,17 +715,24 @@ LIBRATBAG_EXPORT struct ratbag_button* ratbag_profile_get_button_by_index(struct ratbag_profile *profile, unsigned int index) { + struct ratbag_device *device = profile->device; struct ratbag_button *button; + if (index >= ratbag_device_get_num_buttons(device)) + return NULL; + list_for_each(button, &profile->buttons, link) { if (button->index == index) { - if (profile->device->driver->read_button) - profile->device->driver->read_button(button); + if (device->driver->read_button) + device->driver->read_button(button); return ratbag_button_ref(button); } } - return ratbag_create_button(profile, index); + log_bug_libratbag(device->ratbag, "Button %d, profile %d not found\n", + index, profile->index); + + return NULL; } LIBRATBAG_EXPORT enum ratbag_button_type