Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix so module can be unloaded and loaded cleanly #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions thinkpad-wmi-master/drivers/platform/x86/think-lmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ struct think_lmi {
struct dev_ext_attribute *devattrs;
struct think_lmi_debug debug;
struct cdev c_dev;
struct device *tlmi_device;
};

static dev_t tlmi_dev;
Expand Down Expand Up @@ -1307,7 +1308,6 @@ static int think_lmi_debugfs_init(struct think_lmi *think)
static void think_lmi_chardev_initialize(struct think_lmi *think)
{
int ret;
struct device *dev_ret;

ret = alloc_chrdev_region(&tlmi_dev, 0, TLMI_NUM_DEVICES, TLMI_NAME);
if (ret < 0) {
Expand All @@ -1324,22 +1324,31 @@ static void think_lmi_chardev_initialize(struct think_lmi *think)
return;
}

tlmi_class = class_create(THIS_MODULE, "char");
tlmi_class = class_create(THIS_MODULE, "tlmi");
if (IS_ERR(tlmi_class)) {
pr_warn("tlmi: char dev class creation failed\n");
cdev_del(&think->c_dev);
unregister_chrdev_region(tlmi_dev, TLMI_NUM_DEVICES);
return;
}
dev_ret = device_create(tlmi_class, NULL, tlmi_dev, NULL, "thinklmi");
if (IS_ERR(dev_ret)) {
think->tlmi_device = device_create(tlmi_class, NULL, tlmi_dev, NULL,
"thinklmi");
if (IS_ERR(think->tlmi_device)) {
pr_warn("tlmi: char dev device creation failed\n");
class_destroy(tlmi_class);
cdev_del(&think->c_dev);
unregister_chrdev_region(tlmi_dev, TLMI_NUM_DEVICES);
}
}

static void think_lmi_chardev_exit(struct think_lmi *think)
{
device_del(think->tlmi_device);
class_destroy(tlmi_class);
cdev_del(&think->c_dev);
unregister_chrdev_region(tlmi_dev, TLMI_NUM_DEVICES);
}

/* Base driver */
static void think_lmi_analyze(struct think_lmi *think)
{
Expand Down Expand Up @@ -1442,12 +1451,12 @@ static int think_lmi_remove(struct wmi_device *wdev)
think = dev_get_drvdata(&wdev->dev);
think_lmi_debugfs_exit(think);
think_lmi_platform_exit(think);
think_lmi_chardev_exit(think);

for (i = 0; think->settings[i]; ++i) {
kfree(think->settings[i]);
think->settings[i] = NULL;
}

kfree(think);
return 0;
}
Expand Down