From: Nicolas Ferre <nicolas.ferre@microchip.com> Date: 2021-03-31 08:19:23
On 09/02/2021 at 12:01, Claudiu Beznea wrote:
Free resources on exit path (failure path of probe and remove).
I'm not sure we can use this driver as a module anyway.
Otherwise, it looks fine, but isn't it possible to use devm_of_iomap(),
even in loop, and avoid having to deal with exit path?
On 01.04.2021 17:42, Claudiu Beznea - M18063 wrote:
On 31.03.2021 11:18, Nicolas Ferre wrote:
quoted
On 09/02/2021 at 12:01, Claudiu Beznea wrote:
quoted
Free resources on exit path (failure path of probe and remove).
I'm not sure we can use this driver as a module anyway.
Otherwise, it looks fine, but isn't it possible to use devm_of_iomap(),
even in loop, and avoid having to deal with exit path?
For:
reset->rstc_base = of_iomap(pdev->dev.of_node, 0);
it should work.
For the maps in the loop I have to double check. Basically, the struct
resource object to pass to devm_of_iomap() is needed and for this the
Just realized I looked at the wrong code. Anyway, I'll double check and return.
pointer to a struct platform_device object corresponding to the node we
look for in the loop is needed. So, I think this cannot be done this way.
But if we keep this loop, I have the feeling that some kind of
"of_node_put()" is needed as well.
No! In the loop:
for_each_matching_node_and_match(np, at91_ramc_of_match, &match) {
reset->ramc_lpr = (u32)match->data;
reset->ramc_base[idx] = of_iomap(np, 0);
if (!reset->ramc_base[idx]) {
dev_err(&pdev->dev, "Could not map ram controller address\n");
of_node_put(np);
ret = -ENODEV;
goto unmap;
}
idx++;
}
the of_node_put() is needed only if the loop is interrupted as the macro:
for_each_matching_node_and_match() is defined as follows:
#define for_each_matching_node_and_match(dn, matches, match) \
for (dn = of_find_matching_node_and_match(NULL, matches, match); \
dn; dn = of_find_matching_node_and_match(dn, matches, match))
and of_find_matching_node_and_match() will return a np with refcount
incremented but at the next loop step the of_find_matching_node_and_match()
will be called with the same np pointer and the np refcount will be
decremented.
struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match)
{
// ...
of_node_put(from);
// ...
}
Free resources on exit path (failure path of probe and remove).
I'm not sure we can use this driver as a module anyway.
Otherwise, it looks fine, but isn't it possible to use devm_of_iomap(),
even in loop, and avoid having to deal with exit path?
For:
reset->rstc_base = of_iomap(pdev->dev.of_node, 0);
it should work.
For the maps in the loop I have to double check. Basically, the struct
resource object to pass to devm_of_iomap() is needed and for this the
pointer to a struct platform_device object corresponding to the node we
look for in the loop is needed. So, I think this cannot be done this way.
But if we keep this loop, I have the feeling that some kind of
"of_node_put()" is needed as well.
No! In the loop:
for_each_matching_node_and_match(np, at91_ramc_of_match, &match) {
reset->ramc_lpr = (u32)match->data;
reset->ramc_base[idx] = of_iomap(np, 0);
if (!reset->ramc_base[idx]) {
dev_err(&pdev->dev, "Could not map ram controller address\n");
of_node_put(np);
ret = -ENODEV;
goto unmap;
}
idx++;
}
the of_node_put() is needed only if the loop is interrupted as the macro:
for_each_matching_node_and_match() is defined as follows:
#define for_each_matching_node_and_match(dn, matches, match) \
for (dn = of_find_matching_node_and_match(NULL, matches, match); \
dn; dn = of_find_matching_node_and_match(dn, matches, match))
and of_find_matching_node_and_match() will return a np with refcount
incremented but at the next loop step the of_find_matching_node_and_match()
will be called with the same np pointer and the np refcount will be
decremented.
struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match)
{
// ...
of_node_put(from);
// ...
}
But if we keep this loop, I have the feeling that some kind of
"of_node_put()" is needed as well.
No! In the loop:
for_each_matching_node_and_match(np, at91_ramc_of_match, &match) {
reset->ramc_lpr = (u32)match->data;
reset->ramc_base[idx] = of_iomap(np, 0);
if (!reset->ramc_base[idx]) {
dev_err(&pdev->dev, "Could not map ram controller address\n");
of_node_put(np);
ret = -ENODEV;
goto unmap;
}
idx++;
}
the of_node_put() is needed only if the loop is interrupted as the macro:
for_each_matching_node_and_match() is defined as follows:
#define for_each_matching_node_and_match(dn, matches, match) \
for (dn = of_find_matching_node_and_match(NULL, matches, match); \
dn; dn = of_find_matching_node_and_match(dn, matches, match))
and of_find_matching_node_and_match() will return a np with refcount
incremented but at the next loop step the of_find_matching_node_and_match()
will be called with the same np pointer and the np refcount will be
decremented.
struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match)
{
// ...
of_node_put(from);
// ...
}
Oh yes you're right Claudiu, I overlooked this one. Thanks for the
in-depth explanation.
Best regards,
Nicolas
--
Nicolas Ferre
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel