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

powerpc/pseries: re-use code from of_helpers module

The derive_parent() has similar semantics to what we have in newly introduced
of_helpers module. The replacement reduces code base and propagates the actual
error code to the caller.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Andy Shevchenko and committed by
Michael Ellerman
06bacefc a46d9884

+5 -26
+5 -26
arch/powerpc/platforms/pseries/dlpar.c
··· 18 18 #include <linux/cpu.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/of.h> 21 + 22 + #include "of_helpers.h" 21 23 #include "offline_states.h" 22 24 #include "pseries.h" 23 25 ··· 246 244 return first_dn; 247 245 } 248 246 249 - static struct device_node *derive_parent(const char *path) 250 - { 251 - struct device_node *parent; 252 - char *last_slash; 253 - 254 - last_slash = strrchr(path, '/'); 255 - if (last_slash == path) { 256 - parent = of_find_node_by_path("/"); 257 - } else { 258 - char *parent_path; 259 - int parent_path_len = last_slash - path + 1; 260 - parent_path = kmalloc(parent_path_len, GFP_KERNEL); 261 - if (!parent_path) 262 - return NULL; 263 - 264 - strlcpy(parent_path, path, parent_path_len); 265 - parent = of_find_node_by_path(parent_path); 266 - kfree(parent_path); 267 - } 268 - 269 - return parent; 270 - } 271 - 272 247 int dlpar_attach_node(struct device_node *dn) 273 248 { 274 249 int rc; 275 250 276 - dn->parent = derive_parent(dn->full_name); 277 - if (!dn->parent) 278 - return -ENOMEM; 251 + dn->parent = pseries_of_derive_parent(dn->full_name); 252 + if (IS_ERR(dn->parent)) 253 + return PTR_ERR(dn->parent); 279 254 280 255 rc = of_attach_node(dn); 281 256 if (rc) {