Commit 98ceb75c7c14eada76b0aa9f03a635a735cee3cb

Authored by Jean Delvare
Committed by Benjamin Herrenschmidt
1 parent 33a470f6d5

macintosh/hwmon/ams: Fix device removal sequence

Some code that is in ams_exit() (the module exit code) should instead
be called when the device (not module) is removed. It probably doesn't
make much of a difference in the PMU case, but in the I2C case it does
matter.

I make no guarantee that my fix isn't racy, I'm not familiar enough
with the ams driver code to tell for sure.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Christian Kujau <lists@nerdbynature.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Stelian Pop <stelian@popies.net>
Cc: Michael Hanselmann <linux-kernel@hansmi.ch>
Cc: stable@kernel.org
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Showing 4 changed files with 12 additions and 4 deletions Side-by-side Diff

drivers/hwmon/ams/ams-core.c
... ... @@ -213,7 +213,7 @@
213 213 return -ENODEV;
214 214 }
215 215  
216   -void ams_exit(void)
  216 +void ams_sensor_detach(void)
217 217 {
218 218 /* Remove input device */
219 219 ams_input_exit();
... ... @@ -221,9 +221,6 @@
221 221 /* Remove attributes */
222 222 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current);
223 223  
224   - /* Shut down implementation */
225   - ams_info.exit();
226   -
227 224 /* Flush interrupt worker
228 225 *
229 226 * We do this after ams_info.exit(), because an interrupt might
... ... @@ -237,6 +234,12 @@
237 234 /* Remove handler */
238 235 pmf_unregister_irq_client(&ams_shock_client);
239 236 pmf_unregister_irq_client(&ams_freefall_client);
  237 +}
  238 +
  239 +static void __exit ams_exit(void)
  240 +{
  241 + /* Shut down implementation */
  242 + ams_info.exit();
240 243 }
241 244  
242 245 MODULE_AUTHOR("Stelian Pop, Michael Hanselmann");
drivers/hwmon/ams/ams-i2c.c
... ... @@ -238,6 +238,8 @@
238 238 static int ams_i2c_remove(struct i2c_client *client)
239 239 {
240 240 if (ams_info.has_device) {
  241 + ams_sensor_detach();
  242 +
241 243 /* Disable interrupts */
242 244 ams_i2c_set_irq(AMS_IRQ_ALL, 0);
243 245  
drivers/hwmon/ams/ams-pmu.c
... ... @@ -133,6 +133,8 @@
133 133  
134 134 static void ams_pmu_exit(void)
135 135 {
  136 + ams_sensor_detach();
  137 +
136 138 /* Disable interrupts */
137 139 ams_pmu_set_irq(AMS_IRQ_ALL, 0);
138 140  
drivers/hwmon/ams/ams.h
... ... @@ -61,6 +61,7 @@
61 61  
62 62 extern void ams_sensors(s8 *x, s8 *y, s8 *z);
63 63 extern int ams_sensor_attach(void);
  64 +extern void ams_sensor_detach(void);
64 65  
65 66 extern int ams_pmu_init(struct device_node *np);
66 67 extern int ams_i2c_init(struct device_node *np);