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.

reset: use lock guards in reset core

Simplify the locking code in reset core by using lock guard from
linux/cleanup.h.

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>

authored by

Bartosz Golaszewski and committed by
Philipp Zabel
1f10008a 6703784a

+25 -30
+25 -30
drivers/reset/core.c
··· 129 129 130 130 INIT_LIST_HEAD(&rcdev->reset_control_head); 131 131 132 - mutex_lock(&reset_list_mutex); 132 + guard(mutex)(&reset_list_mutex); 133 + 133 134 list_add(&rcdev->list, &reset_controller_list); 134 - mutex_unlock(&reset_list_mutex); 135 135 136 136 return 0; 137 137 } ··· 143 143 */ 144 144 void reset_controller_unregister(struct reset_controller_dev *rcdev) 145 145 { 146 - mutex_lock(&reset_list_mutex); 146 + guard(mutex)(&reset_list_mutex); 147 + 147 148 list_del(&rcdev->list); 148 - mutex_unlock(&reset_list_mutex); 149 149 } 150 150 EXPORT_SYMBOL_GPL(reset_controller_unregister); 151 151 ··· 646 646 if (reset_control_is_array(rstc)) 647 647 return reset_control_array_acquire(rstc_to_array(rstc)); 648 648 649 - mutex_lock(&reset_list_mutex); 649 + guard(mutex)(&reset_list_mutex); 650 650 651 - if (rstc->acquired) { 652 - mutex_unlock(&reset_list_mutex); 651 + if (rstc->acquired) 653 652 return 0; 654 - } 655 653 656 654 list_for_each_entry(rc, &rstc->rcdev->reset_control_head, list) { 657 655 if (rstc != rc && rstc->id == rc->id) { 658 - if (rc->acquired) { 659 - mutex_unlock(&reset_list_mutex); 656 + if (rc->acquired) 660 657 return -EBUSY; 661 - } 662 658 } 663 659 } 664 660 665 661 rstc->acquired = true; 666 662 667 - mutex_unlock(&reset_list_mutex); 668 663 return 0; 669 664 } 670 665 EXPORT_SYMBOL_GPL(reset_control_acquire); ··· 1059 1064 1060 1065 ret = __reset_add_reset_gpio_device(node, &args); 1061 1066 if (ret) { 1062 - rstc = ERR_PTR(ret); 1063 - goto out_put; 1067 + of_node_put(args.np); 1068 + return ERR_PTR(ret); 1064 1069 } 1065 1070 } 1066 1071 1067 - mutex_lock(&reset_list_mutex); 1072 + guard(mutex)(&reset_list_mutex); 1073 + 1068 1074 rcdev = __reset_find_rcdev(&args, gpio_fallback); 1069 1075 if (!rcdev) { 1070 1076 rstc = ERR_PTR(-EPROBE_DEFER); 1071 - goto out_unlock; 1077 + goto out_put; 1072 1078 } 1073 1079 1074 1080 if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { 1075 1081 rstc = ERR_PTR(-EINVAL); 1076 - goto out_unlock; 1082 + goto out_put; 1077 1083 } 1078 1084 1079 1085 rstc_id = rcdev->of_xlate(rcdev, &args); 1080 1086 if (rstc_id < 0) { 1081 1087 rstc = ERR_PTR(rstc_id); 1082 - goto out_unlock; 1088 + goto out_put; 1083 1089 } 1084 1090 1085 1091 flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL; ··· 1088 1092 /* reset_list_mutex also protects the rcdev's reset_control list */ 1089 1093 rstc = __reset_control_get_internal(rcdev, rstc_id, flags); 1090 1094 1091 - out_unlock: 1092 - mutex_unlock(&reset_list_mutex); 1093 1095 out_put: 1094 1096 of_node_put(args.np); 1095 1097 ··· 1129 1135 return 0; 1130 1136 1131 1137 err: 1132 - mutex_lock(&reset_list_mutex); 1138 + guard(mutex)(&reset_list_mutex); 1139 + 1133 1140 while (i--) 1134 1141 __reset_control_put_internal(rstcs[i].rstc); 1135 - mutex_unlock(&reset_list_mutex); 1142 + 1136 1143 return ret; 1137 1144 } 1138 1145 EXPORT_SYMBOL_GPL(__reset_control_bulk_get); ··· 1142 1147 { 1143 1148 int i; 1144 1149 1145 - mutex_lock(&reset_list_mutex); 1150 + guard(mutex)(&reset_list_mutex); 1151 + 1146 1152 for (i = 0; i < resets->num_rstcs; i++) 1147 1153 __reset_control_put_internal(resets->rstc[i]); 1148 - mutex_unlock(&reset_list_mutex); 1149 1154 kfree(resets); 1150 1155 } 1151 1156 ··· 1163 1168 return; 1164 1169 } 1165 1170 1166 - mutex_lock(&reset_list_mutex); 1171 + guard(mutex)(&reset_list_mutex); 1172 + 1167 1173 __reset_control_put_internal(rstc); 1168 - mutex_unlock(&reset_list_mutex); 1169 1174 } 1170 1175 EXPORT_SYMBOL_GPL(reset_control_put); 1171 1176 ··· 1176 1181 */ 1177 1182 void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs) 1178 1183 { 1179 - mutex_lock(&reset_list_mutex); 1184 + guard(mutex)(&reset_list_mutex); 1185 + 1180 1186 while (num_rstcs--) 1181 1187 __reset_control_put_internal(rstcs[num_rstcs].rstc); 1182 - mutex_unlock(&reset_list_mutex); 1183 1188 } 1184 1189 EXPORT_SYMBOL_GPL(reset_control_bulk_put); 1185 1190 ··· 1398 1403 return &resets->base; 1399 1404 1400 1405 err_rst: 1401 - mutex_lock(&reset_list_mutex); 1406 + guard(mutex)(&reset_list_mutex); 1407 + 1402 1408 while (--i >= 0) 1403 1409 __reset_control_put_internal(resets->rstc[i]); 1404 - mutex_unlock(&reset_list_mutex); 1405 1410 1406 1411 kfree(resets); 1407 1412