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

reset: simplify locking with guard()

Simplify error handling (less gotos) over locks with guard().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Link: https://lore.kernel.org/r/20240825-reset-cleanup-scoped-v1-3-03f6d834f8c0@linaro.org
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>

authored by

Krzysztof Kozlowski and committed by
Philipp Zabel
3ec21e7f b14e40f5

+4 -11
+4 -11
drivers/reset/core.c
··· 916 916 */ 917 917 lockdep_assert_not_held(&reset_list_mutex); 918 918 919 - mutex_lock(&reset_gpio_lookup_mutex); 919 + guard(mutex)(&reset_gpio_lookup_mutex); 920 920 921 921 list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { 922 922 if (args->np == rgpio_dev->of_args.np) { 923 923 if (of_phandle_args_equal(args, &rgpio_dev->of_args)) 924 - goto out; /* Already on the list, done */ 924 + return 0; /* Already on the list, done */ 925 925 } 926 926 } 927 927 928 928 id = ida_alloc(&reset_gpio_ida, GFP_KERNEL); 929 - if (id < 0) { 930 - ret = id; 931 - goto err_unlock; 932 - } 929 + if (id < 0) 930 + return id; 933 931 934 932 /* Not freed on success, because it is persisent subsystem data. */ 935 933 rgpio_dev = kzalloc(sizeof(*rgpio_dev), GFP_KERNEL); ··· 957 959 958 960 list_add(&rgpio_dev->list, &reset_gpio_lookup_list); 959 961 960 - out: 961 - mutex_unlock(&reset_gpio_lookup_mutex); 962 - 963 962 return 0; 964 963 965 964 err_put: ··· 965 970 kfree(rgpio_dev); 966 971 err_ida_free: 967 972 ida_free(&reset_gpio_ida, id); 968 - err_unlock: 969 - mutex_unlock(&reset_gpio_lookup_mutex); 970 973 971 974 return ret; 972 975 }