Skip to content

Commit 0cf321c

Browse files
dlezcanorafaeljw
authored andcommitted
thermal/drivers/tegra: Remove unneeded lock when setting a trip point
The function tegra_tsensor_enable_hw_channel() takes the thermal zone lock to prevent "a potential" race with a call to set_trips() callback. The driver must not play with the thermal framework core code internals. The tegra_tsensor_enable_hw_channel() is called by: - the suspend / resume callbacks - the probe function after the thermal zones are registered The thermal zone lock taken in this function is supposed to protect from a call to the set_trips() callback which writes in the same register. The potential race is when suspend / resume are called at the same time as set_trips. This one is called only in thermal_zone_device_update(). - At suspend time, the 'in_suspend' is set, thus the thermal_zone_device_update() bails out immediately and set_trips is not called during this moment. - At resume time, the thermal zone is updated at PM_POST_SUSPEND, thus the driver has already set the TH2 temperature. - At probe time, we register the thermal zone and then we set the TH2. The only scenario I can see so far is the interrupt fires, the thermal_zone_update() is called exactly at the moment tegra_tsensor_enable_hw_channel() a few lines after registering it. Enable the channels before setting up the interrupt. We close the potential race window without using the thermal zone's lock. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Suggested-by: Thierry Reding <thierry.reding@gmail.com> Acked-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent ec2c8aa commit 0cf321c

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

drivers/thermal/tegra/tegra30-tsensor.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
359359

360360
tegra_tsensor_get_hw_channel_trips(tzd, &hot_trip, &crit_trip);
361361

362-
/* prevent potential racing with tegra_tsensor_set_trips() */
363-
mutex_lock(&tzd->lock);
364-
365362
dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n",
366363
id, DIV_ROUND_CLOSEST(crit_trip, 1000));
367364

@@ -404,8 +401,6 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
404401
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG0_INTR_THERMAL_RST_EN, 1);
405402
writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG0);
406403

407-
mutex_unlock(&tzd->lock);
408-
409404
err = thermal_zone_device_enable(tzd);
410405
if (err) {
411406
dev_err(ts->dev, "ch%u: failed to enable zone: %d\n", id, err);
@@ -585,19 +580,27 @@ static int tegra_tsensor_probe(struct platform_device *pdev)
585580
return err;
586581
}
587582

583+
/*
584+
* Enable the channels before setting the interrupt so
585+
* set_trips() can not be called while we are setting up the
586+
* register TSENSOR_SENSOR0_CONFIG1. With this we close a
587+
* potential race window where we are setting up the TH2 and
588+
* the temperature hits TH1 resulting to an update of the
589+
* TSENSOR_SENSOR0_CONFIG1 register in the ISR.
590+
*/
591+
for (i = 0; i < ARRAY_SIZE(ts->ch); i++) {
592+
err = tegra_tsensor_enable_hw_channel(ts, i);
593+
if (err)
594+
return err;
595+
}
596+
588597
err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
589598
tegra_tsensor_isr, IRQF_ONESHOT,
590599
"tegra_tsensor", ts);
591600
if (err)
592601
return dev_err_probe(&pdev->dev, err,
593602
"failed to request interrupt\n");
594603

595-
for (i = 0; i < ARRAY_SIZE(ts->ch); i++) {
596-
err = tegra_tsensor_enable_hw_channel(ts, i);
597-
if (err)
598-
return err;
599-
}
600-
601604
return 0;
602605
}
603606

0 commit comments

Comments
 (0)