diff --git a/src/add-ons/kernel/drivers/graphics/vesa/device.cpp b/src/add-ons/kernel/drivers/graphics/vesa/device.cpp index 144e4936ed..0ea3602341 100644 --- a/src/add-ons/kernel/drivers/graphics/vesa/device.cpp +++ b/src/add-ons/kernel/drivers/graphics/vesa/device.cpp @@ -51,13 +51,12 @@ device_open(const char* name, uint32 flags, void** _cookie) return B_BAD_VALUE; vesa_info* info = gDeviceInfo[id]; - *_cookie = info; mutex_lock(&gLock); status_t status = B_OK; - if (info->open_count++ == 0) { + if (info->open_count == 0) { // this device has been opened for the first time, so // we allocate needed resources and initialize the structure if (status == B_OK) @@ -66,6 +65,11 @@ device_open(const char* name, uint32 flags, void** _cookie) info->id = id; } + if (status == B_OK) { + info->open_count++; + *_cookie = info; + } + mutex_unlock(&gLock); return status; }