Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

of: reserved_mem: Remove the use of phandle from the reserved_mem APIs

The __find_rmem() function is the only place that references the phandle
field of the reserved_mem struct. __find_rmem() is used to match a
device_node object to its corresponding entry in the reserved_mem array
using its phandle value. But, there is already a function called
of_reserved_mem_lookup() which carries out the same action using the
name of the node.

Using the of_reserved_mem_lookup() function is more reliable because
every node is guaranteed to have a name, but not all nodes will have a
phandle.

Nodes are only assigned a phandle if they are explicitly defined in the
DT using "phandle = <phandle_number>", or if they are referenced by
another node in the DT. Hence, If the phandle field is empty, then
__find_rmem() will return a false negative.

Hence, delete the __find_rmem() function and switch to using the
of_reserved_mem_lookup() function to find the corresponding entry of a
device_node in the reserved_mem array. Since the phandle field of the
reserved_mem struct is now unused, delete that as well.

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
Link: https://lore.kernel.org/r/20240502192403.3307277-1-quic_obabatun@quicinc.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

authored by

Oreoluwa Babatunde and committed by
Rob Herring (Arm)
c56436ef 669430b1

+1 -22
+1 -21
drivers/of/of_reserved_mem.c
··· 437 437 for (i = 0; i < reserved_mem_count; i++) { 438 438 struct reserved_mem *rmem = &reserved_mem[i]; 439 439 unsigned long node = rmem->fdt_node; 440 - int len; 441 - const __be32 *prop; 442 440 int err = 0; 443 441 bool nomap; 444 442 445 443 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; 446 - prop = of_get_flat_dt_prop(node, "phandle", &len); 447 - if (!prop) 448 - prop = of_get_flat_dt_prop(node, "linux,phandle", &len); 449 - if (prop) 450 - rmem->phandle = of_read_number(prop, len/4); 451 444 452 445 if (rmem->size == 0) 453 446 err = __reserved_mem_alloc_size(node, rmem->name, ··· 468 475 } 469 476 } 470 477 } 471 - } 472 - 473 - static inline struct reserved_mem *__find_rmem(struct device_node *node) 474 - { 475 - unsigned int i; 476 - 477 - if (!node->phandle) 478 - return NULL; 479 - 480 - for (i = 0; i < reserved_mem_count; i++) 481 - if (reserved_mem[i].phandle == node->phandle) 482 - return &reserved_mem[i]; 483 - return NULL; 484 478 } 485 479 486 480 struct rmem_assigned_device { ··· 514 534 return 0; 515 535 } 516 536 517 - rmem = __find_rmem(target); 537 + rmem = of_reserved_mem_lookup(target); 518 538 of_node_put(target); 519 539 520 540 if (!rmem || !rmem->ops || !rmem->ops->device_init)
-1
include/linux/of_reserved_mem.h
··· 11 11 struct reserved_mem { 12 12 const char *name; 13 13 unsigned long fdt_node; 14 - unsigned long phandle; 15 14 const struct reserved_mem_ops *ops; 16 15 phys_addr_t base; 17 16 phys_addr_t size;