Skip to content

Commit 17a2f46

Browse files
klock-androidjic23
authored andcommitted
iio: dht11: Use boottime
Wall time obtained from ktime_get_real_ns is susceptible to sudden jumps due to user setting the time or due to NTP. Boot time is constantly increasing time better suited for comparing two timestamps. Signed-off-by: Abhilash Jindal <[email protected]> Reviewed-by: Harald Geyer <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent ddeb35c commit 17a2f46

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/iio/humidity/dht11.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int dht11_decode(struct dht11 *dht11, int offset, int timeres)
117117
if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum)
118118
return -EIO;
119119

120-
dht11->timestamp = ktime_get_real_ns();
120+
dht11->timestamp = ktime_get_boot_ns();
121121
if (hum_int < 20) { /* DHT22 */
122122
dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
123123
((temp_int & 0x80) ? -100 : 100);
@@ -145,7 +145,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
145145

146146
/* TODO: Consider making the handler safe for IRQ sharing */
147147
if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
148-
dht11->edges[dht11->num_edges].ts = ktime_get_real_ns();
148+
dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns();
149149
dht11->edges[dht11->num_edges++].value =
150150
gpio_get_value(dht11->gpio);
151151

@@ -164,7 +164,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
164164
int ret, timeres;
165165

166166
mutex_lock(&dht11->lock);
167-
if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) {
167+
if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) {
168168
timeres = ktime_get_resolution_ns();
169169
if (DHT11_DATA_BIT_HIGH < 2 * timeres) {
170170
dev_err(dht11->dev, "timeresolution %dns too low\n",
@@ -279,7 +279,7 @@ static int dht11_probe(struct platform_device *pdev)
279279
return -EINVAL;
280280
}
281281

282-
dht11->timestamp = ktime_get_real_ns() - DHT11_DATA_VALID_TIME - 1;
282+
dht11->timestamp = ktime_get_boot_ns() - DHT11_DATA_VALID_TIME - 1;
283283
dht11->num_edges = -1;
284284

285285
platform_set_drvdata(pdev, iio);

0 commit comments

Comments
 (0)