History

extcon: Modify extcon device to be created after driver data is set

Currently, someone can invoke the sysfs such as state_show() intermittently before dev_set_drvdata() is done. And it can be a cause of kernel Oops because of edev is Null at that time. So modified the driver registration to after setting drviver data. - Oops's backtrace. Backtrace: [<c067865c>] (state_show) from [<c05222e8>] (dev_attr_show) [<c05222c0>] (dev_attr_show) from [<c02c66e0>] (sysfs_kf_seq_show) [<c02c6648>] (sysfs_kf_seq_show) from [<c02c496c>] (kernfs_seq_show) [<c02c4938>] (kernfs_seq_show) from [<c025e2a0>] (seq_read) [<c025e11c>] (seq_read) from [<c02c50a0>] (kernfs_fop_read) [<c02c5064>] (kernfs_fop_read) from [<c0231cac>] (__vfs_read) [<c0231c5c>] (__vfs_read) from [<c0231ee0>] (vfs_read) [<c0231e34>] (vfs_read) from [<c0232464>] (ksys_read) [<c02323f0>] (ksys_read) from [<c02324fc>] (sys_read) [<c02324e4>] (sys_read) from [<c00091d0>] (__sys_trace_return)

bumwoo lee committed 4 years ago

Commit 5dcc2af1 parent 5faf7cb1 file · +17 −12Browse files

Unified · Split

drivers/extcon/extcon.c+17−12
@@ -1224,19 +1224,14 @@ int extcon_dev_register(struct extcon_dev *edev) · 1223 unmodified lines
12241224 edev->dev.type = &edev->extcon_dev_type;
12251225 }
12261226
1227− ret = device_register(&edev->dev);
1228− if (ret) {
1229− put_device(&edev->dev);
1230− goto err_dev;
1231− }
1232−
12331227 spin_lock_init(&edev->lock);
1234− edev->nh = devm_kcalloc(&edev->dev, edev->max_supported,
1235− sizeof(*edev->nh), GFP_KERNEL);
1236− if (!edev->nh) {
1237− ret = -ENOMEM;
1238− device_unregister(&edev->dev);
1239− goto err_dev;
1228+ if (edev->max_supported) {
1229+ edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
1230+ GFP_KERNEL);
1231+ if (!edev->nh) {
1232+ ret = -ENOMEM;
1233+ goto err_alloc_nh;
1234+ }
12401235 }
12411236
12421237 for (index = 0; index < edev->max_supported; index++)
@@ -1247,6 +1242,12 @@ int extcon_dev_register(struct extcon_dev *edev) · 4 unmodified lines
12471242 dev_set_drvdata(&edev->dev, edev);
12481243 edev->state = 0;
12491244
1245+ ret = device_register(&edev->dev);
1246+ if (ret) {
1247+ put_device(&edev->dev);
1248+ goto err_dev;
1249+ }
1250+
12501251 mutex_lock(&extcon_dev_list_lock);
12511252 list_add(&edev->entry, &extcon_dev_list);
12521253 mutex_unlock(&extcon_dev_list_lock);
@@ -1254,6 +1255,9 @@ int extcon_dev_register(struct extcon_dev *edev) · 1 unmodified line
12541255 return 0;
12551256
12561257 err_dev:
1258+ if (edev->max_supported)
1259+ kfree(edev->nh);
1260+err_alloc_nh:
12571261 if (edev->max_supported)
12581262 kfree(edev->extcon_dev_type.groups);
12591263 err_alloc_groups:
@@ -1314,6 +1318,7 @@ void extcon_dev_unregister(struct extcon_dev *edev) · 54 unmodified lines
13141318 if (edev->max_supported) {
13151319 kfree(edev->extcon_dev_type.groups);
13161320 kfree(edev->cables);
1321+ kfree(edev->nh);
13171322 }
13181323
13191324 put_device(&edev->dev);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t