mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
testdrv: make sure .remove() is called only once
And be sure to not call it twice if the sanity check fails. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -88,6 +88,13 @@ test_probe(struct ratbag_device *device, const struct ratbag_id id)
|
||||
static void
|
||||
test_remove(struct ratbag_device *device)
|
||||
{
|
||||
struct ratbag_test_device *d = ratbag_get_drv_data(device);
|
||||
|
||||
/* remove must be called only once */
|
||||
assert(d != NULL);
|
||||
if (d->destroyed)
|
||||
d->destroyed(device, d->destroyed_data);
|
||||
ratbag_set_drv_data(device, NULL);
|
||||
}
|
||||
|
||||
struct ratbag_driver test_driver = {
|
||||
|
||||
@@ -54,6 +54,8 @@ struct ratbag_test_device {
|
||||
unsigned int num_profiles;
|
||||
unsigned int num_buttons;
|
||||
struct ratbag_test_profile profiles[RATBAG_TEST_MAX_PROFILES];
|
||||
void (*destroyed)(struct ratbag_device *device, void *data);
|
||||
void *destroyed_data;
|
||||
};
|
||||
|
||||
struct ratbag_device* ratbag_device_new_test_device(struct ratbag *ratbag,
|
||||
|
||||
@@ -412,7 +412,6 @@ ratbag_find_driver(struct ratbag_device *device,
|
||||
rc = driver->probe(device, matched_id);
|
||||
if (rc == 0) {
|
||||
if (!ratbag_sanity_check_device(device)) {
|
||||
driver->remove(device);
|
||||
return NULL;
|
||||
} else {
|
||||
log_debug(ratbag, "driver match found\n");
|
||||
|
||||
Reference in New Issue
Block a user