@@ -11,15 +11,15 @@ OSDefineMetaClassAndStructors(HyperVVMBusDevice, super);
11
11
12
12
bool HyperVVMBusDevice::attach (IOService *provider) {
13
13
bool result = false ;
14
-
14
+
15
15
char channelLocation[10 ];
16
16
OSString *typeIdString;
17
17
OSNumber *channelNumber;
18
18
OSData *instanceBytes;
19
-
19
+
20
20
UInt8 builtInBytes = 0 ;
21
21
OSData *builtInData;
22
-
22
+
23
23
//
24
24
// Get VMBus provider.
25
25
//
@@ -46,14 +46,14 @@ bool HyperVVMBusDevice::attach(IOService *provider) {
46
46
HVSYSLOG (" Failed to initialize work loop" );
47
47
break ;
48
48
}
49
-
49
+
50
50
_commandGate = IOCommandGate::commandGate (this );
51
51
if (_commandGate == nullptr ) {
52
52
HVSYSLOG (" Failed to initialize command gate" );
53
53
break ;
54
54
}
55
55
_workLoop->addEventSource (_commandGate);
56
-
56
+
57
57
//
58
58
// Get channel number and GUID properties.
59
59
//
@@ -64,7 +64,7 @@ bool HyperVVMBusDevice::attach(IOService *provider) {
64
64
HVSYSLOG (" Failed to get channel properties" );
65
65
break ;
66
66
}
67
-
67
+
68
68
//
69
69
// Copy channel number and GUIDs.
70
70
// uuid_string_t size includes null terminator.
@@ -73,13 +73,13 @@ bool HyperVVMBusDevice::attach(IOService *provider) {
73
73
_channelId = channelNumber->unsigned32BitValue ();
74
74
HVDBGLOG (" Attaching nub type %s for channel %u" , _typeId, _channelId);
75
75
memcpy (_instanceId, instanceBytes->getBytesNoCopy (), instanceBytes->getLength ());
76
-
76
+
77
77
//
78
78
// Set location to ensure unique names in I/O Registry.
79
79
//
80
80
snprintf (channelLocation, sizeof (channelLocation), " %x" , (unsigned int ) _channelId);
81
81
setLocation (channelLocation);
82
-
82
+
83
83
//
84
84
// The built-in property is required for some devices, like networking.
85
85
//
@@ -91,12 +91,15 @@ bool HyperVVMBusDevice::attach(IOService *provider) {
91
91
setProperty (" built-in" , builtInData);
92
92
builtInData->release ();
93
93
94
- _vmbusRequestsLock = IOLockAlloc ();
95
- _vmbusTransLock = IOLockAlloc ();
96
-
94
+ _vmbusRequestsLock = IOLockAlloc ();
95
+ _vmbusTransLock = IOLockAlloc ();
97
96
_threadZeroRequest.lock = IOLockAlloc ();
97
+ if ((_vmbusRequestsLock == nullptr ) || (_vmbusTransLock == nullptr ) || (_threadZeroRequest.lock == nullptr )) {
98
+ HVSYSLOG (" Failed to initialize locks" );
99
+ break ;
100
+ }
98
101
prepareSleepThread ();
99
-
102
+
100
103
result = true ;
101
104
} while (false );
102
105
@@ -117,9 +120,15 @@ void HyperVVMBusDevice::detach(IOService *provider) {
117
120
OSSafeReleaseNULL (_vmbusProvider);
118
121
}
119
122
120
- IOLockFree (_vmbusRequestsLock);
121
- IOLockFree (_vmbusTransLock);
122
- IOLockFree (_threadZeroRequest.lock );
123
+ if (_vmbusRequestsLock != nullptr ) {
124
+ IOLockFree (_vmbusRequestsLock);
125
+ }
126
+ if (_vmbusTransLock != nullptr ) {
127
+ IOLockFree (_vmbusTransLock);
128
+ }
129
+ if (_threadZeroRequest.lock != nullptr ) {
130
+ IOLockFree (_threadZeroRequest.lock );
131
+ }
123
132
124
133
if (_commandGate != nullptr ) {
125
134
_workLoop->removeEventSource (_commandGate);
0 commit comments