diff options
Diffstat (limited to 'drivers/extcon/extcon-class.c')
| -rw-r--r-- | drivers/extcon/extcon-class.c | 102 | 
1 files changed, 50 insertions, 52 deletions
| diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 148382faded9..15443d3b6be1 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -74,7 +74,7 @@ static DEFINE_MUTEX(extcon_dev_list_lock);  /**   * check_mutually_exclusive - Check if new_state violates mutually_exclusive - *			    condition. + *			      condition.   * @edev:	the extcon device   * @new_state:	new cable attach status for @edev   * @@ -105,7 +105,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,  			  char *buf)  {  	int i, count = 0; -	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev); +	struct extcon_dev *edev = dev_get_drvdata(dev);  	if (edev->print_state) {  		int ret = edev->print_state(edev, buf); @@ -129,13 +129,12 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,  	return count;  } -int extcon_set_state(struct extcon_dev *edev, u32 state);  static ssize_t state_store(struct device *dev, struct device_attribute *attr,  			   const char *buf, size_t count)  {  	u32 state;  	ssize_t ret = 0; -	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev); +	struct extcon_dev *edev = dev_get_drvdata(dev);  	ret = sscanf(buf, "0x%x", &state);  	if (ret == 0) @@ -153,7 +152,7 @@ static DEVICE_ATTR_RW(state);  static ssize_t name_show(struct device *dev, struct device_attribute *attr,  		char *buf)  { -	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev); +	struct extcon_dev *edev = dev_get_drvdata(dev);  	/* Optional callback given by the user */  	if (edev->print_name) { @@ -162,7 +161,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,  			return ret;  	} -	return sprintf(buf, "%s\n", dev_name(edev->dev)); +	return sprintf(buf, "%s\n", dev_name(&edev->dev));  }  static DEVICE_ATTR_RO(name); @@ -189,7 +188,7 @@ static ssize_t cable_state_show(struct device *dev,  /**   * extcon_update_state() - Update the cable attach states of the extcon device - *			only for the masked bits. + *			   only for the masked bits.   * @edev:	the extcon device   * @mask:	the bit mask to designate updated bits.   * @state:	new cable attach status for @edev @@ -227,11 +226,10 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)  		edev->state |= state & mask;  		raw_notifier_call_chain(&edev->nh, old_state, edev); -  		/* This could be in interrupt handler */  		prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);  		if (prop_buf) { -			length = name_show(edev->dev, NULL, prop_buf); +			length = name_show(&edev->dev, NULL, prop_buf);  			if (length > 0) {  				if (prop_buf[length - 1] == '\n')  					prop_buf[length - 1] = 0; @@ -239,7 +237,7 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)  					"NAME=%s", prop_buf);  				envp[env_offset++] = name_buf;  			} -			length = state_show(edev->dev, NULL, prop_buf); +			length = state_show(&edev->dev, NULL, prop_buf);  			if (length > 0) {  				if (prop_buf[length - 1] == '\n')  					prop_buf[length - 1] = 0; @@ -251,14 +249,14 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)  			/* Unlock early before uevent */  			spin_unlock_irqrestore(&edev->lock, flags); -			kobject_uevent_env(&edev->dev->kobj, KOBJ_CHANGE, envp); +			kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);  			free_page((unsigned long)prop_buf);  		} else {  			/* Unlock early before uevent */  			spin_unlock_irqrestore(&edev->lock, flags); -			dev_err(edev->dev, "out of memory in extcon_set_state\n"); -			kobject_uevent(&edev->dev->kobj, KOBJ_CHANGE); +			dev_err(&edev->dev, "out of memory in extcon_set_state\n"); +			kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);  		}  	} else {  		/* No changes */ @@ -339,8 +337,9 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);  /**   * extcon_set_cable_state_() - Set the status of a specific cable. - * @edev:	the extcon device that has the cable. - * @index:	cable index that can be retrieved by extcon_find_cable_index(). + * @edev:		the extcon device that has the cable. + * @index:		cable index that can be retrieved by + *			extcon_find_cable_index().   * @cable_state:	the new cable status. The default semantics is   *			true: attached / false: detached.   */ @@ -359,8 +358,8 @@ EXPORT_SYMBOL_GPL(extcon_set_cable_state_);  /**   * extcon_set_cable_state() - Set the status of a specific cable. - * @edev:	the extcon device that has the cable. - * @cable_name:	cable name. + * @edev:		the extcon device that has the cable. + * @cable_name:		cable name.   * @cable_state:	the new cable status. The default semantics is   *			true: attached / false: detached.   * @@ -419,14 +418,14 @@ static int _call_per_cable(struct notifier_block *nb, unsigned long val,  /**   * extcon_register_interest() - Register a notifier for a state change of a - *			      specific cable, not an entier set of cables of a - *			      extcon device. - * @obj:	an empty extcon_specific_cable_nb object to be returned. + *				specific cable, not an entier set of cables of a + *				extcon device. + * @obj:		an empty extcon_specific_cable_nb object to be returned.   * @extcon_name:	the name of extcon device.   *			if NULL, extcon_register_interest will register   *			every cable with the target cable_name given.   * @cable_name:		the target cable name. - * @nb:		the notifier block to get notified. + * @nb:			the notifier block to get notified.   *   * Provide an empty extcon_specific_cable_nb. extcon_register_interest() sets   * the struct for you. @@ -452,7 +451,8 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,  		if (!obj->edev)  			return -ENODEV; -		obj->cable_index = extcon_find_cable_index(obj->edev, cable_name); +		obj->cable_index = extcon_find_cable_index(obj->edev, +							  cable_name);  		if (obj->cable_index < 0)  			return obj->cable_index; @@ -460,7 +460,8 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,  		obj->internal_nb.notifier_call = _call_per_cable; -		return raw_notifier_chain_register(&obj->edev->nh, &obj->internal_nb); +		return raw_notifier_chain_register(&obj->edev->nh, +						  &obj->internal_nb);  	} else {  		struct class_dev_iter iter;  		struct extcon_dev *extd; @@ -470,7 +471,7 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,  			return -ENODEV;  		class_dev_iter_init(&iter, extcon_class, NULL, NULL);  		while ((dev = class_dev_iter_next(&iter))) { -			extd = (struct extcon_dev *)dev_get_drvdata(dev); +			extd = dev_get_drvdata(dev);  			if (extcon_find_cable_index(extd, cable_name) < 0)  				continue; @@ -487,7 +488,7 @@ EXPORT_SYMBOL_GPL(extcon_register_interest);  /**   * extcon_unregister_interest() - Unregister the notifier registered by - *				extcon_register_interest(). + *				  extcon_register_interest().   * @obj:	the extcon_specific_cable_nb object returned by   *		extcon_register_interest().   */ @@ -502,7 +503,7 @@ EXPORT_SYMBOL_GPL(extcon_unregister_interest);  /**   * extcon_register_notifier() - Register a notifiee to get notified by - *			      any attach status changes from the extcon. + *				any attach status changes from the extcon.   * @edev:	the extcon device.   * @nb:		a notifier block to be registered.   * @@ -556,7 +557,6 @@ static int create_extcon_class(void)  static void extcon_dev_release(struct device *dev)  { -	kfree(dev);  }  static const char *muex_name = "mutually_exclusive"; @@ -567,14 +567,13 @@ static void dummy_sysfs_dev_release(struct device *dev)  /**   * extcon_dev_register() - Register a new extcon device   * @edev	: the new extcon device (should be allocated before calling) - * @dev		: the parent device for this extcon device.   *   * Among the members of edev struct, please set the "user initializing data"   * in any case and set the "optional callbacks" if required. However, please   * do not set the values of "internal data", which are initialized by   * this function.   */ -int extcon_dev_register(struct extcon_dev *edev, struct device *dev) +int extcon_dev_register(struct extcon_dev *edev)  {  	int ret, index = 0; @@ -594,19 +593,20 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)  	}  	if (index > SUPPORTED_CABLE_MAX) { -		dev_err(edev->dev, "extcon: maximum number of supported cables exceeded.\n"); +		dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");  		return -EINVAL;  	} -	edev->dev = kzalloc(sizeof(struct device), GFP_KERNEL); -	if (!edev->dev) -		return -ENOMEM; -	edev->dev->parent = dev; -	edev->dev->class = extcon_class; -	edev->dev->release = extcon_dev_release; +	edev->dev.class = extcon_class; +	edev->dev.release = extcon_dev_release; -	edev->name = edev->name ? edev->name : dev_name(dev); -	dev_set_name(edev->dev, "%s", edev->name); +	edev->name = edev->name ? edev->name : dev_name(edev->dev.parent); +	if (IS_ERR_OR_NULL(edev->name)) { +		dev_err(&edev->dev, +			"extcon device name is null\n"); +		return -EINVAL; +	} +	dev_set_name(&edev->dev, "%s", edev->name);  	if (edev->max_supported) {  		char buf[10]; @@ -714,7 +714,7 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)  			goto err_alloc_groups;  		} -		edev->extcon_dev_type.name = dev_name(edev->dev); +		edev->extcon_dev_type.name = dev_name(&edev->dev);  		edev->extcon_dev_type.release = dummy_sysfs_dev_release;  		for (index = 0; index < edev->max_supported; index++) @@ -724,25 +724,24 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)  			edev->extcon_dev_type.groups[index] =  				&edev->attr_g_muex; -		edev->dev->type = &edev->extcon_dev_type; +		edev->dev.type = &edev->extcon_dev_type;  	} -	ret = device_register(edev->dev); +	ret = device_register(&edev->dev);  	if (ret) { -		put_device(edev->dev); +		put_device(&edev->dev);  		goto err_dev;  	}  #if defined(CONFIG_ANDROID)  	if (switch_class) -		ret = class_compat_create_link(switch_class, edev->dev, -					       NULL); +		ret = class_compat_create_link(switch_class, &edev->dev, NULL);  #endif /* CONFIG_ANDROID */  	spin_lock_init(&edev->lock);  	RAW_INIT_NOTIFIER_HEAD(&edev->nh); -	dev_set_drvdata(edev->dev, edev); +	dev_set_drvdata(&edev->dev, edev);  	edev->state = 0;  	mutex_lock(&extcon_dev_list_lock); @@ -768,7 +767,6 @@ err_alloc_cables:  	if (edev->max_supported)  		kfree(edev->cables);  err_sysfs_alloc: -	kfree(edev->dev);  	return ret;  }  EXPORT_SYMBOL_GPL(extcon_dev_register); @@ -788,9 +786,9 @@ void extcon_dev_unregister(struct extcon_dev *edev)  	list_del(&edev->entry);  	mutex_unlock(&extcon_dev_list_lock); -	if (IS_ERR_OR_NULL(get_device(edev->dev))) { -		dev_err(edev->dev, "Failed to unregister extcon_dev (%s)\n", -				dev_name(edev->dev)); +	if (IS_ERR_OR_NULL(get_device(&edev->dev))) { +		dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n", +				dev_name(&edev->dev));  		return;  	} @@ -812,10 +810,10 @@ void extcon_dev_unregister(struct extcon_dev *edev)  #if defined(CONFIG_ANDROID)  	if (switch_class) -		class_compat_remove_link(switch_class, edev->dev, NULL); +		class_compat_remove_link(switch_class, &edev->dev, NULL);  #endif -	device_unregister(edev->dev); -	put_device(edev->dev); +	device_unregister(&edev->dev); +	put_device(&edev->dev);  }  EXPORT_SYMBOL_GPL(extcon_dev_unregister); |