linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator/core.c: remove the else statement
@ 2017-04-18 15:39 hubiaoyong
  2017-04-18 15:49 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: hubiaoyong @ 2017-04-18 15:39 UTC (permalink / raw)
  To: lgirdwood; +Cc: broonie, linux-kernel, hby2003, hubiaoyong

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

Signed-off-by: hubiaoyong <hubiaoyong@gmail.com>
---
 drivers/regulator/core.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 53d4fc7..de3d07a 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -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--;
 		}
 	}
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator/core.c: remove the else statement
  2017-04-18 15:39 [PATCH] regulator/core.c: remove the else statement hubiaoyong
@ 2017-04-18 15:49 ` Mark Brown
  2017-04-18 16:28   ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2017-04-18 15:49 UTC (permalink / raw)
  To: hubiaoyong; +Cc: lgirdwood, linux-kernel, hby2003

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]

On Tue, Apr 18, 2017 at 11:39:34PM +0800, hubiaoyong wrote:
> 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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator/core.c: remove the else statement
  2017-04-18 15:49 ` Mark Brown
@ 2017-04-18 16:28   ` Joe Perches
       [not found]     ` <CAJPOojYT0Mk-+_Enmtz6C1ZRGDmMcnQLMAOXvGwKAs+bM67tMg@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-04-18 16:28 UTC (permalink / raw)
  To: Mark Brown, hubiaoyong; +Cc: lgirdwood, linux-kernel, hby2003

On Tue, 2017-04-18 at 16:49 +0100, Mark Brown wrote:
> On Tue, Apr 18, 2017 at 11:39:34PM +0800, hubiaoyong wrote:
> > 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--;
	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator/core.c: remove the else statement
       [not found]     ` <CAJPOojYT0Mk-+_Enmtz6C1ZRGDmMcnQLMAOXvGwKAs+bM67tMg@mail.gmail.com>
@ 2017-04-19 16:26       ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2017-04-19 16:26 UTC (permalink / raw)
  To: Biaoyong Hu; +Cc: Joe Perches, Liam Girdwood, linux-kernel, byhoo

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]

On Wed, Apr 19, 2017 at 08:53:05PM +0800, Biaoyong Hu wrote:

> 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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-19 16:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-18 15:39 [PATCH] regulator/core.c: remove the else statement hubiaoyong
2017-04-18 15:49 ` Mark Brown
2017-04-18 16:28   ` Joe Perches
     [not found]     ` <CAJPOojYT0Mk-+_Enmtz6C1ZRGDmMcnQLMAOXvGwKAs+bM67tMg@mail.gmail.com>
2017-04-19 16:26       ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).