IOReturn CLASS::newUserClient(task_t owningTask, void* securityID, UInt32 type, IOUserClient ** handler)
{
	IOUserClient *client;

	if (type != kGUXUCType)
		return kIOReturnUnsupported;
	if (!handler)
		return kIOReturnBadArgument;

	client = OSTypeAlloc(GenericUSBXHCIUserClient);
	if (!client)
		return kIOReturnNoMemory;
	if (!client->initWithTask(owningTask, securityID, type)) {
		client->release();
		return kIOReturnInternalError;
	}
	if (!client->attach(this)) {
		client->release();
		return kIOReturnInternalError;
	}
	if (!client->start(this)) {
		client->detach(this);
		client->release();
		return kIOReturnInternalError;
	}
	*handler = client;
	return kIOReturnSuccess;
}
Ejemplo n.º 2
0
IOReturn
IOI2CDevice::newUserClient(
	task_t			owningTask,
	void			*securityID,
	UInt32			type,
	OSDictionary	*properties,
	IOUserClient	**handler)
{
	IOUserClient	*client;
	OSObject		*temp;

	DLOG("%s::newUserClient\n", getName());

	if (type != kIOI2CUserClientType)
		return super::newUserClient(owningTask,securityID,type,properties,handler);

	if (IOUserClient::clientHasPrivilege(securityID, "root") != kIOReturnSuccess)
	{
		ERRLOG("%s::newUserClient: Can't create user client, not privileged\n", getName());
		return kIOReturnNotPrivileged;
	}

	temp = OSMetaClass::allocClassWithName("IOI2CUserClient");
	if (!temp)
		return kIOReturnNoMemory;

	if (OSDynamicCast(IOUserClient, temp))
		client = (IOUserClient *) temp;
	else
	{
		temp->release();
		return kIOReturnUnsupported;
	}

	if ( !client->initWithTask(owningTask, securityID, type, properties) )
	{
		client->release();
		return kIOReturnBadArgument;
	}

	if ( !client->attach(this) )
	{
		client->release();
		return kIOReturnUnsupported;
	}

	if ( !client->start(this) )
	{
		client->detach(this);
		client->release();
		return kIOReturnUnsupported;
	}

	*handler = client;
	return kIOReturnSuccess;
}