ACPI: Add the reference count to avoid unloading ACPI video bus twice

Sometimes both acpi video and i915 driver are compiled as modules.
And there exists the strict dependency between the two drivers.
The acpi video bus will be unloaded in course of unloading the i915 driver.
If we unload the acpi video driver, then the kernel oops will be triggered.

Add the reference count to avoid unloading the ACPI video bus twice.
The reference count should be checked before unregistering the acpi video bus.
If the reference count is already zero, it won't unregister it again.
And after the acpi video bus is already unregistered, the reference count
will be set to zero.

http://bugzilla.kernel.org/show_bug.cgi?id=13396

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Acked-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Zhao Yakui 2009-06-16 11:23:13 +08:00 committed by Len Brown
parent 07a2039b8e
commit 86e437f077
3 changed files with 38 additions and 9 deletions

View File

@ -76,6 +76,7 @@ MODULE_LICENSE("GPL");
static int brightness_switch_enabled = 1; static int brightness_switch_enabled = 1;
module_param(brightness_switch_enabled, bool, 0644); module_param(brightness_switch_enabled, bool, 0644);
static int register_count = 0;
static int acpi_video_bus_add(struct acpi_device *device); static int acpi_video_bus_add(struct acpi_device *device);
static int acpi_video_bus_remove(struct acpi_device *device, int type); static int acpi_video_bus_remove(struct acpi_device *device, int type);
static int acpi_video_resume(struct acpi_device *device); static int acpi_video_resume(struct acpi_device *device);
@ -2318,6 +2319,13 @@ static int __init intel_opregion_present(void)
int acpi_video_register(void) int acpi_video_register(void)
{ {
int result = 0; int result = 0;
if (register_count) {
/*
* if the function of acpi_video_register is already called,
* don't register the acpi_vide_bus again and return no error.
*/
return 0;
}
acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
if (!acpi_video_dir) if (!acpi_video_dir)
@ -2329,10 +2337,35 @@ int acpi_video_register(void)
return -ENODEV; return -ENODEV;
} }
/*
* When the acpi_video_bus is loaded successfully, increase
* the counter reference.
*/
register_count = 1;
return 0; return 0;
} }
EXPORT_SYMBOL(acpi_video_register); EXPORT_SYMBOL(acpi_video_register);
void acpi_video_unregister(void)
{
if (!register_count) {
/*
* If the acpi video bus is already unloaded, don't
* unload it again and return directly.
*/
return;
}
acpi_bus_unregister_driver(&acpi_video_bus);
remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
register_count = 0;
return;
}
EXPORT_SYMBOL(acpi_video_unregister);
/* /*
* This is kind of nasty. Hardware using Intel chipsets may require * This is kind of nasty. Hardware using Intel chipsets may require
* the video opregion code to be run first in order to initialise * the video opregion code to be run first in order to initialise
@ -2350,16 +2383,12 @@ static int __init acpi_video_init(void)
return acpi_video_register(); return acpi_video_register();
} }
void acpi_video_exit(void) static void __exit acpi_video_exit(void)
{ {
acpi_video_unregister();
acpi_bus_unregister_driver(&acpi_video_bus);
remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
return; return;
} }
EXPORT_SYMBOL(acpi_video_exit);
module_init(acpi_video_init); module_init(acpi_video_init);
module_exit(acpi_video_exit); module_exit(acpi_video_exit);

View File

@ -419,7 +419,7 @@ void intel_opregion_free(struct drm_device *dev, int suspend)
return; return;
if (!suspend) if (!suspend)
acpi_video_exit(); acpi_video_unregister();
opregion->acpi->drdy = 0; opregion->acpi->drdy = 0;

View File

@ -3,10 +3,10 @@
#if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE) #if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE)
extern int acpi_video_register(void); extern int acpi_video_register(void);
extern int acpi_video_exit(void); extern void acpi_video_unregister(void);
#else #else
static inline int acpi_video_register(void) { return 0; } static inline int acpi_video_register(void) { return 0; }
static inline void acpi_video_exit(void) { return; } static inline void acpi_video_unregister(void) { return; }
#endif #endif
#endif #endif