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