Skip to content

Commit 66a8f7f

Browse files
mwallerobherring
authored andcommitted
of: base: make small of_parse_phandle() variants static inline
Make all the smaller variants of the of_parse_phandle() static inline. This also let us remove the empty function stubs if CONFIG_OF is not defined. Suggested-by: Rob Herring <robh@kernel.org> Signed-off-by: Michael Walle <michael@walle.cc> [robh: move index < 0 check into __of_parse_phandle_with_args] Signed-off-by: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20220118173504.2867523-2-michael@walle.cc
1 parent 25e20b5 commit 66a8f7f

File tree

2 files changed

+129
-150
lines changed

2 files changed

+129
-150
lines changed

drivers/of/base.c

Lines changed: 9 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,15 +1420,18 @@ int of_phandle_iterator_args(struct of_phandle_iterator *it,
14201420
return count;
14211421
}
14221422

1423-
static int __of_parse_phandle_with_args(const struct device_node *np,
1424-
const char *list_name,
1425-
const char *cells_name,
1426-
int cell_count, int index,
1427-
struct of_phandle_args *out_args)
1423+
int __of_parse_phandle_with_args(const struct device_node *np,
1424+
const char *list_name,
1425+
const char *cells_name,
1426+
int cell_count, int index,
1427+
struct of_phandle_args *out_args)
14281428
{
14291429
struct of_phandle_iterator it;
14301430
int rc, cur_index = 0;
14311431

1432+
if (index < 0)
1433+
return -EINVAL;
1434+
14321435
/* Loop over the phandles until all the requested entry is found */
14331436
of_for_each_phandle(&it, rc, np, list_name, cells_name, cell_count) {
14341437
/*
@@ -1471,82 +1474,7 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
14711474
of_node_put(it.node);
14721475
return rc;
14731476
}
1474-
1475-
/**
1476-
* of_parse_phandle - Resolve a phandle property to a device_node pointer
1477-
* @np: Pointer to device node holding phandle property
1478-
* @phandle_name: Name of property holding a phandle value
1479-
* @index: For properties holding a table of phandles, this is the index into
1480-
* the table
1481-
*
1482-
* Return: The device_node pointer with refcount incremented. Use
1483-
* of_node_put() on it when done.
1484-
*/
1485-
struct device_node *of_parse_phandle(const struct device_node *np,
1486-
const char *phandle_name, int index)
1487-
{
1488-
struct of_phandle_args args;
1489-
1490-
if (index < 0)
1491-
return NULL;
1492-
1493-
if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
1494-
index, &args))
1495-
return NULL;
1496-
1497-
return args.np;
1498-
}
1499-
EXPORT_SYMBOL(of_parse_phandle);
1500-
1501-
/**
1502-
* of_parse_phandle_with_args() - Find a node pointed by phandle in a list
1503-
* @np: pointer to a device tree node containing a list
1504-
* @list_name: property name that contains a list
1505-
* @cells_name: property name that specifies phandles' arguments count
1506-
* @index: index of a phandle to parse out
1507-
* @out_args: optional pointer to output arguments structure (will be filled)
1508-
*
1509-
* This function is useful to parse lists of phandles and their arguments.
1510-
* Returns 0 on success and fills out_args, on error returns appropriate
1511-
* errno value.
1512-
*
1513-
* Caller is responsible to call of_node_put() on the returned out_args->np
1514-
* pointer.
1515-
*
1516-
* Example::
1517-
*
1518-
* phandle1: node1 {
1519-
* #list-cells = <2>;
1520-
* };
1521-
*
1522-
* phandle2: node2 {
1523-
* #list-cells = <1>;
1524-
* };
1525-
*
1526-
* node3 {
1527-
* list = <&phandle1 1 2 &phandle2 3>;
1528-
* };
1529-
*
1530-
* To get a device_node of the ``node2`` node you may call this:
1531-
* of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
1532-
*/
1533-
int of_parse_phandle_with_args(const struct device_node *np, const char *list_name,
1534-
const char *cells_name, int index,
1535-
struct of_phandle_args *out_args)
1536-
{
1537-
int cell_count = -1;
1538-
1539-
if (index < 0)
1540-
return -EINVAL;
1541-
1542-
/* If cells_name is NULL we assume a cell count of 0 */
1543-
if (!cells_name)
1544-
cell_count = 0;
1545-
1546-
return __of_parse_phandle_with_args(np, list_name, cells_name,
1547-
cell_count, index, out_args);
1548-
}
1549-
EXPORT_SYMBOL(of_parse_phandle_with_args);
1477+
EXPORT_SYMBOL(__of_parse_phandle_with_args);
15501478

