1
0
forked from drath/libratbag

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:
Benjamin Tissoires
2015-09-04 11:59:04 -04:00
parent 97bfc86165
commit 7b2a43f17c
4 changed files with 38 additions and 1 deletions

View File

@@ -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 = {

View File

@@ -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,

View File

@@ -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");