summaryrefslogtreecommitdiff
path: root/drivers/misc/m4sensorhub_heartrate.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/m4sensorhub_heartrate.c')
-rw-r--r--drivers/misc/m4sensorhub_heartrate.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/drivers/misc/m4sensorhub_heartrate.c b/drivers/misc/m4sensorhub_heartrate.c
index 8f6ea2f1648..a35be957f15 100644
--- a/drivers/misc/m4sensorhub_heartrate.c
+++ b/drivers/misc/m4sensorhub_heartrate.c
@@ -315,35 +315,19 @@ static int m4hrt_driver_init(struct init_calldata *p_arg)
goto m4hrt_driver_init_fail;
}
- err = m4hrt_create_iiodev(iio);
- if (err < 0) {
- m4hrt_err("%s: Failed to create IIO device.\n", __func__);
- goto m4hrt_driver_init_fail;
- }
-
err = m4sensorhub_irq_register(dd->m4,
M4SH_IRQ_HEARTRATESENSOR_DATA_READY, m4hrt_isr, iio);
if (err < 0) {
m4hrt_err("%s: Failed to register M4 IRQ.\n", __func__);
- goto m4hrt_driver_init_irq_fail;
+ goto m4hrt_driver_init_fail;
}
- /*
- * NOTE: We're intentionally unlocking here instead of
- * at function end (after error cases). The reason
- * is that the mutex ceases to exist because IIO is
- * freed, so we would cause a panic putting the unlock
- * after m4hrt_driver_init_exit.
- */
- mutex_unlock(&(dd->mutex));
-
goto m4hrt_driver_init_exit;
-m4hrt_driver_init_irq_fail:
- m4hrt_remove_iiodev(iio); /* dd is freed here */
m4hrt_driver_init_fail:
m4hrt_err("%s: Init failed with error code %d.\n", __func__, err);
m4hrt_driver_init_exit:
+ mutex_unlock(&(dd->mutex));
return err;
}
@@ -366,6 +350,12 @@ static int m4hrt_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, iio);
dd->samplerate = -1; /* We always start disabled */
+ err = m4hrt_create_iiodev(iio); /* iio and dd are freed on fail */
+ if (err < 0) {
+ m4hrt_err("%s: Failed to create IIO device.\n", __func__);
+ goto m4hrt_probe_fail_noiio;
+ }
+
err = m4sensorhub_register_initcall(m4hrt_driver_init, iio);
if (err < 0) {
m4hrt_err("%s: Failed to register initcall.\n", __func__);
@@ -376,7 +366,7 @@ static int m4hrt_probe(struct platform_device *pdev)
m4hrt_probe_fail:
mutex_destroy(&(dd->mutex));
- iio_device_free(iio); /* dd is freed here */
+ m4hrt_remove_iiodev(iio); /* iio and dd are freed here */
m4hrt_probe_fail_noiio:
m4hrt_err("%s: Probe failed with error code %d.\n", __func__, err);
return err;