Commit 014714b8 authored by Kirill Yatsenko's avatar Kirill Yatsenko Committed by Guenter Roeck
Browse files

hwmon: (aht10) Refactor aht10_read_values function



Exit from the function immediately if the poll time hasn't yet expired.
Therefore the code after the check can be moved one tab to the left which
improves readability.

Signed-off-by: default avatarKirill Yatsenko <kiriyatsenko@gmail.com>
Link: https://lore.kernel.org/r/20230511202633.299174-2-kiriyatsenko@gmail.com


[groeck: Dropped else after return]
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 0cb01ec3
Loading
Loading
Loading
Loading
+35 −33
Original line number Diff line number Diff line
@@ -135,22 +135,24 @@ static int aht10_read_values(struct aht10_data *data)
	struct i2c_client *client = data->client;

	mutex_lock(&data->lock);
	if (aht10_polltime_expired(data)) {
	if (!aht10_polltime_expired(data)) {
		mutex_unlock(&data->lock);
		return 0;
	}

	res = i2c_master_send(client, cmd_meas, sizeof(cmd_meas));
	if (res < 0) {
		mutex_unlock(&data->lock);
		return res;
	}

		usleep_range(AHT10_MEAS_DELAY,
			     AHT10_MEAS_DELAY + AHT10_DELAY_EXTRA);
	usleep_range(AHT10_MEAS_DELAY, AHT10_MEAS_DELAY + AHT10_DELAY_EXTRA);

	res = i2c_master_recv(client, raw_data, AHT10_MEAS_SIZE);
	if (res != AHT10_MEAS_SIZE) {
		mutex_unlock(&data->lock);
		if (res >= 0)
			return -ENODATA;
			else
		return res;
	}

@@ -168,7 +170,7 @@ static int aht10_read_values(struct aht10_data *data)
	data->temperature = (int)temp - 50000;
	data->humidity = hum;
	data->previous_poll_time = ktime_get_boottime();
	}

	mutex_unlock(&data->lock);
	return 0;
}