15511479
/**
15521480
* of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it
@@ -1732,47 +1660,6 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
17321660
}
17331661
EXPORT_SYMBOL(of_parse_phandle_with_args_map);
17341662

1735-
/**
1736-
* of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
1737-
* @np: pointer to a device tree node containing a list
1738-
* @list_name: property name that contains a list
1739-
* @cell_count: number of argument cells following the phandle
1740-
* @index: index of a phandle to parse out
1741-
* @out_args: optional pointer to output arguments structure (will be filled)
1742-
*
1743-
* This function is useful to parse lists of phandles and their arguments.
1744-
* Returns 0 on success and fills out_args, on error returns appropriate
1745-
* errno value.
1746-
*
1747-
* Caller is responsible to call of_node_put() on the returned out_args->np
1748-
* pointer.
1749-
*
1750-
* Example::
1751-
*
1752-
* phandle1: node1 {
1753-
* };
1754-
*
1755-
* phandle2: node2 {
1756-
* };
1757-
*
1758-
* node3 {
1759-
* list = <&phandle1 0 2 &phandle2 2 3>;
1760-
* };
1761-
*
1762-
* To get a device_node of the ``node2`` node you may call this:
1763-
* of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
1764-
*/
1765-
int of_parse_phandle_with_fixed_args(const struct device_node *np,
1766-
const char *list_name, int cell_count,
1767-
int index, struct of_phandle_args *out_args)
1768-
{
1769-
if (index < 0)
1770-
return -EINVAL;
1771-
return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
1772-
index, out_args);
1773-
}
1774-
EXPORT_SYMBOL(of_parse_phandle_with_fixed_args);
1775-
17761663
/**
17771664
* of_count_phandle_with_args() - Find the number of phandles references in a property
17781665
* @np: pointer to a device tree node containing a list

include/linux/of.h

Lines changed: 120 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,12 @@ extern const struct of_device_id *of_match_node(
364364
const struct of_device_id *matches, const struct device_node *node);
365365
extern int of_modalias_node(struct device_node *node, char *modalias, int len);
366366
extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
367-
extern struct device_node *of_parse_phandle(const struct device_node *np,
368-
const char *phandle_name,
369-
int index);
370-
extern int of_parse_phandle_with_args(const struct device_node *np,
371-
const char *list_name, const char *cells_name, int index,
372-
struct of_phandle_args *out_args);
367+
extern int __of_parse_phandle_with_args(const struct device_node *np,
368+
const char *list_name, const char *cells_name, int cell_count,
369+
int index, struct of_phandle_args *out_args);
373370
extern int of_parse_phandle_with_args_map(const struct device_node *np,
374371
const char *list_name, const char *stem_name, int index,
375372
struct of_phandle_args *out_args);
376-
extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
377-
const char *list_name, int cells_count, int index,
378-
struct of_phandle_args *out_args);
379373
extern int of_count_phandle_with_args(const struct device_node *np,
380374
const char *list_name, const char *cells_name);
381375

@@ -865,18 +859,12 @@ static inline int of_property_read_string_helper(const struct device_node *np,
865859
return -ENOSYS;
866860
}
867861

868-
static inline struct device_node *of_parse_phandle(const struct device_node *np,
869-
const char *phandle_name,
870-
int index)
871-
{
872-
return NULL;
873-
}
874-
875-
static inline int of_parse_phandle_with_args(const struct device_node *np,
876-
const char *list_name,
877-
const char *cells_name,
878-
int index,
879-
struct of_phandle_args *out_args)
862+
static inline int __of_parse_phandle_with_args(const struct device_node *np,
863+
const char *list_name,
864+
const char *cells_name,
865+
int cell_count,
866+
int index,
867+
struct of_phandle_args *out_args)
880868
{
881869
return -ENOSYS;
882870
}
@@ -890,13 +878,6 @@ static inline int of_parse_phandle_with_args_map(const struct device_node *np,
890878
return -ENOSYS;
891879
}
892880

893-
static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
894-
const char *list_name, int cells_count, int index,
895-
struct of_phandle_args *out_args)
896-
{
897-
return -ENOSYS;
898-
}
899-
900881
static inline int of_count_phandle_with_args(const struct device_node *np,
901882
const char *list_name,
902883
const char *cells_name)
@@ -1077,6 +1058,117 @@ static inline bool of_node_is_type(const struct device_node *np, const char *typ
10771058
return np && match && type && !strcmp(match, type);
10781059
}
10791060

1061+
/**
1062+
* of_parse_phandle - Resolve a phandle property to a device_node pointer
1063+
* @np: Pointer to device node holding phandle property
1064+
* @phandle_name: Name of property holding a phandle value
1065+
* @index: For properties holding a table of phandles, this is the index into
1066+
* the table
1067+
*
1068+
* Return: The device_node pointer with refcount incremented. Use
1069+
* of_node_put() on it when done.
1070+
*/
1071+
static inline struct device_node *of_parse_phandle(const struct device_node *np,
1072+
const char *phandle_name,
1073+
int index)
1074+
{
1075+
struct of_phandle_args args;
1076+
1077+
if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
1078+
index, &args))
1079+
return NULL;
1080+
1081+
return args.np;
1082+
}
1083+
1084+
/**
1085+
* of_parse_phandle_with_args() - Find a node pointed by phandle in a list
1086+
* @np: pointer to a device tree node containing a list
1087+
* @list_name: property name that contains a list
1088+
* @cells_name: property name that specifies phandles' arguments count
1089+
* @index: index of a phandle to parse out
1090+
* @out_args: optional pointer to output arguments structure (will be filled)
1091+
*
1092+
* This function is useful to parse lists of phandles and their arguments.
1093+
* Returns 0 on success and fills out_args, on error returns appropriate
1094+
* errno value.
1095+
*
1096+
* Caller is responsible to call of_node_put() on the returned out_args->np
1097+
* pointer.
1098+
*
1099+
* Example::
1100+
*
1101+
* phandle1: node1 {
1102+
* #list-cells = <2>;
1103+
* };
1104+
*
1105+
* phandle2: node2 {
1106+
* #list-cells = <1>;
1107+
* };
1108+
*
1109+
* node3 {
1110+
* list = <&phandle1 1 2 &phandle2 3>;
1111+
* };
1112+
*
1113+
* To get a device_node of the ``node2`` node you may call this:
1114+
* of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
1115+
*/
1116+
static inline int of_parse_phandle_with_args(const struct device_node *np,
1117+
const char *list_name,
1118+
const char *cells_name,
1119+
int index,
1120+
struct of_phandle_args *out_args)
1121+
{
1122+
int cell_count = -1;
1123+
1124+
/* If cells_name is NULL we assume a cell count of 0 */
1125+
if (!cells_name)
1126+
cell_count = 0;
1127+
1128+
return __of_parse_phandle_with_args(np, list_name, cells_name,
1129+
cell_count, index, out_args);
1130+
}
1131+
1132+
/**
1133+
* of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
1134+
* @np: pointer to a device tree node containing a list
1135+
* @list_name: property name that contains a list
1136+
* @cell_count: number of argument cells following the phandle
1137+
* @index: index of a phandle to parse out
1138+
* @out_args: optional pointer to output arguments structure (will be filled)
1139+
*
1140+
* This function is useful to parse lists of phandles and their arguments.
1141+
* Returns 0 on success and fills out_args, on error returns appropriate
1142+
* errno value.
1143+
*
1144+
* Caller is responsible to call of_node_put() on the returned out_args->np
1145+
* pointer.
1146+
*
1147+
* Example::
1148+
*
1149+
* phandle1: node1 {
1150+
* };
1151+
*
1152+
* phandle2: node2 {
1153+
* };
1154+
*
1155+
* node3 {
1156+
* list = <&phandle1 0 2 &phandle2 2 3>;
1157+
* };
1158+
*
1159+
* To get a device_node of the ``node2`` node you may call this:
1160+
* of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
1161+
*/
1162+
static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
1163+
const char *list_name,
1164+
int cell_count,
1165+
int index,
1166+
struct of_phandle_args *out_args)
1167+
{
1168+
return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
1169+
index, out_args);
1170+
}
1171+
10801172
/**
10811173
* of_property_count_u8_elems - Count the number of u8 elements in a property
10821174
*

0 commit comments

Comments
 (0)