Skip to content

Commit f5242e5

Browse files
committed
of/reconfig: Always use the same structure for notifiers
The OF_RECONFIG notifier callback uses a different structure depending on whether it is a node change or a property change. This is silly, and not very safe. Rework the code to use the same data structure regardless of the type of notifier. Signed-off-by: Grant Likely <grant.likely@linaro.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Cc: <linuxppc-dev@lists.ozlabs.org>
1 parent 00aa372 commit f5242e5

File tree

8 files changed

+54
-49
lines changed

8 files changed

+54
-49
lines changed

arch/powerpc/mm/numa.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,12 +1711,11 @@ static void stage_topology_update(int core_id)
17111711
static int dt_update_callback(struct notifier_block *nb,
17121712
unsigned long action, void *data)
17131713
{
1714-
struct of_prop_reconfig *update;
1714+
struct of_reconfig_data *update = data;
17151715
int rc = NOTIFY_DONE;
17161716

17171717
switch (action) {
17181718
case OF_RECONFIG_UPDATE_PROPERTY:
1719-
update = (struct of_prop_reconfig *)data;
17201719
if (!of_prop_cmp(update->dn->type, "cpu") &&
17211720
!of_prop_cmp(update->prop->name, "ibm,associativity")) {
17221721
u32 core_id;

arch/powerpc/platforms/pseries/hotplug-cpu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@ static void pseries_remove_processor(struct device_node *np)
340340
}
341341

342342
static int pseries_smp_notifier(struct notifier_block *nb,
343-
unsigned long action, void *node)
343+
unsigned long action, void *data)
344344
{
345+
struct of_reconfig_data *rd = data;
345346
int err = 0;
346347

347348
switch (action) {
348349
case OF_RECONFIG_ATTACH_NODE:
349-
err = pseries_add_processor(node);
350+
err = pseries_add_processor(rd->dn);
350351
break;
351352
case OF_RECONFIG_DETACH_NODE:
352-
pseries_remove_processor(node);
353+
pseries_remove_processor(rd->dn);
353354
break;
354355
}
355356
return notifier_from_errno(err);

arch/powerpc/platforms/pseries/hotplug-memory.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static int pseries_add_mem_node(struct device_node *np)
183183
return (ret < 0) ? -EINVAL : 0;
184184
}
185185

186-
static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
186+
static int pseries_update_drconf_memory(struct of_reconfig_data *pr)
187187
{
188188
struct of_drconf_cell *new_drmem, *old_drmem;
189189
unsigned long memblock_size;
@@ -232,22 +232,21 @@ static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
232232
}
233233

234234
static int pseries_memory_notifier(struct notifier_block *nb,
235-
unsigned long action, void *node)
235+
unsigned long action, void *data)
236236
{
237-
struct of_prop_reconfig *pr;
237+
struct of_reconfig_data *rd = data;
238238
int err = 0;
239239

240240
switch (action) {
241241
case OF_RECONFIG_ATTACH_NODE:
242-
err = pseries_add_mem_node(node);
242+
err = pseries_add_mem_node(rd->dn);
243243
break;
244244
case OF_RECONFIG_DETACH_NODE:
245-
err = pseries_remove_mem_node(node);
245+
err = pseries_remove_mem_node(rd->dn);
246246
break;
247247
case OF_RECONFIG_UPDATE_PROPERTY:
248-
pr = (struct of_prop_reconfig *)node;
249-
if (!strcmp(pr->prop->name, "ibm,dynamic-memory"))
250-
err = pseries_update_drconf_memory(pr);
248+
if (!strcmp(rd->prop->name, "ibm,dynamic-memory"))
249+
err = pseries_update_drconf_memory(rd);
251250
break;
252251
}
253252
return notifier_from_errno(err);

arch/powerpc/platforms/pseries/iommu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,10 +1251,11 @@ static struct notifier_block iommu_mem_nb = {
12511251
.notifier_call = iommu_mem_notifier,
12521252
};
12531253

1254-
static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
1254+
static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
12551255
{
12561256
int err = NOTIFY_OK;
1257-
struct device_node *np = node;
1257+
struct of_reconfig_data *rd = data;
1258+
struct device_node *np = rd->dn;
12581259
struct pci_dn *pci = PCI_DN(np);
12591260
struct direct_window *window;
12601261

arch/powerpc/platforms/pseries/setup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ static void __init pseries_discover_pic(void)
251251
" interrupt-controller\n");
252252
}
253253

