Skip to contentSkip to conversation

regulator/core.c: remove the else statement

PATCH In review hubiaoyong 3 participants 4 messages Apr 18, 2017 – Apr 19, 2017 1 message not in the archive Voltage and current regulator framework

lore
Share & tools
lore

hubiaoyong

author
#0 lore raw

PATCH 1/1 regulator/core.c: remove the else statement

in the function regulator_ena_gpio_free, the if branch contains the return statement, so remove the else statement.

---
 drivers/regulator/core.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/regulator/core.c +1 -2
index 53d4fc7..de3d07a 100644
@@ -2007,9 +2007,8 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
 				kfree(pin);
 				rdev->ena_pin = NULL;
 				return;
-			} else {
-				pin->request_count--;
 			}
+			pin->request_count--;
 		}
 	}
 }
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 2 lines · hubiaoyong

in the function regulator_ena_gpio_free, the if branch contains the return statement, so remove the else statement.

Why is it a benefit to make this change?

#2 lore raw
Quoted 5 lines · Mark Brown
Quoted 2 lines · hubiaoyong

in the function regulator_ena_gpio_free, the if branch contains the return statement, so remove the else statement.

Why is it a benefit to make this change?

In general, reducing source code indentation is a good thing.

The logic today is:

	/* Free the GPIO only in case of no use */
	list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) {
		if (pin->gpiod == rdev->ena_pin->gpiod) {
			if (pin->request_count <= 1) {
				pin->request_count = 0;
				gpiod_put(pin->gpiod);
				list_del(&pin->list);
				kfree(pin);
				rdev->ena_pin = NULL;
				return;
			} else {
				pin->request_count--;
			}
		}
	}

Perhaps it's better written as:

	/* Free the GPIO only in case of no use */
	list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) {
		if (pin->gpiod != rdev->ena_pin->gpiod)
			continue;
		if (pin->request_count <= 1) {
			pin->request_count = 0;
			gpiod_put(pin->gpiod);
			list_del(&pin->list);
			kfree(pin);
			rdev->ena_pin = NULL;
			return;
		}
		pin->request_count--;
	}

A message that is not in the archive (sent off-list or not yet received): CAJPOojYT0Mk-+_Enmtz6C1ZRGDmMcnQLMAOXvGwKAs+bM67tMg@mail.gmail.com

maintainer
#4 lore raw
Quoted 2 lines · Biaoyong Hu

kfree(pin); pin will be freed. So, "pin->request_count = 0;" should be removed?

Yes, it's redundant.

Please don't top post, reply in line with needed context. This allows readers to readily follow the flow of conversation and understand what you are talking about and also helps ensure that everything in the discussion is being addressed.