Skip to content

Commit

Permalink
Validate whether MatchedName exists (#415)
Browse files Browse the repository at this point in the history
* Validate whether MatchedName exists

Fix #405

* Iterate with getChildIterator()

* Refractor publishNubs()

* Update VoodooI2CControllerDriver.cpp
  • Loading branch information
zhen-zen authored Dec 5, 2020
1 parent 34bbfcb commit b5a11ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Dependencies/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const char* getMatchedName(IOService* provider) {
OSData *data;
data = OSDynamicCast(OSData, provider->getProperty("name"));
return (const char *)(data->getBytesNoCopy());
return (data ? (const char *)(data->getBytesNoCopy()) : "(null)");
}

UInt16 abs(SInt16 x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,47 +238,32 @@ IOReturn VoodooI2CControllerDriver::publishNubs() {
IOLog("%s::%s Publishing device nubs\n", getName(), bus_device.name);

IOService* child;
IORegistryIterator* children = IORegistryIterator::iterateOver(nub->controller->physical_device.acpi_device, gIOACPIPlane);

if (children) {
OSOrderedSet* set = children->iterateAll();
if (set) {
OSIterator *iterator = OSCollectionIterator::withCollection(set);
if (iterator) {
while ((child = reinterpret_cast<IOService*>(iterator->getNextObject()))) {
IOLog("%s::%s Found I2C device: %s\n", getName(), bus_device.name, getMatchedName(child));

VoodooI2CDeviceNub* device_nub = OSTypeAlloc(VoodooI2CDeviceNub);

OSDictionary* child_properties = child->dictionaryWithProperties();
bool nub_initialized = true;
if (!device_nub ||
!device_nub->init(child_properties) ||
!device_nub->attach(this, child)) {
nub_initialized = false;
} else if (!device_nub->start(this)) {
device_nub->detach(this);
nub_initialized = false;
}

OSSafeReleaseNULL(child_properties);

if (!nub_initialized) {
IOLog("%s::%s Could not initialise nub for %s\n", getName(), bus_device.name, getMatchedName(child));
OSSafeReleaseNULL(device_nub);

continue;
}

device_nubs->setObject(device_nub);
device_nub->release();
}
iterator->release();
}
set->release();
OSIterator* children = nub->controller->physical_device.acpi_device->getChildIterator(gIOACPIPlane);

if (!children)
return kIOReturnNoResources;

while ((child = OSDynamicCast(IOService, children->getNextObject()))) {
IOLog("%s::%s Found I2C device: %s\n", getName(), bus_device.name, getMatchedName(child));

VoodooI2CDeviceNub* device_nub = OSTypeAlloc(VoodooI2CDeviceNub);
OSDictionary* child_properties = child->dictionaryWithProperties();

if (!device_nub ||
!device_nub->init(child_properties) ||
!device_nub->attach(this, child)) {
IOLog("%s::%s Could not initialise nub for %s\n", getName(), bus_device.name, getMatchedName(child));
} else if (!device_nub->start(this)) {
device_nub->detach(this);
IOLog("%s::%s Could not start nub for %s\n", getName(), bus_device.name, getMatchedName(child));
} else {
device_nubs->setObject(device_nub);
}
children->release();

OSSafeReleaseNULL(child_properties);
OSSafeReleaseNULL(device_nub);
}
children->release();

return kIOReturnSuccess;
}
Expand Down

0 comments on commit b5a11ce

Please sign in to comment.