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

w1: Replace usage of found with dedicated list iterator variable

To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jkl820.git@gmail.com>
Link: https://lore.kernel.org/r/20230509-w1-replace-usage-of-found-with-tmp-list-iterator-variable-v3-1-e07c9603fd9d@gmail.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

authored by

Jakob Koschel and committed by
Krzysztof Kozlowski
b332af53 0df2a5e9

+15 -17
+15 -17
drivers/w1/w1.c
··· 821 821 822 822 struct w1_master *w1_search_master_id(u32 id) 823 823 { 824 - struct w1_master *dev; 825 - int found = 0; 824 + struct w1_master *dev = NULL, *iter; 826 825 827 826 mutex_lock(&w1_mlock); 828 - list_for_each_entry(dev, &w1_masters, w1_master_entry) { 829 - if (dev->id == id) { 830 - found = 1; 831 - atomic_inc(&dev->refcnt); 827 + list_for_each_entry(iter, &w1_masters, w1_master_entry) { 828 + if (iter->id == id) { 829 + dev = iter; 830 + atomic_inc(&iter->refcnt); 832 831 break; 833 832 } 834 833 } 835 834 mutex_unlock(&w1_mlock); 836 835 837 - return (found)?dev:NULL; 836 + return dev; 838 837 } 839 838 840 839 struct w1_slave *w1_search_slave(struct w1_reg_num *id) 841 840 { 842 841 struct w1_master *dev; 843 - struct w1_slave *sl = NULL; 844 - int found = 0; 842 + struct w1_slave *sl = NULL, *iter; 845 843 846 844 mutex_lock(&w1_mlock); 847 845 list_for_each_entry(dev, &w1_masters, w1_master_entry) { 848 846 mutex_lock(&dev->list_mutex); 849 - list_for_each_entry(sl, &dev->slist, w1_slave_entry) { 850 - if (sl->reg_num.family == id->family && 851 - sl->reg_num.id == id->id && 852 - sl->reg_num.crc == id->crc) { 853 - found = 1; 847 + list_for_each_entry(iter, &dev->slist, w1_slave_entry) { 848 + if (iter->reg_num.family == id->family && 849 + iter->reg_num.id == id->id && 850 + iter->reg_num.crc == id->crc) { 851 + sl = iter; 854 852 atomic_inc(&dev->refcnt); 855 - atomic_inc(&sl->refcnt); 853 + atomic_inc(&iter->refcnt); 856 854 break; 857 855 } 858 856 } 859 857 mutex_unlock(&dev->list_mutex); 860 858 861 - if (found) 859 + if (sl) 862 860 break; 863 861 } 864 862 mutex_unlock(&w1_mlock); 865 863 866 - return (found)?sl:NULL; 864 + return sl; 867 865 } 868 866 869 867 void w1_reconnect_slaves(struct w1_family *f, int attach)