Commit 33a470f6 authored by Jean Delvare's avatar Jean Delvare Committed by Benjamin Herrenschmidt

macintosh/therm_adt746x: Fix sysfs attributes lifetime

Looking at drivers/macintosh/therm_adt746x.c, the sysfs files are
created in thermostat_init() and removed in thermostat_exit(), which
are the driver's init and exit functions. These files are backed-up by
a per-device structure, so it looks like the wrong thing to do: the
sysfs files have a lifetime longer than the data structure that is
backing it up.

I think that sysfs files creation should be moved to the end of
probe_thermostat() and sysfs files removal should be moved to the
beginning of remove_thermostat().
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Tested-by: default avatarChristian Kujau <lists@nerdbynature.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Colin Leroy <colin@colino.net>
Cc: stable@kernel.org
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 119ea109
...@@ -90,6 +90,8 @@ static struct task_struct *thread_therm = NULL; ...@@ -90,6 +90,8 @@ static struct task_struct *thread_therm = NULL;
static void write_both_fan_speed(struct thermostat *th, int speed); static void write_both_fan_speed(struct thermostat *th, int speed);
static void write_fan_speed(struct thermostat *th, int speed, int fan); static void write_fan_speed(struct thermostat *th, int speed, int fan);
static void thermostat_create_files(void);
static void thermostat_remove_files(void);
static int static int
write_reg(struct thermostat* th, int reg, u8 data) write_reg(struct thermostat* th, int reg, u8 data)
...@@ -161,6 +163,8 @@ remove_thermostat(struct i2c_client *client) ...@@ -161,6 +163,8 @@ remove_thermostat(struct i2c_client *client)
struct thermostat *th = i2c_get_clientdata(client); struct thermostat *th = i2c_get_clientdata(client);
int i; int i;
thermostat_remove_files();
if (thread_therm != NULL) { if (thread_therm != NULL) {
kthread_stop(thread_therm); kthread_stop(thread_therm);
} }
...@@ -449,6 +453,8 @@ static int probe_thermostat(struct i2c_client *client, ...@@ -449,6 +453,8 @@ static int probe_thermostat(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
} }
thermostat_create_files();
return 0; return 0;
} }
...@@ -566,7 +572,6 @@ thermostat_init(void) ...@@ -566,7 +572,6 @@ thermostat_init(void)
struct device_node* np; struct device_node* np;
const u32 *prop; const u32 *prop;
int i = 0, offset = 0; int i = 0, offset = 0;
int err;
np = of_find_node_by_name(NULL, "fan"); np = of_find_node_by_name(NULL, "fan");
if (!np) if (!np)
...@@ -633,6 +638,17 @@ thermostat_init(void) ...@@ -633,6 +638,17 @@ thermostat_init(void)
return -ENODEV; return -ENODEV;
} }
#ifndef CONFIG_I2C_POWERMAC
request_module("i2c-powermac");
#endif
return i2c_add_driver(&thermostat_driver);
}
static void thermostat_create_files(void)
{
int err;
err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature); err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature);
err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature); err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature);
err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit); err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit);
...@@ -647,16 +663,9 @@ thermostat_init(void) ...@@ -647,16 +663,9 @@ thermostat_init(void)
if (err) if (err)
printk(KERN_WARNING printk(KERN_WARNING
"Failed to create tempertaure attribute file(s).\n"); "Failed to create tempertaure attribute file(s).\n");
#ifndef CONFIG_I2C_POWERMAC
request_module("i2c-powermac");
#endif
return i2c_add_driver(&thermostat_driver);
} }
static void __exit static void thermostat_remove_files(void)
thermostat_exit(void)
{ {
if (of_dev) { if (of_dev) {
device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature); device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature);
...@@ -673,9 +682,14 @@ thermostat_exit(void) ...@@ -673,9 +682,14 @@ thermostat_exit(void)
device_remove_file(&of_dev->dev, device_remove_file(&of_dev->dev,
&dev_attr_sensor2_fan_speed); &dev_attr_sensor2_fan_speed);
of_device_unregister(of_dev);
} }
}
static void __exit
thermostat_exit(void)
{
i2c_del_driver(&thermostat_driver); i2c_del_driver(&thermostat_driver);
of_device_unregister(of_dev);
} }
module_init(thermostat_init); module_init(thermostat_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment