drivers/of: Constify device_node->name and ->path_component_name
authorGrant Likely <grant.likely@secretlab.ca>
Wed, 14 Nov 2012 22:37:12 +0000 (22:37 +0000)
committerGrant Likely <grant.likely@secretlab.ca>
Sat, 17 Nov 2012 12:05:57 +0000 (12:05 +0000)
Neither of these should ever be changed once set. Make them const and
fix up the users that try to modify it in-place. In one case
kmalloc+memcpy is replaced with kstrdup() to avoid modifying the string.

Build tested with defconfigs on ARM, PowerPC, Sparc, MIPS, x86 among
others.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Julian Calaby <julian.calaby@gmail.com>
arch/powerpc/platforms/powermac/pfunc_core.c
arch/powerpc/platforms/pseries/reconfig.c
arch/powerpc/sysdev/fsl_pci.c
arch/sparc/kernel/pci_impl.h
drivers/of/fdt.c
include/linux/of.h

index b0c3777528a1e418387e312b4ae75183aa2de8c8..d588e48dff74cd9d1469e4dfafce5627ec09b4f2 100644 (file)
@@ -686,7 +686,7 @@ static int pmf_add_functions(struct pmf_device *dev, void *driverdata)
        int count = 0;
 
        for (pp = dev->node->properties; pp != 0; pp = pp->next) {
-               char *name;
+               const char *name;
                if (strncmp(pp->name, PP_PREFIX, plen) != 0)
                        continue;
                name = pp->name + plen;
index 39f71fba9b38eed2e34d717d2bd2e4ea1ca38925..2f4668136b200d9f22a25c7761749e7e512b315f 100644 (file)
@@ -281,12 +281,11 @@ static struct property *new_property(const char *name, const int length,
        if (!new)
                return NULL;
 
-       if (!(new->name = kmalloc(strlen(name) + 1, GFP_KERNEL)))
+       if (!(new->name = kstrdup(name, GFP_KERNEL)))
                goto cleanup;
        if (!(new->value = kmalloc(length + 1, GFP_KERNEL)))
                goto cleanup;
 
-       strcpy(new->name, name);
        memcpy(new->value, value, length);
        *(((char *)new->value) + length) = 0;
        new->length = length;
index ffb93ae9379b1bb282ca2e99db53049974e81d95..01b62a62c63582d2a56e870e2522186185391446 100644 (file)
@@ -136,7 +136,7 @@ static void __init setup_pci_atmu(struct pci_controller *hose,
        u32 pcicsrbar = 0, pcicsrbar_sz;
        u32 piwar = PIWAR_EN | PIWAR_PF | PIWAR_TGI_LOCAL |
                        PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
-       char *name = hose->dn->full_name;
+       const char *name = hose->dn->full_name;
        const u64 *reg;
        int len;
 
index 918a2031c8bbc855c7ee7a3eac30c82ab5f94ca4..5f688531f48cfff4754b993cdf855bded6432f3e 100644 (file)
@@ -88,7 +88,7 @@ struct pci_pbm_info {
        int                             chip_revision;
 
        /* Name used for top-level resources. */
-       char                            *name;
+       const char                      *name;
 
        /* OBP specific information. */
        struct platform_device          *op;
index c2b08dcdbc537fd2d0320542f885ad4e686ad0ee..c8be32644c851348636f38c459c05872f81c5282 100644 (file)
@@ -199,10 +199,10 @@ static unsigned long unflatten_dt_node(struct boot_param_header *blob,
        np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl,
                                __alignof__(struct device_node));
        if (allnextpp) {
+               char *fn;
                memset(np, 0, sizeof(*np));
-               np->full_name = ((char *)np) + sizeof(struct device_node);
+               np->full_name = fn = ((char *)np) + sizeof(*np);
                if (new_format) {
-                       char *fn = np->full_name;
                        /* rebuild full path for new format */
                        if (dad && dad->parent) {
                                strcpy(fn, dad->full_name);
@@ -216,9 +216,9 @@ static unsigned long unflatten_dt_node(struct boot_param_header *blob,
                                fn += strlen(fn);
                        }
                        *(fn++) = '/';
-                       memcpy(fn, pathp, l);
-               } else
-                       memcpy(np->full_name, pathp, l);
+               }
+               memcpy(fn, pathp, l);
+
                prev_pp = &np->properties;
                **allnextpp = np;
                *allnextpp = &np->allnext;
index b4e50d56fc7440b1b1d03849e33b77acf7ee41b6..857dde984a6edfbfed848f9ff298c523a265866b 100644 (file)
@@ -46,7 +46,7 @@ struct device_node {
        const char *name;
        const char *type;
        phandle phandle;
-       char    *full_name;
+       const char *full_name;
 
        struct  property *properties;
        struct  property *deadprops;    /* removed properties */
@@ -60,7 +60,7 @@ struct device_node {
        unsigned long _flags;
        void    *data;
 #if defined(CONFIG_SPARC)
-       char    *path_component_name;
+       const char *path_component_name;
        unsigned int unique_id;
        struct of_irq_controller *irq_trans;
 #endif