2014-12-28 16:38:37

by Aniroop Mathur

[permalink] [raw]
Subject: [PATCH] regulator: core: Avoid negative regulator no & initialize it to -1

This patch initializes regulator_no to -1 to avoid extra subtraction
operation performed every time we register a regulator and avoid negative
regulator no in its name.

Signed-off-by: Aniroop Mathur <[email protected]>
---
drivers/regulator/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a3c3785..b0729ef 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
{
const struct regulation_constraints *constraints = NULL;
const struct regulator_init_data *init_data;
- static atomic_t regulator_no = ATOMIC_INIT(0);
+ static atomic_t regulator_no = ATOMIC_INIT(-1);
struct regulator_dev *rdev;
struct device *dev;
int ret, i;
@@ -3550,8 +3550,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
rdev->dev.class = &regulator_class;
rdev->dev.of_node = of_node_get(config->of_node);
rdev->dev.parent = dev;
- dev_set_name(&rdev->dev, "regulator.%d",
- atomic_inc_return(&regulator_no) - 1);
+ dev_set_name(&rdev->dev, "regulator.%lu",
+ atomic_inc_return(&regulator_no));
ret = device_register(&rdev->dev);
if (ret != 0) {
put_device(&rdev->dev);
--
1.9.1


2014-12-29 16:09:06

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regulator: core: Avoid negative regulator no & initialize it to -1

On Sun, Dec 28, 2014 at 10:08:38PM +0530, Aniroop Mathur wrote:
> This patch initializes regulator_no to -1 to avoid extra subtraction
> operation performed every time we register a regulator and avoid negative
> regulator no in its name.

Applied, thanks.


Attachments:
(No filename) (257.00 B)
signature.asc (473.00 B)
Digital signature
Download all attachments