Skip to contentSkip to conversation

sh: replace usage of found with dedicated list iterator variable

PATCH New Jakob Koschel 1 participant 1 message Mar 24, 2022 SuperH

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh: 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.

---
 arch/sh/drivers/dma/dma-api.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
arch/sh/drivers/dma/dma-api.c +10 -12
index ab9170494dcc..b1a54269b03c 100644
@@ -127,20 +127,19 @@ static int search_cap(const char **haystack, const char *needle)
  */
 int request_dma_bycap(const char **dmac, const char **caps, const char *dev_id)
 {
-	unsigned int found = 0;
-	struct dma_info *info;
+	struct dma_info *info = NULL, *iter;
 	const char **p;
 	int i;
 
 	BUG_ON(!dmac || !caps);
 
-	list_for_each_entry(info, &registered_dmac_list, list)
-		if (strcmp(*dmac, info->name) == 0) {
-			found = 1;
+	list_for_each_entry(iter, &registered_dmac_list, list)
+		if (strcmp(*dmac, iter->name) == 0) {
+			info = iter;
 			break;
 		}
 
-	if (!found)
+	if (!info)
 		return -ENODEV;
 
 	for (i = 0; i < info->nr_channels; i++) {
@@ -242,17 +241,16 @@ EXPORT_SYMBOL(dma_wait_for_completion);
 
 int register_chan_caps(const char *dmac, struct dma_chan_caps *caps)
 {
-	struct dma_info *info;
-	unsigned int found = 0;
+	struct dma_info *info = NULL, *iter;
 	int i;
 
-	list_for_each_entry(info, &registered_dmac_list, list)
-		if (strcmp(dmac, info->name) == 0) {
-			found = 1;
+	list_for_each_entry(iter, &registered_dmac_list, list)
+		if (strcmp(dmac, iter->name) == 0) {
+			info = iter;
 			break;
 		}
 
-	if (unlikely(!found))
+	if (unlikely(!info))
 		return -ENODEV;
 
 	for (i = 0; i < info->nr_channels; i++, caps++) {

base-commit: f443e374ae131c168a065ea1748feac6b2e76613

Signature · 1 line
2.25.1