Commit dae61651 authored by Chanwoo Choi's avatar Chanwoo Choi

extcon: Change field type of 'dev' in extcon_dev structure

The extcon device must always need 'struct device' so this patch change
field type of 'dev' instead of allocating memory for 'struct device' on
extcon_dev_register() function.
Signed-off-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: default avatarMyungjoo Ham <cw00.choi@samsung.com>
parent 41024243
...@@ -64,7 +64,7 @@ static void adc_jack_handler(struct work_struct *work) ...@@ -64,7 +64,7 @@ static void adc_jack_handler(struct work_struct *work)
ret = iio_read_channel_raw(data->chan, &adc_val); ret = iio_read_channel_raw(data->chan, &adc_val);
if (ret < 0) { if (ret < 0) {
dev_err(data->edev.dev, "read channel() error: %d\n", ret); dev_err(&data->edev.dev, "read channel() error: %d\n", ret);
return; return;
} }
......
...@@ -162,7 +162,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, ...@@ -162,7 +162,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
return ret; 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); static DEVICE_ATTR_RO(name);
...@@ -230,7 +230,7 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) ...@@ -230,7 +230,7 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
/* This could be in interrupt handler */ /* This could be in interrupt handler */
prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
if (prop_buf) { if (prop_buf) {
length = name_show(edev->dev, NULL, prop_buf); length = name_show(&edev->dev, NULL, prop_buf);
if (length > 0) { if (length > 0) {
if (prop_buf[length - 1] == '\n') if (prop_buf[length - 1] == '\n')
prop_buf[length - 1] = 0; prop_buf[length - 1] = 0;
...@@ -238,7 +238,7 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) ...@@ -238,7 +238,7 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
"NAME=%s", prop_buf); "NAME=%s", prop_buf);
envp[env_offset++] = name_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 (length > 0) {
if (prop_buf[length - 1] == '\n') if (prop_buf[length - 1] == '\n')
prop_buf[length - 1] = 0; prop_buf[length - 1] = 0;
...@@ -250,14 +250,14 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) ...@@ -250,14 +250,14 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
/* Unlock early before uevent */ /* Unlock early before uevent */
spin_unlock_irqrestore(&edev->lock, flags); 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); free_page((unsigned long)prop_buf);
} else { } else {
/* Unlock early before uevent */ /* Unlock early before uevent */
spin_unlock_irqrestore(&edev->lock, flags); spin_unlock_irqrestore(&edev->lock, flags);
dev_err(edev->dev, "out of memory in extcon_set_state\n"); dev_err(&edev->dev, "out of memory in extcon_set_state\n");
kobject_uevent(&edev->dev->kobj, KOBJ_CHANGE); kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
} }
} else { } else {
/* No changes */ /* No changes */
...@@ -556,7 +556,6 @@ static int create_extcon_class(void) ...@@ -556,7 +556,6 @@ static int create_extcon_class(void)
static void extcon_dev_release(struct device *dev) static void extcon_dev_release(struct device *dev)
{ {
kfree(dev);
} }
static const char *muex_name = "mutually_exclusive"; static const char *muex_name = "mutually_exclusive";
...@@ -594,19 +593,16 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev) ...@@ -594,19 +593,16 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
} }
if (index > SUPPORTED_CABLE_MAX) { 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; return -EINVAL;
} }
edev->dev = kzalloc(sizeof(struct device), GFP_KERNEL); edev->dev.parent = dev;
if (!edev->dev) edev->dev.class = extcon_class;
return -ENOMEM; edev->dev.release = extcon_dev_release;
edev->dev->parent = dev;
edev->dev->class = extcon_class;
edev->dev->release = extcon_dev_release;
edev->name = edev->name ? edev->name : dev_name(dev); edev->name = edev->name ? edev->name : dev_name(dev);
dev_set_name(edev->dev, "%s", edev->name); dev_set_name(&edev->dev, "%s", edev->name);
if (edev->max_supported) { if (edev->max_supported) {
char buf[10]; char buf[10];
...@@ -714,7 +710,7 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev) ...@@ -714,7 +710,7 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
goto err_alloc_groups; 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; edev->extcon_dev_type.release = dummy_sysfs_dev_release;
for (index = 0; index < edev->max_supported; index++) for (index = 0; index < edev->max_supported; index++)
...@@ -724,25 +720,24 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev) ...@@ -724,25 +720,24 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
edev->extcon_dev_type.groups[index] = edev->extcon_dev_type.groups[index] =
&edev->attr_g_muex; &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) { if (ret) {
put_device(edev->dev); put_device(&edev->dev);
goto err_dev; goto err_dev;
} }
#if defined(CONFIG_ANDROID) #if defined(CONFIG_ANDROID)
if (switch_class) if (switch_class)
ret = class_compat_create_link(switch_class, edev->dev, ret = class_compat_create_link(switch_class, &edev->dev, NULL);
NULL);
#endif /* CONFIG_ANDROID */ #endif /* CONFIG_ANDROID */
spin_lock_init(&edev->lock); spin_lock_init(&edev->lock);
RAW_INIT_NOTIFIER_HEAD(&edev->nh); RAW_INIT_NOTIFIER_HEAD(&edev->nh);
dev_set_drvdata(edev->dev, edev); dev_set_drvdata(&edev->dev, edev);
edev->state = 0; edev->state = 0;
mutex_lock(&extcon_dev_list_lock); mutex_lock(&extcon_dev_list_lock);
...@@ -768,7 +763,6 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev) ...@@ -768,7 +763,6 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
if (edev->max_supported) if (edev->max_supported)
kfree(edev->cables); kfree(edev->cables);
err_sysfs_alloc: err_sysfs_alloc:
kfree(edev->dev);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(extcon_dev_register); EXPORT_SYMBOL_GPL(extcon_dev_register);
...@@ -788,9 +782,9 @@ void extcon_dev_unregister(struct extcon_dev *edev) ...@@ -788,9 +782,9 @@ void extcon_dev_unregister(struct extcon_dev *edev)
list_del(&edev->entry); list_del(&edev->entry);
mutex_unlock(&extcon_dev_list_lock); mutex_unlock(&extcon_dev_list_lock);
if (IS_ERR_OR_NULL(get_device(edev->dev))) { if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
dev_err(edev->dev, "Failed to unregister extcon_dev (%s)\n", dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
dev_name(edev->dev)); dev_name(&edev->dev));
return; return;
} }
...@@ -812,10 +806,10 @@ void extcon_dev_unregister(struct extcon_dev *edev) ...@@ -812,10 +806,10 @@ void extcon_dev_unregister(struct extcon_dev *edev)
#if defined(CONFIG_ANDROID) #if defined(CONFIG_ANDROID)
if (switch_class) if (switch_class)
class_compat_remove_link(switch_class, edev->dev, NULL); class_compat_remove_link(switch_class, &edev->dev, NULL);
#endif #endif
device_unregister(edev->dev); device_unregister(&edev->dev);
put_device(edev->dev); put_device(&edev->dev);
} }
EXPORT_SYMBOL_GPL(extcon_dev_unregister); EXPORT_SYMBOL_GPL(extcon_dev_unregister);
......
...@@ -93,7 +93,7 @@ struct extcon_cable; ...@@ -93,7 +93,7 @@ struct extcon_cable;
* name of the extcon device. * name of the extcon device.
* @print_state: An optional callback to override the method to print the * @print_state: An optional callback to override the method to print the
* status of the extcon device. * status of the extcon device.
* @dev: Device of this extcon. Do not provide at register-time. * @dev: Device of this extcon.
* @state: Attach/detach state of this extcon. Do not provide at * @state: Attach/detach state of this extcon. Do not provide at
* register-time. * register-time.
* @nh: Notifier for the state change events from this extcon * @nh: Notifier for the state change events from this extcon
...@@ -121,7 +121,7 @@ struct extcon_dev { ...@@ -121,7 +121,7 @@ struct extcon_dev {
ssize_t (*print_state)(struct extcon_dev *edev, char *buf); ssize_t (*print_state)(struct extcon_dev *edev, char *buf);
/* Internal data. Please do not set. */ /* Internal data. Please do not set. */
struct device *dev; struct device dev;
struct raw_notifier_head nh; struct raw_notifier_head nh;
struct list_head entry; struct list_head entry;
int max_supported; int max_supported;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment