firmware: gsmi: remove sysfs entries when unload the module

This patch removes sysfs entries in gsmi_exit() and gsmi_init() error path.

Also move the driver successfully loaded message to the end of gsmi_init()
and return proper error if register_efivars() fails.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Axel Lin 2011-06-29 15:57:53 +08:00 committed by Greg Kroah-Hartman
parent 48d9854285
commit 1e4de81653

View File

@ -869,8 +869,6 @@ static __init int gsmi_init(void)
goto out_err; goto out_err;
} }
printk(KERN_INFO "gsmi version " DRIVER_VERSION " loaded\n");
/* Register in the firmware directory */ /* Register in the firmware directory */
ret = -ENOMEM; ret = -ENOMEM;
gsmi_kobj = kobject_create_and_add("gsmi", firmware_kobj); gsmi_kobj = kobject_create_and_add("gsmi", firmware_kobj);
@ -890,12 +888,13 @@ static __init int gsmi_init(void)
ret = sysfs_create_files(gsmi_kobj, gsmi_attrs); ret = sysfs_create_files(gsmi_kobj, gsmi_attrs);
if (ret) { if (ret) {
printk(KERN_INFO "gsmi: Failed to add attrs"); printk(KERN_INFO "gsmi: Failed to add attrs");
goto out_err; goto out_remove_bin_file;
} }
if (register_efivars(&efivars, &efivar_ops, gsmi_kobj)) { ret = register_efivars(&efivars, &efivar_ops, gsmi_kobj);
if (ret) {
printk(KERN_INFO "gsmi: Failed to register efivars\n"); printk(KERN_INFO "gsmi: Failed to register efivars\n");
goto out_err; goto out_remove_sysfs_files;
} }
register_reboot_notifier(&gsmi_reboot_notifier); register_reboot_notifier(&gsmi_reboot_notifier);
@ -903,9 +902,15 @@ static __init int gsmi_init(void)
atomic_notifier_chain_register(&panic_notifier_list, atomic_notifier_chain_register(&panic_notifier_list,
&gsmi_panic_notifier); &gsmi_panic_notifier);
printk(KERN_INFO "gsmi version " DRIVER_VERSION " loaded\n");
return 0; return 0;
out_err: out_remove_sysfs_files:
sysfs_remove_files(gsmi_kobj, gsmi_attrs);
out_remove_bin_file:
sysfs_remove_bin_file(gsmi_kobj, &eventlog_bin_attr);
out_err:
kobject_put(gsmi_kobj); kobject_put(gsmi_kobj);
gsmi_buf_free(gsmi_dev.param_buf); gsmi_buf_free(gsmi_dev.param_buf);
gsmi_buf_free(gsmi_dev.data_buf); gsmi_buf_free(gsmi_dev.data_buf);
@ -925,6 +930,8 @@ static void __exit gsmi_exit(void)
&gsmi_panic_notifier); &gsmi_panic_notifier);
unregister_efivars(&efivars); unregister_efivars(&efivars);
sysfs_remove_files(gsmi_kobj, gsmi_attrs);
sysfs_remove_bin_file(gsmi_kobj, &eventlog_bin_attr);
kobject_put(gsmi_kobj); kobject_put(gsmi_kobj);
gsmi_buf_free(gsmi_dev.param_buf); gsmi_buf_free(gsmi_dev.param_buf);
gsmi_buf_free(gsmi_dev.data_buf); gsmi_buf_free(gsmi_dev.data_buf);