leds: powernv: Replace of_node_put to __free
Use __free for device_node values, and thus drop calls to of_node_put. The variable attribute __free adds a scope based cleanup to the device node. The goal is to reduce memory management issues in the kernel code. The of_node_put calls were removed, and the for_each_available_child_of_node was replaced to the equivalent for_each_available_child_of_node_scoped which use the __free. Suggested-by: Julia Lawall <julia.lawall@inria.fr> Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com> Link: https://lore.kernel.org/r/20240601031713.1307859-1-marilene.agarcia@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
parent
e786348b24
commit
d35625734a
@ -246,29 +246,25 @@ static int powernv_led_classdev(struct platform_device *pdev,
|
|||||||
const char *cur = NULL;
|
const char *cur = NULL;
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
struct property *p;
|
struct property *p;
|
||||||
struct device_node *np;
|
|
||||||
struct powernv_led_data *powernv_led;
|
struct powernv_led_data *powernv_led;
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
|
|
||||||
for_each_available_child_of_node(led_node, np) {
|
for_each_available_child_of_node_scoped(led_node, np) {
|
||||||
p = of_find_property(np, "led-types", NULL);
|
p = of_find_property(np, "led-types", NULL);
|
||||||
|
|
||||||
while ((cur = of_prop_next_string(p, cur)) != NULL) {
|
while ((cur = of_prop_next_string(p, cur)) != NULL) {
|
||||||
powernv_led = devm_kzalloc(dev, sizeof(*powernv_led),
|
powernv_led = devm_kzalloc(dev, sizeof(*powernv_led),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!powernv_led) {
|
if (!powernv_led)
|
||||||
of_node_put(np);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
powernv_led->common = powernv_led_common;
|
powernv_led->common = powernv_led_common;
|
||||||
powernv_led->loc_code = (char *)np->name;
|
powernv_led->loc_code = (char *)np->name;
|
||||||
|
|
||||||
rc = powernv_led_create(dev, powernv_led, cur);
|
rc = powernv_led_create(dev, powernv_led, cur);
|
||||||
if (rc) {
|
if (rc)
|
||||||
of_node_put(np);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
|
||||||
} /* while end */
|
} /* while end */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,12 +274,11 @@ static int powernv_led_classdev(struct platform_device *pdev,
|
|||||||
/* Platform driver probe */
|
/* Platform driver probe */
|
||||||
static int powernv_led_probe(struct platform_device *pdev)
|
static int powernv_led_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device_node *led_node;
|
|
||||||
struct powernv_led_common *powernv_led_common;
|
struct powernv_led_common *powernv_led_common;
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
int rc;
|
struct device_node *led_node
|
||||||
|
__free(device_node) = of_find_node_by_path("/ibm,opal/leds");
|
||||||
|
|
||||||
led_node = of_find_node_by_path("/ibm,opal/leds");
|
|
||||||
if (!led_node) {
|
if (!led_node) {
|
||||||
dev_err(dev, "%s: LED parent device node not found\n",
|
dev_err(dev, "%s: LED parent device node not found\n",
|
||||||
__func__);
|
__func__);
|
||||||
@ -292,20 +287,15 @@ static int powernv_led_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common),
|
powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!powernv_led_common) {
|
if (!powernv_led_common)
|
||||||
rc = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_init(&powernv_led_common->lock);
|
mutex_init(&powernv_led_common->lock);
|
||||||
powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
|
powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
|
||||||
|
|
||||||
platform_set_drvdata(pdev, powernv_led_common);
|
platform_set_drvdata(pdev, powernv_led_common);
|
||||||
|
|
||||||
rc = powernv_led_classdev(pdev, led_node, powernv_led_common);
|
return powernv_led_classdev(pdev, led_node, powernv_led_common);
|
||||||
out:
|
|
||||||
of_node_put(led_node);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Platform driver remove */
|
/* Platform driver remove */
|
||||||
|
Loading…
Reference in New Issue
Block a user