* [PATCH] drivers/of: Constify device_node->name and ->path_component_name
@ 2012-11-14 22:28 Grant Likely
2012-11-14 22:33 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2012-11-14 22:28 UTC (permalink / raw)
To: linux-kernel, devicetree-discuss
Cc: sparclinux, Grant Likely, Benjamin Herrenschmidt, David S. Miller
Neither of these should ever be changed once set. Make them const
Build tested with defconfigs on ARM, PowerPC, Sparc, MIPS, x86 among
others.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "David S. Miller" <davem@davemloft.net>
---
arch/powerpc/platforms/powermac/pfunc_core.c | 2 +-
arch/powerpc/platforms/pseries/reconfig.c | 3 +--
arch/powerpc/sysdev/fsl_pci.c | 2 +-
arch/sparc/kernel/pci_impl.h | 2 +-
drivers/of/fdt.c | 10 +++++-----
include/linux/of.h | 4 ++--
6 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/arch/powerpc/platforms/powermac/pfunc_core.c b/arch/powerpc/platforms/powermac/pfunc_core.c
index b0c3777..d588e48 100644
--- a/arch/powerpc/platforms/powermac/pfunc_core.c
+++ b/arch/powerpc/platforms/powermac/pfunc_core.c
@@ -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;
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index 39f71fb..2f46681 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -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;
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index ffb93ae..01b62a6 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -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;
diff --git a/arch/sparc/kernel/pci_impl.h b/arch/sparc/kernel/pci_impl.h
index 918a203..5f68853 100644
--- a/arch/sparc/kernel/pci_impl.h
+++ b/arch/sparc/kernel/pci_impl.h
@@ -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;
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 91a375f..4aded3b 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -198,10 +198,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);
@@ -215,9 +215,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;
diff --git a/include/linux/of.h b/include/linux/of.h
index b4e50d5..857dde9 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -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
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/of: Constify device_node->name and ->path_component_name
2012-11-14 22:28 [PATCH] drivers/of: Constify device_node->name and ->path_component_name Grant Likely
@ 2012-11-14 22:33 ` David Miller
2012-11-14 22:42 ` Grant Likely
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2012-11-14 22:33 UTC (permalink / raw)
To: grant.likely; +Cc: linux-kernel, devicetree-discuss, sparclinux, benh
You're making other changes here, such as the kstrdup() stuff,
seperate that into another patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/of: Constify device_node->name and ->path_component_name
2012-11-14 22:33 ` David Miller
@ 2012-11-14 22:42 ` Grant Likely
2012-11-14 22:46 ` Julian Calaby
2012-11-14 22:49 ` David Miller
0 siblings, 2 replies; 6+ messages in thread
From: Grant Likely @ 2012-11-14 22:42 UTC (permalink / raw)
To: David Miller; +Cc: linux-kernel, devicetree-discuss, sparclinux, benh
On Wed, Nov 14, 2012 at 10:33 PM, David Miller <davem@davemloft.net> wrote:
>
> You're making other changes here, such as the kstrdup() stuff,
> seperate that into another patch.
It's part of the same change. The original code was allocating a
buffer, saving the pointer in the name field and then modifying it.
Making the code to a kstrdup() gets rid of modifying the const buffer.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/of: Constify device_node->name and ->path_component_name
2012-11-14 22:42 ` Grant Likely
@ 2012-11-14 22:46 ` Julian Calaby
2012-11-14 22:48 ` Grant Likely
2012-11-14 22:49 ` David Miller
1 sibling, 1 reply; 6+ messages in thread
From: Julian Calaby @ 2012-11-14 22:46 UTC (permalink / raw)
To: Grant Likely
Cc: David Miller, linux-kernel, devicetree-discuss, sparclinux, benh
Hi Grant,
On Thu, Nov 15, 2012 at 9:42 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
> On Wed, Nov 14, 2012 at 10:33 PM, David Miller <davem@davemloft.net> wrote:
>>
>> You're making other changes here, such as the kstrdup() stuff,
>> seperate that into another patch.
>
> It's part of the same change. The original code was allocating a
> buffer, saving the pointer in the name field and then modifying it.
> Making the code to a kstrdup() gets rid of modifying the const buffer.
You should really mention this in the commit log, maybe something like:
[PATCH] drivers/of: Constify device_node->name and ->path_component_name
Neither of these should ever be changed once set. Make them const
Also use kstrdup() instead of memcpy() so we don't attempt to modify them.
Build tested with defconfigs on ARM, PowerPC, Sparc, MIPS, x86 among
others.
Thanks,
--
Julian Calaby
Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/of: Constify device_node->name and ->path_component_name
2012-11-14 22:46 ` Julian Calaby
@ 2012-11-14 22:48 ` Grant Likely
0 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2012-11-14 22:48 UTC (permalink / raw)
To: Julian Calaby
Cc: David Miller, linux-kernel, devicetree-discuss, sparclinux, benh
On Wed, Nov 14, 2012 at 10:46 PM, Julian Calaby <julian.calaby@gmail.com> wrote:
> Hi Grant,
>
> On Thu, Nov 15, 2012 at 9:42 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
>> On Wed, Nov 14, 2012 at 10:33 PM, David Miller <davem@davemloft.net> wrote:
>>>
>>> You're making other changes here, such as the kstrdup() stuff,
>>> seperate that into another patch.
>>
>> It's part of the same change. The original code was allocating a
>> buffer, saving the pointer in the name field and then modifying it.
>> Making the code to a kstrdup() gets rid of modifying the const buffer.
>
> You should really mention this in the commit log, maybe something like:
>
>
> [PATCH] drivers/of: Constify device_node->name and ->path_component_name
>
> Neither of these should ever be changed once set. Make them const
>
> Also use kstrdup() instead of memcpy() so we don't attempt to modify them.
Yup, will do.
g.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/of: Constify device_node->name and ->path_component_name
2012-11-14 22:42 ` Grant Likely
2012-11-14 22:46 ` Julian Calaby
@ 2012-11-14 22:49 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2012-11-14 22:49 UTC (permalink / raw)
To: grant.likely; +Cc: linux-kernel, devicetree-discuss, sparclinux, benh
From: Grant Likely <grant.likely@secretlab.ca>
Date: Wed, 14 Nov 2012 22:42:26 +0000
> On Wed, Nov 14, 2012 at 10:33 PM, David Miller <davem@davemloft.net> wrote:
>>
>> You're making other changes here, such as the kstrdup() stuff,
>> seperate that into another patch.
>
> It's part of the same change. The original code was allocating a
> buffer, saving the pointer in the name field and then modifying it.
> Making the code to a kstrdup() gets rid of modifying the const buffer.
Please mention that in your commit message then, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-11-14 22:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-14 22:28 [PATCH] drivers/of: Constify device_node->name and ->path_component_name Grant Likely
2012-11-14 22:33 ` David Miller
2012-11-14 22:42 ` Grant Likely
2012-11-14 22:46 ` Julian Calaby
2012-11-14 22:48 ` Grant Likely
2012-11-14 22:49 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).