drm/etnaviv: Fix driver unregistering
Subsystems (3)
PATCH v2 1/1 drm/etnaviv: Fix driver unregistering
From: Fabio Estevam <[email protected]>
Russell King reported:
"When removing and reloading the etnaviv module, the following splat occurs:
sysfs: cannot create duplicate filename '/devices/platform/etnaviv'
CPU: 0 PID: 1471 Comm: modprobe Not tainted 4.17.0+ #1608 Hardware name: Marvell Dove (Cubox) Backtrace: [<c00157d4>] (dump_backtrace) from [<c0015b8c>] (show_stack+0x18/0x1c) r6:ef033e38 r5:ee07b340 r4:edb9d000 r3:00000000 [<c0015b74>] (show_stack) from [<c0620784>] (dump_stack+0x20/0x28) [<c0620764>] (dump_stack) from [<c01bcd24>] (sysfs_warn_dup+0x5c/0x70) [<c01bccc8>] (sysfs_warn_dup) from [<c01bce14>] (sysfs_create_dir_ns+0x90/0x98)
..."
Commit 246774d17fc0 ("drm/etnaviv: remove the need for a gpu-subsystem DT node") introduced DRM registration via platform_device_register_simple(), but missed to call platform_device_unregister() inside etnaviv_exit().
Fix the problem by calling platform_device_unregister() inside etnaviv_exit(). While at it, also rearrange the function calls in the exit path to make them happen in the opposite order of registration.
Tested on a imx6-sabresd board.
---
Changes since v1:
- Make the exit path symmetrical to the init path by calling platform_device_unregister() inside for_each_compatible_node()
drivers/gpu/drm/etnaviv/etnaviv_drv.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_drv.c +16 -2
@@ -631,6 +631,8 @@ static struct platform_driver etnaviv_platform_driver = { }, }; +static struct platform_device *etnaviv_drm; +static int __init etnaviv_init (void ) {int ret;
@@ -654,7 +656,8 @@ static int __init etnaviv_init(void)if (!of_device_is_available (np))continue ; -platform_device_register_simple ("etnaviv" ,-1 ,NULL ,0 ); + etnaviv_drm =platform_device_register_simple ("etnaviv" ,-1 , +NULL ,0 );of_node_put (np);break ; }
@@ -665,8 +668,19 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { -platform_driver_unregister (&etnaviv_gpu_driver); +struct device_node *np; + +for_each_compatible_node (np,NULL ,"vivante,gc" ) { +if (!of_device_is_available (np)) +continue ; + +platform_device_unregister (etnaviv_drm); +of_node_put (np); +break ; + } +platform_driver_unregister (&etnaviv_platform_driver); +platform_driver_unregister (&etnaviv_gpu_driver); }module_exit (etnaviv_exit);
Signature · 1 line
2.7.4
Hi Fabio,
Quoted 56 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Russell King reported:
"When removing and reloading the etnaviv module, the following splat occurs:
sysfs: cannot create duplicate filename '/devices/platform/etnaviv'
CPU: 0 PID: 1471 Comm: modprobe Not tainted 4.17.0+ #1608 Hardware name: Marvell Dove (Cubox) Backtrace: [<c00157d4>] (dump_backtrace) from [<c0015b8c>] (show_stack+0x18/0x1c) r6:ef033e38 r5:ee07b340 r4:edb9d000 r3:00000000 [<c0015b74>] (show_stack) from [<c0620784>] (dump_stack+0x20/0x28) [<c0620764>] (dump_stack) from [<c01bcd24>] (sysfs_warn_dup+0x5c/0x70) [<c01bccc8>] (sysfs_warn_dup) from [<c01bce14>] (sysfs_create_dir_ns+0x90/0x98)..."
Commit
246774d17fc0("drm/etnaviv: remove the need for a gpu-subsystem DT node") introduced DRM registration viaplatform_device_register_simple(), but missed to callplatform_device_unregister()insideetnaviv_exit().Fix the problem by calling
platform_device_unregister()insideetnaviv_exit(). While at it, also rearrange the function calls in the exit path to make them happen in the opposite order of registration.Tested on a imx6-sabresd board.
Cc <[email protected]>Fixes 246774d17fc0 ("drm/etnaviv: remove the need for a gpu-subsystem DT node")Reported-by Russell King <[email protected]>Signed-off-by Fabio Estevam <[email protected]>---
Changes since v1:
- Make the exit path symmetrical to the init path by callingplatform_device_unregister()insidefor_each_compatible_node()drivers/gpu/drm/etnaviv/etnaviv_drv.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/gpu/drm/etnaviv/etnaviv_drv.c +2
-0@@ -631,6 +631,8 @@ static struct platform_driver etnaviv_platform_driver = { }, }; +static struct platform_device *etnaviv_drm; +static int __init etnaviv_init (void ) {int ret;
drivers/gpu/drm/etnaviv/etnaviv_drv.c static int __init etnaviv_init(void) · line 660
Quoted 6 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c +2
-1@@ -654,7 +656,8 @@ static int __init etnaviv_init(void)if (!of_device_is_available (np))continue ; -platform_device_register_simple ("etnaviv" ,-1 ,NULL ,0 ); + etnaviv_drm =platform_device_register_simple ("etnaviv" ,-1 , +NULL ,0 );
If there are multiple vivante,gc device nodes, this overwrites etnaviv_drm with each additional device after the first one.
Also, it would be better to store NULL instead of the error value.
Quoted 5 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c +0
-0of_node_put (np);break ; }@@ -665,8 +668,19 @@ module_init(etnaviv_init);
drivers/gpu/drm/etnaviv/etnaviv_drv.c module_init(etnaviv_init); · line 677
Quoted 10 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c +7
-1static void __exit etnaviv_exit(void) { -platform_driver_unregister (&etnaviv_gpu_driver); +struct device_node *np; + +for_each_compatible_node (np,NULL ,"vivante,gc" ) { +if (!of_device_is_available (np)) +continue ; + +platform_device_unregister (etnaviv_drm);
If there are multiple vivante,gc nodes, this will try to unregister the last device multiple times. Also, this will break if the pointer contains an error value.
drivers/gpu/drm/etnaviv/etnaviv_drv.c module_init(etnaviv_init); · line 686
Quoted 9 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c +5
-0+of_node_put (np); +break ; + } +platform_driver_unregister (&etnaviv_platform_driver); +platform_driver_unregister (&etnaviv_gpu_driver); }module_exit (etnaviv_exit);
regards
Philipp
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Philipp,
Quoted 9 lines · Philipp Zabel
Quoted 9 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c +2
-0+static struct platform_device *etnaviv_drm; +static int __init etnaviv_init (void ) {int ret;@@ -654,7 +656,8 @@ static int __init etnaviv_init(void)if (!of_device_is_available (np))continue ;
Quoted 6 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c static int __init etnaviv_init(void) · line 660
Quoted 3 lines
drivers/gpu/drm/etnaviv/etnaviv_drv.c +2
-1-platform_device_register_simple ("etnaviv" ,-1 ,NULL ,0 ); + etnaviv_drm =platform_device_register_simple ("etnaviv" ,-1 , +NULL ,0 );If there are multiple vivante,gc device nodes, this overwrites
etnaviv_drmwith each additional device after the first one.
In fact there are multiple vivante,gc device nodes, but platform_device_register_simple() is only called once as expected.
I will make this clear and will also check for the error code on platform_device_register_simple().
Thanks