Skip to contentSkip to conversation

drm/sysfs: Do not drop device reference twice

PATCH In review Thierry Reding 3 participants 4 messages Oct 30, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/sysfs: Do not drop device reference twice

device_unregister() already drops its reference to the struct device, so explicitly calling put_device() before device_unregister() can cause the device to have been freed before it can be unregistered.

---
 drivers/gpu/drm/drm_sysfs.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_sysfs.c +0 -2
index dae42c7..db1c8f9 100644
@@ -439,7 +439,6 @@ err_out_files:
 		device_remove_file(connector->kdev, &connector_attrs_opt1[i]);
 	for (i = 0; i < attr_cnt; i++)
 		device_remove_file(connector->kdev, &connector_attrs[i]);
-	put_device(connector->kdev);
 	device_unregister(connector->kdev);
 
 out:
@@ -472,7 +471,6 @@ void drm_sysfs_connector_remove(struct drm_connector *connector)
 	for (i = 0; i < ARRAY_SIZE(connector_attrs); i++)
 		device_remove_file(connector->kdev, &connector_attrs[i]);
 	sysfs_remove_bin_file(&connector->kdev->kobj, &edid_attr);
-	put_device(connector->kdev);
 	device_unregister(connector->kdev);
 	connector->kdev = NULL;
 }
Signature · 1 line
1.8.4
Reviewed-by Tested-by on v1 1/1
#1 lore raw

2013/10/30 Thierry Reding <[email protected]>:

Quoted 5 lines

device_unregister() already drops its reference to the struct device, so explicitly calling put_device() before device_unregister() can cause the device to have been freed before it can be unregistered.

I started investigating this problem yesterday and reached the same conclusion. The connector path can be easily reproduced on i915.ko:
get a machine that has an eDP panel, physically disconnect the panel, boot the machine, "modprobe i915" and watch the segfault.

I didn't really bisect, but I believe this is probably a regression from "drm/sysfs: sort out minor and connector device object lifetimes".

And kudos to whoever invented CONFIG_DEBUG_KOBJECT :)

Quoted 31 lines
---
 drivers/gpu/drm/drm_sysfs.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_sysfs.c +0 -3
index dae42c7..db1c8f9 100644
@@ -439,7 +439,6 @@ err_out_files:
                device_remove_file(connector->kdev, &connector_attrs_opt1[i]);
        for (i = 0; i < attr_cnt; i++)
                device_remove_file(connector->kdev, &connector_attrs[i]);
-       put_device(connector->kdev);
        device_unregister(connector->kdev);
 
 out:
@@ -472,7 +471,6 @@ void drm_sysfs_connector_remove(struct drm_connector *connector)
        for (i = 0; i < ARRAY_SIZE(connector_attrs); i++)
                device_remove_file(connector->kdev, &connector_attrs[i]);
        sysfs_remove_bin_file(&connector->kdev->kobj, &edid_attr);
-       put_device(connector->kdev);
        device_unregister(connector->kdev);
        connector->kdev = NULL;
 }
--

1.8.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 1 line
Paulo Zanoni
#2 lore raw
Quoted 12 lines · Paulo Zanoni

2013/10/30 Thierry Reding <[email protected]>:

Quoted 5 lines

device_unregister() already drops its reference to the struct device, so explicitly calling put_device() before device_unregister() can cause the device to have been freed before it can be unregistered.

I started investigating this problem yesterday and reached the same conclusion. The connector path can be easily reproduced on i915.ko:
get a machine that has an eDP panel, physically disconnect the panel, boot the machine, "modprobe i915" and watch the segfault.

Quoted 6 lines

I didn't really bisect, but I believe this is probably a regression from "drm/sysfs: sort out minor and connector device object lifetimes".

Yes, I think that's the one that broke it.

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Tested-by on v1 1/1
#3 lore raw
In reply to Thierry Reding
Quoted 5 lines · Thierry Reding

device_unregister() already drops its reference to the struct device, so explicitly calling put_device() before device_unregister() can cause the device to have been freed before it can be unregistered.

Thanks for fixing this. It was driving me nuts.

[snip]

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center