1
0
forked from drath/libratbag

hidpp20-drv: prevent an empty profile to try to read a null macro

If the macro has not been retrieved, it's more likely that the button
is not bound to anything.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2016-05-09 19:52:56 +02:00
parent 64037febdc
commit c14a0ca2a1

View File

@@ -117,7 +117,7 @@ hidpp20drv_read_macro_key_8100(struct ratbag_device *device, union hidpp20_macro
return ratbag_hidraw_get_keycode_from_keyboard_usage(device, macro->key.key);
}
static void
static int
hidpp20drv_read_macro_8100(struct ratbag_button *button,
struct hidpp20_profile *profile,
union hidpp20_button_binding *binding)
@@ -130,6 +130,9 @@ hidpp20drv_read_macro_8100(struct ratbag_button *button,
macro = profile->macros[binding->macro.page];
if (!macro)
return -EINVAL;
i = 0;
m = ratbag_button_macro_new("macro");
@@ -175,6 +178,8 @@ hidpp20drv_read_macro_8100(struct ratbag_button *button,
ratbag_button_copy_macro(button, m);
ratbag_button_macro_unref(m);
return 0;
}
static void
@@ -183,6 +188,7 @@ hidpp20drv_read_button_8100(struct ratbag_button *button)
struct ratbag_device *device = button->profile->device;
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
struct hidpp20_profile *profile;
int rc;
if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100))
return;
@@ -213,7 +219,9 @@ hidpp20drv_read_button_8100(struct ratbag_button *button)
button->action.action.special = hidpp20_onboard_profiles_get_special(profile->buttons[button->index].special.special);
break;
case HIDPP20_BUTTON_MACRO:
hidpp20drv_read_macro_8100(button, profile, &profile->buttons[button->index]);
rc = hidpp20drv_read_macro_8100(button, profile, &profile->buttons[button->index]);
if (rc)
button->action.type = RATBAG_BUTTON_ACTION_TYPE_NONE;
break;
default:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_UNKNOWN;