254-
static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
254+
static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
255255
{
256-
struct device_node *np = node;
256+
struct of_reconfig_data *rd = data;
257+
struct device_node *np = rd->dn;
257258
struct pci_dn *pci = NULL;
258259
int err = NOTIFY_OK;
259260

drivers/crypto/nx/nx-842.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,9 @@ static int nx842_OF_upd(struct property *new_prop)
10091009
* notifier_to_errno() to decode this value
10101010
*/
10111011
static int nx842_OF_notifier(struct notifier_block *np, unsigned long action,
1012-
void *update)
1012+
void *data)
10131013
{
1014-
struct of_prop_reconfig *upd = update;
1014+
struct of_reconfig_data *upd = data;
10151015
struct nx842_devdata *local_devdata;
10161016
struct device_node *node = NULL;
10171017

drivers/of/dynamic.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,17 @@ const char *action_names[] = {
8787
};
8888
#endif
8989

90-
int of_reconfig_notify(unsigned long action, void *p)
90+
int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p)
9191
{
9292
int rc;
9393
#ifdef DEBUG
94-
struct device_node *dn = p;
95-
struct of_prop_reconfig *pr = p;
94+
struct of_reconfig_data *pr = p;
9695

9796
switch (action) {
9897
case OF_RECONFIG_ATTACH_NODE:
9998
case OF_RECONFIG_DETACH_NODE:
10099
pr_debug("of/notify %-15s %s\n", action_names[action],
101-
dn->full_name);
100+
pr->dn->full_name);
102101
break;
103102
case OF_RECONFIG_ADD_PROPERTY:
104103
case OF_RECONFIG_REMOVE_PROPERTY:
@@ -122,31 +121,22 @@ int of_reconfig_notify(unsigned long action, void *p)
122121
* Returns 0 on device going from enabled to disabled, 1 on device
123122
* going from disabled to enabled and -1 on no change.
124123
*/
125-
int of_reconfig_get_state_change(unsigned long action, void *arg)
124+
int of_reconfig_get_state_change(unsigned long action, struct of_reconfig_data *pr)
126125
{
127-
struct device_node *dn;
128-
struct property *prop, *old_prop;
129-
struct of_prop_reconfig *pr;
126+
struct property *prop, *old_prop = NULL;
130127
int is_status, status_state, old_status_state, prev_state, new_state;
131128

132129
/* figure out if a device should be created or destroyed */
133-
dn = NULL;
134-
prop = old_prop = NULL;
135130
switch (action) {
136131
case OF_RECONFIG_ATTACH_NODE:
137132
case OF_RECONFIG_DETACH_NODE:
138-
dn = arg;
139-
prop = of_find_property(dn, "status", NULL);
133+
prop = of_find_property(pr->dn, "status", NULL);
140134
break;
141135
case OF_RECONFIG_ADD_PROPERTY:
142136
case OF_RECONFIG_REMOVE_PROPERTY:
143-
pr = arg;
144-
dn = pr->dn;
145137
prop = pr->prop;
146138
break;
147139
case OF_RECONFIG_UPDATE_PROPERTY:
148-
pr = arg;
149-
dn = pr->dn;
150140
prop = pr->prop;
151141
old_prop = pr->old_prop;
152142
break;
@@ -212,7 +202,7 @@ EXPORT_SYMBOL_GPL(of_reconfig_get_state_change);
212202
int of_property_notify(int action, struct device_node *np,
213203
struct property *prop, struct property *oldprop)
214204
{
215-
struct of_prop_reconfig pr;
205+
struct of_reconfig_data pr;
216206

217207
/* only call notifiers if the node is attached */
218208
if (!of_node_is_attached(np))
@@ -250,8 +240,12 @@ void __of_attach_node(struct device_node *np)
250240
*/
251241
int of_attach_node(struct device_node *np)
252242
{
243+
struct of_reconfig_data rd;
253244
unsigned long flags;
254245

246+
memset(&rd, 0, sizeof(rd));
247+
rd.dn = np;
248+
255249
mutex_lock(&of_mutex);
256250
raw_spin_lock_irqsave(&devtree_lock, flags);
257251
__of_attach_node(np);
@@ -260,7 +254,7 @@ int of_attach_node(struct device_node *np)
260254
__of_attach_node_sysfs(np);
261255
mutex_unlock(&of_mutex);
262256

263-
of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np);
257+
of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd);
264258

265259
return 0;
266260
}
@@ -298,9 +292,13 @@ void __of_detach_node(struct device_node *np)
298292
*/
299293
int of_detach_node(struct device_node *np)
300294
{
295+
struct of_reconfig_data rd;
301296
unsigned long flags;
302297
int rc = 0;
303298

299+
memset(&rd, 0, sizeof(rd));
300+
rd.dn = np;
301+
304302
mutex_lock(&of_mutex);
305303
raw_spin_lock_irqsave(&devtree_lock, flags);
306304
__of_detach_node(np);
@@ -309,7 +307,7 @@ int of_detach_node(struct device_node *np)
309307
__of_detach_node_sysfs(np);
310308
mutex_unlock(&of_mutex);
311309

312-
of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np);
310+
of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd);
313311

314312
return rc;
315313
}
@@ -505,6 +503,7 @@ static void __of_changeset_entry_invert(struct of_changeset_entry *ce,
505503

506504
static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool revert)
507505
{
506+
struct of_reconfig_data rd;
508507
struct of_changeset_entry ce_inverted;
509508
int ret;
510509

@@ -516,7 +515,9 @@ static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool reve
516515
switch (ce->action) {
517516
case OF_RECONFIG_ATTACH_NODE:
518517
case OF_RECONFIG_DETACH_NODE:
519-
ret = of_reconfig_notify(ce->action, ce->np);
518+
memset(&rd, 0, sizeof(rd));
519+
rd.dn = ce->np;
520+
ret = of_reconfig_notify(ce->action, &rd);
520521
break;
521522
case OF_RECONFIG_ADD_PROPERTY:
522523
case OF_RECONFIG_REMOVE_PROPERTY:

include/linux/of.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ struct of_phandle_args {
7373
uint32_t args[MAX_PHANDLE_ARGS];
7474
};
7575

76+
struct of_reconfig_data {
77+
struct device_node *dn;
78+
struct property *prop;
79+
struct property *old_prop;
80+
};
81+
7682
/* initialize a node */
7783
extern struct kobj_type of_node_ktype;
7884
static inline void of_node_init(struct device_node *node)
@@ -318,12 +324,6 @@ extern int of_update_property(struct device_node *np, struct property *newprop);
318324
#define OF_RECONFIG_REMOVE_PROPERTY 0x0004
319325
#define OF_RECONFIG_UPDATE_PROPERTY 0x0005
320326

321-
struct of_prop_reconfig {
322-
struct device_node *dn;
323-
struct property *prop;
324-
struct property *old_prop;
325-
};
326-
327327
extern int of_attach_node(struct device_node *);
328328
extern int of_detach_node(struct device_node *);
329329

@@ -892,8 +892,9 @@ enum of_reconfig_change {
892892
#ifdef CONFIG_OF_DYNAMIC
893893
extern int of_reconfig_notifier_register(struct notifier_block *);
894894
extern int of_reconfig_notifier_unregister(struct notifier_block *);
895-
extern int of_reconfig_notify(unsigned long, void *);
896-
extern int of_reconfig_get_state_change(unsigned long action, void *arg);
895+
extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
896+
extern int of_reconfig_get_state_change(unsigned long action,
897+
struct of_reconfig_data *arg);
897898

898899
extern void of_changeset_init(struct of_changeset *ocs);
899900
extern void of_changeset_destroy(struct of_changeset *ocs);
@@ -941,11 +942,13 @@ static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
941942
{
942943
return -EINVAL;
943944
}
944-
static inline int of_reconfig_notify(unsigned long action, void *arg)
945+
static inline int of_reconfig_notify(unsigned long action,
946+
struct of_reconfig_data *arg)
945947
{
946948
return -EINVAL;
947949
}
948-
static inline int of_reconfig_get_state_change(unsigned long action, void *arg)
950+
static inline int of_reconfig_get_state_change(unsigned long action,
951+
struct of_reconfig_data *arg)
949952
{
950953
return -EINVAL;
951954
}

0 commit comments

Comments
 (0)