Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: accel: kx022a: Use cleanup.h helpers

A few functions in KX022A need to use mutex for protecting the
enabling/disabling of the measurement while configurations are being
made. Some of the functions can be slightly simplified by using the
__cleanup based scoped mutexes, which allows dropping the goto based
unlocking at error path.

Simplify error paths using guard(mutex).

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://patch.msgid.link/4785f841ad5f131356ba78b4f3c76f676d86a2e8.1732783834.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
725521e1 0c39208b

+23 -38
+23 -38
drivers/iio/accel/kionix-kx022a.c
··· 5 5 * ROHM/KIONIX accelerometer driver 6 6 */ 7 7 8 + #include <linux/cleanup.h> 8 9 #include <linux/delay.h> 9 10 #include <linux/device.h> 10 11 #include <linux/interrupt.h> ··· 449 448 *val2 = kx022a_scale_table[val][1]; 450 449 } 451 450 452 - static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on) 451 + static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) 453 452 { 454 453 int ret; 455 454 ··· 470 469 int ret; 471 470 472 471 mutex_lock(&data->mutex); 473 - ret = kx022a_turn_on_off_unlocked(data, false); 472 + ret = __kx022a_turn_on_off(data, false); 474 473 if (ret) 475 474 mutex_unlock(&data->mutex); 476 475 ··· 481 480 { 482 481 int ret; 483 482 484 - ret = kx022a_turn_on_off_unlocked(data, true); 483 + ret = __kx022a_turn_on_off(data, true); 485 484 mutex_unlock(&data->mutex); 486 485 487 486 return ret; ··· 913 912 { 914 913 int ret = 0; 915 914 916 - ret = kx022a_turn_off_lock(data); 915 + guard(mutex)(&data->mutex); 916 + ret = __kx022a_turn_on_off(data, false); 917 917 if (ret) 918 918 return ret; 919 919 920 920 ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI); 921 921 if (ret) 922 - goto unlock_out; 922 + return ret; 923 923 924 924 ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, 925 925 KX022A_MASK_BUF_EN); 926 926 if (ret) 927 - goto unlock_out; 927 + return ret; 928 928 929 929 data->state &= ~KX022A_STATE_FIFO; 930 930 ··· 933 931 934 932 kfree(data->fifo_buffer); 935 933 936 - return kx022a_turn_on_unlock(data); 937 - 938 - unlock_out: 939 - mutex_unlock(&data->mutex); 940 - 941 - return ret; 934 + return __kx022a_turn_on_off(data, true); 942 935 } 943 936 944 937 static int kx022a_buffer_predisable(struct iio_dev *idev) ··· 956 959 if (!data->fifo_buffer) 957 960 return -ENOMEM; 958 961 959 - ret = kx022a_turn_off_lock(data); 962 + guard(mutex)(&data->mutex); 963 + ret = __kx022a_turn_on_off(data, false); 960 964 if (ret) 961 965 return ret; 962 966 963 967 /* Update watermark to HW */ 964 968 ret = kx022a_fifo_set_wmi(data); 965 969 if (ret) 966 - goto unlock_out; 970 + return ret; 967 971 968 972 /* Enable buffer */ 969 973 ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, 970 974 KX022A_MASK_BUF_EN); 971 975 if (ret) 972 - goto unlock_out; 976 + return ret; 973 977 974 978 data->state |= KX022A_STATE_FIFO; 975 979 ret = regmap_set_bits(data->regmap, data->ien_reg, 976 980 KX022A_MASK_WMI); 977 981 if (ret) 978 - goto unlock_out; 982 + return ret; 979 983 980 - return kx022a_turn_on_unlock(data); 981 - 982 - unlock_out: 983 - mutex_unlock(&data->mutex); 984 - 985 - return ret; 984 + return __kx022a_turn_on_off(data, true); 986 985 } 987 986 988 987 static int kx022a_buffer_postenable(struct iio_dev *idev) ··· 1046 1053 struct kx022a_data *data = iio_priv(idev); 1047 1054 irqreturn_t ret = IRQ_NONE; 1048 1055 1049 - mutex_lock(&data->mutex); 1056 + guard(mutex)(&data->mutex); 1050 1057 1051 1058 if (data->trigger_enabled) { 1052 1059 iio_trigger_poll_nested(data->trig); ··· 1061 1068 ret = IRQ_HANDLED; 1062 1069 } 1063 1070 1064 - mutex_unlock(&data->mutex); 1065 - 1066 1071 return ret; 1067 1072 } 1068 1073 ··· 1070 1079 struct kx022a_data *data = iio_trigger_get_drvdata(trig); 1071 1080 int ret = 0; 1072 1081 1073 - mutex_lock(&data->mutex); 1082 + guard(mutex)(&data->mutex); 1074 1083 1075 1084 if (data->trigger_enabled == state) 1076 - goto unlock_out; 1085 + return 0; 1077 1086 1078 1087 if (data->state & KX022A_STATE_FIFO) { 1079 1088 dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); 1080 - ret = -EBUSY; 1081 - goto unlock_out; 1089 + return -EBUSY; 1082 1090 } 1083 1091 1084 - ret = kx022a_turn_on_off_unlocked(data, false); 1092 + ret = __kx022a_turn_on_off(data, false); 1085 1093 if (ret) 1086 - goto unlock_out; 1094 + return ret; 1087 1095 1088 1096 data->trigger_enabled = state; 1089 1097 ret = kx022a_set_drdy_irq(data, state); 1090 1098 if (ret) 1091 - goto unlock_out; 1099 + return ret; 1092 1100 1093 - ret = kx022a_turn_on_off_unlocked(data, true); 1094 - 1095 - unlock_out: 1096 - mutex_unlock(&data->mutex); 1097 - 1098 - return ret; 1101 + return __kx022a_turn_on_off(data, true); 1099 1102 } 1100 1103 1101 1104 static const struct iio_trigger_ops kx022a_trigger_ops = {