Skip to content

Commit 9c63fea

Browse files
committed
of: Constify struct property pointers
Most accesses to struct property do not modify it, so constify struct property pointers where ever possible in the DT core code. Reviewed-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent ec8c232 commit 9c63fea

File tree

7 files changed

+33
-32
lines changed

7 files changed

+33
-32
lines changed

drivers/of/base.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ EXPORT_SYMBOL(of_find_all_nodes);
270270
const void *__of_get_property(const struct device_node *np,
271271
const char *name, int *lenp)
272272
{
273-
struct property *pp = __of_find_property(np, name, lenp);
273+
const struct property *pp = __of_find_property(np, name, lenp);
274274

275275
return pp ? pp->value : NULL;
276276
}
@@ -282,7 +282,7 @@ const void *__of_get_property(const struct device_node *np,
282282
const void *of_get_property(const struct device_node *np, const char *name,
283283
int *lenp)
284284
{
285-
struct property *pp = of_find_property(np, name, lenp);
285+
const struct property *pp = of_find_property(np, name, lenp);
286286

287287
return pp ? pp->value : NULL;
288288
}
@@ -321,7 +321,7 @@ EXPORT_SYMBOL(of_get_property);
321321
static int __of_device_is_compatible(const struct device_node *device,
322322
const char *compat, const char *type, const char *name)
323323
{
324-
struct property *prop;
324+
const struct property *prop;
325325
const char *cp;
326326
int index = 0, score = 0;
327327

@@ -828,7 +828,7 @@ struct device_node *__of_find_node_by_full_path(struct device_node *node,
828828
struct device_node *of_find_node_opts_by_path(const char *path, const char **opts)
829829
{
830830
struct device_node *np = NULL;
831-
struct property *pp;
831+
const struct property *pp;
832832
unsigned long flags;
833833
const char *separator = strchr(path, ':');
834834

@@ -974,7 +974,7 @@ struct device_node *of_find_node_with_property(struct device_node *from,
974974
const char *prop_name)
975975
{
976976
struct device_node *np;
977-
struct property *pp;
977+
const struct property *pp;
978978
unsigned long flags;
979979

980980
raw_spin_lock_irqsave(&devtree_lock, flags);
@@ -1769,7 +1769,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
17691769
*/
17701770
void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
17711771
{
1772-
struct property *pp;
1772+
const struct property *pp;
17731773

17741774
of_aliases = of_find_node_by_path("/aliases");
17751775
of_chosen = of_find_node_by_path("/chosen");

drivers/of/kobj.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp)
8484
return rc;
8585
}
8686

87-
void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
87+
void __of_sysfs_remove_bin_file(struct device_node *np, const struct property *prop)
8888
{
8989
if (!IS_ENABLED(CONFIG_SYSFS))
9090
return;
@@ -93,15 +93,15 @@ void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop)
9393
kfree(prop->attr.attr.name);
9494
}
9595

96-
void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
96+
void __of_remove_property_sysfs(struct device_node *np, const struct property *prop)
9797
{
9898
/* at early boot, bail here and defer setup to of_init() */
9999
if (of_kset && of_node_is_attached(np))
100100
__of_sysfs_remove_bin_file(np, prop);
101101
}
102102

103103
void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
104-
struct property *oldprop)
104+
const struct property *oldprop)
105105
{
106106
/* At early boot, bail out and defer setup to of_init() */
107107
if (!of_kset)

drivers/of/of_private.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ static inline void of_platform_register_reconfig_notifier(void) { }
6969
#if defined(CONFIG_OF_KOBJ)
7070
int of_node_is_attached(const struct device_node *node);
7171
int __of_add_property_sysfs(struct device_node *np, struct property *pp);
72-
void __of_remove_property_sysfs(struct device_node *np, struct property *prop);
72+
void __of_remove_property_sysfs(struct device_node *np, const struct property *prop);
7373
void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
74-
struct property *oldprop);
74+
const struct property *oldprop);
7575
int __of_attach_node_sysfs(struct device_node *np);
7676
void __of_detach_node_sysfs(struct device_node *np);
7777
#else
7878
static inline int __of_add_property_sysfs(struct device_node *np, struct property *pp)
7979
{
8080
return 0;
8181
}
82-
static inline void __of_remove_property_sysfs(struct device_node *np, struct property *prop) {}
82+
static inline void __of_remove_property_sysfs(struct device_node *np, const struct property *prop) {}
8383
static inline void __of_update_property_sysfs(struct device_node *np,
84-
struct property *newprop, struct property *oldprop) {}
84+
struct property *newprop, const struct property *oldprop) {}
8585
static inline int __of_attach_node_sysfs(struct device_node *np)
8686
{
8787
return 0;
@@ -142,7 +142,7 @@ extern int __of_update_property(struct device_node *np,
142142
extern void __of_detach_node(struct device_node *np);
143143

144144
extern void __of_sysfs_remove_bin_file(struct device_node *np,
145-
struct property *prop);
145+
const struct property *prop);
146146

147147
/* illegal phandle value (set when unresolved) */
148148
#define OF_PHANDLE_ILLEGAL 0xdeadbeef

drivers/of/overlay.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,11 @@ static struct property *dup_and_fixup_symbol_prop(
296296
* invalid @overlay.
297297
*/
298298
static int add_changeset_property(struct overlay_changeset *ovcs,
299-
struct target *target, struct property *overlay_prop,
299+
struct target *target, const struct property *overlay_prop,
300300
bool is_symbols_prop)
301301
{
302-
struct property *new_prop = NULL, *prop;
302+
struct property *new_prop = NULL;
303+
const struct property *prop;
303304
int ret = 0;
304305

305306
if (target->in_livetree)

drivers/of/property.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ EXPORT_SYMBOL(of_graph_is_present);
6868
int of_property_count_elems_of_size(const struct device_node *np,
6969
const char *propname, int elem_size)
7070
{
71-
struct property *prop = of_find_property(np, propname, NULL);
71+
const struct property *prop = of_find_property(np, propname, NULL);
7272

7373
if (!prop)
7474
return -EINVAL;
@@ -104,7 +104,7 @@ EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
104104
static void *of_find_property_value_of_size(const struct device_node *np,
105105
const char *propname, u32 min, u32 max, size_t *len)
106106
{
107-
struct property *prop = of_find_property(np, propname, NULL);
107+
const struct property *prop = of_find_property(np, propname, NULL);
108108

109109
if (!prop)
110110
return ERR_PTR(-EINVAL);
@@ -530,7 +530,7 @@ int of_property_read_string_helper(const struct device_node *np,
530530
}
531531
EXPORT_SYMBOL_GPL(of_property_read_string_helper);
532532

533-
const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
533+
const __be32 *of_prop_next_u32(const struct property *prop, const __be32 *cur,
534534
u32 *pu)
535535
{
536536
const void *curv = cur;
@@ -553,7 +553,7 @@ const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
553553
}
554554
EXPORT_SYMBOL_GPL(of_prop_next_u32);
555555

556-
const char *of_prop_next_string(struct property *prop, const char *cur)
556+
const char *of_prop_next_string(const struct property *prop, const char *cur)
557557
{
558558
const void *curv = cur;
559559

@@ -1466,7 +1466,7 @@ static int of_fwnode_irq_get(const struct fwnode_handle *fwnode,
14661466

14671467
static int of_fwnode_add_links(struct fwnode_handle *fwnode)
14681468
{
1469-
struct property *p;
1469+
const struct property *p;
14701470
struct device_node *con_np = to_of_node(fwnode);
14711471

14721472
if (IS_ENABLED(CONFIG_X86))

drivers/of/resolver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void adjust_overlay_phandles(struct device_node *overlay,
4242
int phandle_delta)
4343
{
4444
struct device_node *child;
45-
struct property *prop;
45+
const struct property *prop;
4646
phandle phandle;
4747

4848
/* adjust node's phandle in node */
@@ -71,10 +71,10 @@ static void adjust_overlay_phandles(struct device_node *overlay,
7171
}
7272

7373
static int update_usages_of_a_phandle_reference(struct device_node *overlay,
74-
struct property *prop_fixup, phandle phandle)
74+
const struct property *prop_fixup, phandle phandle)
7575
{
7676
struct device_node *refnode;
77-
struct property *prop;
77+
const struct property *prop;
7878
char *value __free(kfree) = kmemdup(prop_fixup->value, prop_fixup->length, GFP_KERNEL);
7979
char *cur, *end, *node_path, *prop_name, *s;
8080
int offset, len;
@@ -151,7 +151,7 @@ static int adjust_local_phandle_references(const struct device_node *local_fixup
151151
const struct device_node *overlay, int phandle_delta)
152152
{
153153
struct device_node *overlay_child;
154-
struct property *prop_fix, *prop;
154+
const struct property *prop_fix, *prop;
155155
int err, i, count;
156156
unsigned int off;
157157

include/linux/of.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ extern int of_detach_node(struct device_node *);
435435
* of_property_for_each_u32(np, "propname", u)
436436
* printk("U32 value: %x\n", u);
437437
*/
438-
const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
438+
const __be32 *of_prop_next_u32(const struct property *prop, const __be32 *cur,
439439
u32 *pu);
440440
/*
441441
* struct property *prop;
@@ -444,7 +444,7 @@ const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
444444
* of_property_for_each_string(np, "propname", prop, s)
445445
* printk("String value: %s\n", s);
446446
*/
447-
const char *of_prop_next_string(struct property *prop, const char *cur);
447+
const char *of_prop_next_string(const struct property *prop, const char *cur);
448448

449449
bool of_console_check(const struct device_node *dn, char *name, int index);
450450

@@ -826,13 +826,13 @@ static inline bool of_console_check(const struct device_node *dn, const char *na
826826
return false;
827827
}
828828

829-
static inline const __be32 *of_prop_next_u32(struct property *prop,
829+
static inline const __be32 *of_prop_next_u32(const struct property *prop,
830830
const __be32 *cur, u32 *pu)
831831
{
832832
return NULL;
833833
}
834834

835-
static inline const char *of_prop_next_string(struct property *prop,
835+
static inline const char *of_prop_next_string(const struct property *prop,
836836
const char *cur)
837837
{
838838
return NULL;
@@ -899,7 +899,7 @@ static inline const void *of_device_get_match_data(const struct device *dev)
899899
#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
900900
#endif
901901

902-
static inline int of_prop_val_eq(struct property *p1, struct property *p2)
902+
static inline int of_prop_val_eq(const struct property *p1, const struct property *p2)
903903
{
904904
return p1->length == p2->length &&
905905
!memcmp(p1->value, p2->value, (size_t)p1->length);
@@ -1252,7 +1252,7 @@ static inline int of_property_read_string_index(const struct device_node *np,
12521252
static inline bool of_property_read_bool(const struct device_node *np,
12531253
const char *propname)
12541254
{
1255-
struct property *prop = of_find_property(np, propname, NULL);
1255+
const struct property *prop = of_find_property(np, propname, NULL);
12561256

12571257
return prop ? true : false;
12581258
}
@@ -1430,7 +1430,7 @@ static inline int of_property_read_s32(const struct device_node *np,
14301430
err = of_phandle_iterator_next(it))
14311431

14321432
#define of_property_for_each_u32(np, propname, u) \
1433-
for (struct {struct property *prop; const __be32 *item; } _it = \
1433+
for (struct {const struct property *prop; const __be32 *item; } _it = \
14341434
{of_find_property(np, propname, NULL), \
14351435
of_prop_next_u32(_it.prop, NULL, &u)}; \
14361436
_it.item; \

0 commit comments

Comments
 (0)