Skip to contentSkip to conversation

ASoC: fsl: expand the size of the name in fsl_ssi_private struct

PATCH In review Nicolin Chen 3 participants 3 messages May 23, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: fsl: expand the size of the name in fsl_ssi_private struct

strcpy(ssi_private->name, p) in probe() sets "name" by "p", gotten from dts, while the length of "p", if the devicetree node name of SSI is commonly set, would always be larger than 1 char size, so need a larger size for "name".

---
 sound/soc/fsl/fsl_ssi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
sound/soc/fsl/fsl_ssi.c +1 -1
index 2f2d837..b6a5f94 100644
@@ -152,5 +152,5 @@ struct fsl_ssi_private {
 	} stats;
 
-	char name[1];
+	char name[32];
 };
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 3 lines

strcpy(ssi_private->name, p) in probe() sets "name" by "p", gotten from dts, while the length of "p", if the devicetree node name of SSI is commonly set, would always be larger than 1 char size, so need a larger size for "name".

Are you sure this isn't allowed for when the structure is allocated? Otherwise you also need to use strlcpy() as well.

sound/soc/fsl/fsl_ssi.c struct fsl_ssi_private { · line 155

Quoted 6 lines
sound/soc/fsl/fsl_ssi.c +1 -1
@@ -152,5 +152,5 @@ struct fsl_ssi_private {
 	} stats;
 
-	char name[1];
+	char name[32];
 };

This looks like what c99 allows 'char name[0]' be used for. But ensure the \0 is allowed for before changing to 1 to 0.

David

#2 lore raw
Quoted 5 lines · David Laight
Quoted 3 lines

strcpy(ssi_private->name, p) in probe() sets "name" by "p", gotten from dts,

Quoted 2 lines

while the length of "p", if the devicetree node name of SSI is commonly set, would always be larger than 1 char size, so need a larger size for "name".

Are you sure this isn't allowed for when the structure is allocated? Otherwise you also need to use strlcpy() as well.

Yes, this is already handled properly:

p = strrchr(np->full_name, '/') + 1;
ssi_private = kzalloc(sizeof(struct fsl_ssi_private) + strlen(p),

                      GFP_KERNEL);

Nicolin's patch is wrong. Do not apply it.

Signature · 1 line
Timur Tabi