* [PATCH 0/3] regulator-core: Fine-tuning for nine function implementations
@ 2017-11-02 7:58 SF Markus Elfring
2017-11-02 7:59 ` [PATCH 1/3] regulator/core: Use common error handling code in regulator_resolve_supply() SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-02 7:58 UTC (permalink / raw)
To: kernel-janitors, Liam Girdwood, Mark Brown; +Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 2 Nov 2017 08:54:32 +0100
Three update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Use common error handling code in regulator_resolve_supply()
Improve a size determination in four functions
Adjust 18 checks for null pointers
drivers/regulator/core.c | 60 ++++++++++++++++++++++++------------------------
1 file changed, 30 insertions(+), 30 deletions(-)
--
2.14.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] regulator/core: Use common error handling code in regulator_resolve_supply()
2017-11-02 7:58 [PATCH 0/3] regulator-core: Fine-tuning for nine function implementations SF Markus Elfring
@ 2017-11-02 7:59 ` SF Markus Elfring
2017-11-02 8:00 ` [PATCH 2/3] regulator/core: Improve a size determination in four functions SF Markus Elfring
2017-11-02 8:01 ` [PATCH 3/3] regulator/core: Adjust 18 checks for null pointers SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-02 7:59 UTC (permalink / raw)
To: kernel-janitors, Liam Girdwood, Mark Brown; +Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 1 Nov 2017 22:20:13 +0100
* Add a jump target so that a bit of exception handling can be better
reused at the end of this function.
* Adjust two condition checks.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/regulator/core.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b64b7916507f..14fdf2f17a62 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1554,23 +1554,19 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
*/
if (r->dev.parent && r->dev.parent != rdev->dev.parent) {
if (!device_is_bound(r->dev.parent)) {
- put_device(&r->dev);
- return -EPROBE_DEFER;
+ ret = -EPROBE_DEFER;
+ goto put_device;
}
}
/* Recursively resolve the supply of the supply */
ret = regulator_resolve_supply(r);
- if (ret < 0) {
- put_device(&r->dev);
- return ret;
- }
+ if (ret)
+ goto put_device;
ret = set_supply(rdev, r);
- if (ret < 0) {
- put_device(&r->dev);
- return ret;
- }
+ if (ret)
+ goto put_device;
/* Cascade always-on state to supply */
if (_regulator_is_enabled(rdev)) {
@@ -1583,6 +1579,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
}
return 0;
+
+put_device:
+ put_device(&r->dev);
+ return ret;
}
/* Internal regulator request function */
--
2.14.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] regulator/core: Improve a size determination in four functions
2017-11-02 7:58 [PATCH 0/3] regulator-core: Fine-tuning for nine function implementations SF Markus Elfring
2017-11-02 7:59 ` [PATCH 1/3] regulator/core: Use common error handling code in regulator_resolve_supply() SF Markus Elfring
@ 2017-11-02 8:00 ` SF Markus Elfring
2017-11-02 8:01 ` [PATCH 3/3] regulator/core: Adjust 18 checks for null pointers SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-02 8:00 UTC (permalink / raw)
To: kernel-janitors, Liam Girdwood, Mark Brown; +Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 1 Nov 2017 22:30:10 +0100
Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/regulator/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 14fdf2f17a62..28859c186c9f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1223,7 +1223,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
return -EBUSY;
}
- node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
if (node == NULL)
return -ENOMEM;
@@ -1833,7 +1833,7 @@ int regulator_register_supply_alias(struct device *dev, const char *id,
if (map)
return -EEXIST;
- map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL);
+ map = kzalloc(sizeof(*map), GFP_KERNEL);
if (!map)
return -ENOMEM;
@@ -1964,7 +1964,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
if (ret)
return ret;
- pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
+ pin = kzalloc(sizeof(*pin), GFP_KERNEL);
if (pin == NULL) {
gpio_free(config->ena_gpio);
return -ENOMEM;
@@ -4011,7 +4011,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
return ERR_PTR(-EINVAL);
}
- rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
+ rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
if (rdev == NULL)
return ERR_PTR(-ENOMEM);
--
2.14.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] regulator/core: Adjust 18 checks for null pointers
2017-11-02 7:58 [PATCH 0/3] regulator-core: Fine-tuning for nine function implementations SF Markus Elfring
2017-11-02 7:59 ` [PATCH 1/3] regulator/core: Use common error handling code in regulator_resolve_supply() SF Markus Elfring
2017-11-02 8:00 ` [PATCH 2/3] regulator/core: Improve a size determination in four functions SF Markus Elfring
@ 2017-11-02 8:01 ` SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-02 8:01 UTC (permalink / raw)
To: kernel-janitors, Liam Girdwood, Mark Brown; +Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 1 Nov 2017 22:40:55 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/regulator/core.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 28859c186c9f..4aaf7e40524d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1168,7 +1168,7 @@ static int set_supply(struct regulator_dev *rdev,
return -ENODEV;
rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY");
- if (rdev->supply == NULL) {
+ if (!rdev->supply) {
err = -ENOMEM;
return err;
}
@@ -1195,10 +1195,10 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
struct regulator_map *node;
int has_dev;
- if (supply == NULL)
+ if (!supply)
return -EINVAL;
- if (consumer_dev_name != NULL)
+ if (consumer_dev_name)
has_dev = 1;
else
has_dev = 0;
@@ -1224,7 +1224,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
}
node = kzalloc(sizeof(*node), GFP_KERNEL);
- if (node == NULL)
+ if (!node)
return -ENOMEM;
node->regulator = rdev;
@@ -1232,7 +1232,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
if (has_dev) {
node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
- if (node->dev_name == NULL) {
+ if (!node->dev_name) {
kfree(node);
return -ENOMEM;
}
@@ -1315,7 +1315,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
int err, size;
regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
- if (regulator == NULL)
+ if (!regulator)
return NULL;
mutex_lock(&rdev->mutex);
@@ -1332,7 +1332,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
goto overflow_err;
regulator->supply_name = kstrdup(buf, GFP_KERNEL);
- if (regulator->supply_name == NULL)
+ if (!regulator->supply_name)
goto overflow_err;
err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj,
@@ -1344,7 +1344,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
}
} else {
regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL);
- if (regulator->supply_name == NULL)
+ if (!regulator->supply_name)
goto overflow_err;
}
@@ -1599,7 +1599,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
return ERR_PTR(-EINVAL);
}
- if (id == NULL) {
+ if (!id) {
pr_err("get() with no identifier\n");
return ERR_PTR(-EINVAL);
}
@@ -1671,7 +1671,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
}
regulator = create_regulator(rdev, dev, id);
- if (regulator == NULL) {
+ if (!regulator) {
regulator = ERR_PTR(-ENOMEM);
put_device(&rdev->dev);
module_put(rdev->owner);
@@ -1965,7 +1965,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
return ret;
pin = kzalloc(sizeof(*pin), GFP_KERNEL);
- if (pin == NULL) {
+ if (!pin) {
gpio_free(config->ena_gpio);
return -ENOMEM;
}
@@ -3982,13 +3982,13 @@ regulator_register(const struct regulator_desc *regulator_desc,
struct device *dev;
int ret, i;
- if (regulator_desc == NULL || cfg == NULL)
+ if (!regulator_desc || !cfg)
return ERR_PTR(-EINVAL);
dev = cfg->dev;
WARN_ON(!dev);
- if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
+ if (!regulator_desc->name || !regulator_desc->ops)
return ERR_PTR(-EINVAL);
if (regulator_desc->type != REGULATOR_VOLTAGE &&
@@ -4012,7 +4012,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
}
rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
- if (rdev == NULL)
+ if (!rdev)
return ERR_PTR(-ENOMEM);
/*
@@ -4020,7 +4020,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
* parsing init data.
*/
config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL);
- if (config == NULL) {
+ if (!config) {
kfree(rdev);
return ERR_PTR(-ENOMEM);
}
@@ -4154,7 +4154,7 @@ EXPORT_SYMBOL_GPL(regulator_register);
*/
void regulator_unregister(struct regulator_dev *rdev)
{
- if (rdev == NULL)
+ if (!rdev)
return;
if (rdev->supply) {
--
2.14.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-02 8:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-02 7:58 [PATCH 0/3] regulator-core: Fine-tuning for nine function implementations SF Markus Elfring
2017-11-02 7:59 ` [PATCH 1/3] regulator/core: Use common error handling code in regulator_resolve_supply() SF Markus Elfring
2017-11-02 8:00 ` [PATCH 2/3] regulator/core: Improve a size determination in four functions SF Markus Elfring
2017-11-02 8:01 ` [PATCH 3/3] regulator/core: Adjust 18 checks for null pointers SF Markus Elfring
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).