summaryrefslogtreecommitdiff
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorKirill Yatsenko <kiriyatsenko@gmail.com>2023-05-11 23:26:32 +0300
committerGuenter Roeck <linux@roeck-us.net>2023-06-08 16:41:18 +0300
commit014714b8a62107d22bd2a089801bbfb4bb6412ae (patch)
treec74a8042d713a5e43791c96a9a4b3cefd12ae05b /drivers/hwmon
parent0cb01ec31529096b6460290963bf78c9146d83b7 (diff)
downloadlinux-014714b8a62107d22bd2a089801bbfb4bb6412ae.tar.xz
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: Kirill Yatsenko <kiriyatsenko@gmail.com> Link: https://lore.kernel.org/r/20230511202633.299174-2-kiriyatsenko@gmail.com [groeck: Dropped else after return] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/aht10.c68
1 files changed, 35 insertions, 33 deletions
diff --git a/drivers/hwmon/aht10.c b/drivers/hwmon/aht10.c
index 4ccf49c7cc8c..ec7459575c58 100644
--- a/drivers/hwmon/aht10.c
+++ b/drivers/hwmon/aht10.c
@@ -135,40 +135,42 @@ static int aht10_read_values(struct aht10_data *data)
struct i2c_client *client = data->client;
mutex_lock(&data->lock);
- if (aht10_polltime_expired(data)) {
- 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);
-
- 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;
- }
-
- hum = ((u32)raw_data[1] << 12u) |
- ((u32)raw_data[2] << 4u) |
- ((raw_data[3] & 0xF0u) >> 4u);
-
- temp = ((u32)(raw_data[3] & 0x0Fu) << 16u) |
- ((u32)raw_data[4] << 8u) |
- raw_data[5];
-
- temp = ((temp * 625) >> 15u) * 10;
- hum = ((hum * 625) >> 16u) * 10;
-
- data->temperature = (int)temp - 50000;
- data->humidity = hum;
- data->previous_poll_time = ktime_get_boottime();
+ 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);
+
+ res = i2c_master_recv(client, raw_data, AHT10_MEAS_SIZE);
+ if (res != AHT10_MEAS_SIZE) {
+ mutex_unlock(&data->lock);
+ if (res >= 0)
+ return -ENODATA;
+ return res;
+ }
+
+ hum = ((u32)raw_data[1] << 12u) |
+ ((u32)raw_data[2] << 4u) |
+ ((raw_data[3] & 0xF0u) >> 4u);
+
+ temp = ((u32)(raw_data[3] & 0x0Fu) << 16u) |
+ ((u32)raw_data[4] << 8u) |
+ raw_data[5];
+
+ temp = ((temp * 625) >> 15u) * 10;
+ hum = ((hum * 625) >> 16u) * 10;
+
+ data->temperature = (int)temp - 50000;
+ data->humidity = hum;
+ data->previous_poll_time = ktime_get_boottime();
+
mutex_unlock(&data->lock);
return 0;
}