clk/ti/adpll: allocate room for terminating null
Subsystems (2)
PATCH 1/1 clk/ti/adpll: allocate room for terminating null
The buffer allocated in ti_adpll_clk_get_name doesn't account for the terminating null. This patch adds the extra byte, and switches to snprintf to avoid overflowing.
--- drivers/clk/ti/adpll.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/clk/ti/adpll.c +4 -3
@@ -196,12 +196,13 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, }else {const char *base_name ="adpll" ;char *buf; +size_t size =8 +1 +strlen (base_name) +1 + +strlen (postfix) +1 ; - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); + buf =devm_kzalloc (d->dev, size,GFP_KERNEL );if (!buf)return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); +snprintf (buf, size,"%08lx.%s.%s" , d->pa, base_name, postfix); name = buf; }
Signature · 1 line
2.20.1
Quoted 20 lines · Stephen Kitt
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch adds the extra byte, and switches to snprintf to avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>--- drivers/clk/ti/adpll.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/clk/ti/adpll.c +2
-0@@ -196,12 +196,13 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, }else {const char *base_name ="adpll" ;char *buf; +size_t size =8 +1 +strlen (base_name) +1 + +strlen (postfix) +1 ;
drivers/clk/ti/adpll.c static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, · line 208
Quoted 10 lines
drivers/clk/ti/adpll.c +2
-3- buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); + buf =devm_kzalloc (d->dev, size,GFP_KERNEL );if (!buf)return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); +snprintf (buf, size,"%08lx.%s.%s" , d->pa, base_name, postfix); name = buf; }
Thanks for catching this. Maybe just use devm_kasprintf() here?
Regards,
Tony
Le 27/09/2019 17:23, Tony Lindgren a écrit :
Quoted 22 lines · Stephen Kitt
Quoted 21 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch adds the extra byte, and switches to snprintf to avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>--- drivers/clk/ti/adpll.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/clk/ti/adpll.c +2
-0@@ -196,12 +196,13 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, }else {const char *base_name ="adpll" ;char *buf; +size_t size =8 +1 +strlen (base_name) +1 + +strlen (postfix) +1 ;
Quoted 12 lines
drivers/clk/ti/adpll.c static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, · line 207
Quoted 10 lines
drivers/clk/ti/adpll.c +2
-3- buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); + buf =devm_kzalloc (d->dev, size,GFP_KERNEL );if (!buf)return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); +snprintf (buf, size,"%08lx.%s.%s" , d->pa, base_name, postfix); name = buf; }Thanks for catching this. Maybe just use
devm_kasprintf()here?
Ah yes, that would be much better! V2 coming up, thanks for the suggestion.
Regards,
Stephen
PATCH v2 1/1 clk/ti/adpll: allocate room for terminating null
The buffer allocated in ti_adpll_clk_get_name doesn't account for the terminating null. This patch switches to ka_sprintf to avoid overflowing.
--- drivers/clk/ti/adpll.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/clk/ti/adpll.c +2 -8
@@ -195,14 +195,8 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d,return NULL ; }else {const char *base_name ="adpll" ; -char *buf; - - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); -if (!buf) -return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); - name = buf; + name =devm_kasprintf (d->dev,GFP_KERNEL ,"%08lx.%s.%s" , + d->pa, base_name, postfix); }return name;
Signature · 1 line
2.20.1
Le 27/09/2019 20:05, Stephen Kitt a écrit :
Quoted 2 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches toka_sprintfto avoid
Aargh, devm_kasprintf of course...
Quoted 29 lines
overflowing.
Signed-off-by Stephen Kitt <[email protected]>--- drivers/clk/ti/adpll.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)drivers/clk/ti/adpll.c +2
-8@@ -195,14 +195,8 @@ static const char *ti_adpll_clk_get_name(structti_adpll_data *d, return NULL; }else {const char *base_name ="adpll" ; -char *buf; - - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); -if (!buf) -return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); - name = buf; + name =devm_kasprintf (d->dev,GFP_KERNEL ,"%08lx.%s.%s" , + d->pa, base_name, postfix); }return name;
Stephen Boyd
maintainerQuoting Stephen Kitt (2019-09-27 11:05:59)
Quoted 14 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches toka_sprintfto avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>--- drivers/clk/ti/adpll.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)drivers/clk/ti/adpll.c +0
-0
drivers/clk/ti/adpll.c static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, · line 197
Quoted 3 lines
drivers/clk/ti/adpll.c +0
-0@@ -195,14 +195,8 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d,return NULL ; }else {const char *base_name ="adpll" ;
This is used once.
drivers/clk/ti/adpll.c static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, · line 198
Quoted 9 lines
drivers/clk/ti/adpll.c +1
-8-char *buf; - - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); -if (!buf) -return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); - name = buf; + name = devm_kasprintf(d->dev, GFP_KERNEL, "%08lx.%s.%s",
So why not make this "%08lx.adpll.%s"?
Quoted 2 lines
drivers/clk/ti/adpll.c +1
-0+ d->pa, base_name, postfix); }
Quoted 31 lines · Stephen Boyd
Quoting Stephen Kitt (2019-09-27 11:05:59)
Quoted 14 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches toka_sprintfto avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>--- drivers/clk/ti/adpll.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)drivers/clk/ti/adpll.c +0
-0drivers/clk/ti/adpll.c static const char *ti_adpll_clk_get_name(struct · line 197
Quoted 3 lines
drivers/clk/ti/adpll.c +0
-0@@ -195,14 +195,8 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, return NULL; }else {const char *base_name ="adpll" ;This is used once.
drivers/clk/ti/adpll.c static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d, · line 198
Quoted 9 lines
drivers/clk/ti/adpll.c +1
-8-char *buf; - - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); -if (!buf) -return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); - name = buf; + name = devm_kasprintf(d->dev, GFP_KERNEL, "%08lx.%s.%s",
Quoted 1 line
So why not make this "%08lx.adpll.%s"?
Thanks for the review! I hesitated to do this because I thought the purely formatting string "%08lx.%s.%s" made the resulting code easier to understand than a combined "%08lx.adpll.%s". I’ll follow up with a v3 which merges the "adpll" string into the format string.
Regards,
Stephen
PATCH v3 1/1 clk/ti/adpll: allocate room for terminating null
The buffer allocated in ti_adpll_clk_get_name doesn't account for the terminating null. This patch switches to devm_kasprintf to avoid overflowing.
---
Changes since v2:
- Move "adpll" into the format string and drop base_name entirely.
Changes since v1:
- Use devm_kasprintf instead of manually allocating the target buffer.
--- drivers/clk/ti/adpll.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/clk/ti/adpll.c +2 -9
@@ -194,15 +194,8 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d,if (err)return NULL ; }else { -const char *base_name ="adpll" ; -char *buf; - - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); -if (!buf) -return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); - name = buf; + name =devm_kasprintf (d->dev,GFP_KERNEL ,"%08lx.adpll.%s" , + d->pa, postfix); }return name;
Signature · 1 line
2.20.1
Quoted 4 lines · Stephen Kitt
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches todevm_kasprintfto avoid overflowing.
Quoted 8 lines
Signed-off-by Stephen Kitt <[email protected]>---
Changes since v2:
- Move "adpll" into the format string and dropbase_nameentirely.Changes since v1:
- Usedevm_kasprintfinstead of manually allocating the target buffer.
Quoted 29 lines
--- drivers/clk/ti/adpll.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)drivers/clk/ti/adpll.c +2
-9@@ -194,15 +194,8 @@ static const char *ti_adpll_clk_get_name(struct ti_adpll_data *d,if (err)return NULL ; }else { -const char *base_name ="adpll" ; -char *buf; - - buf =devm_kzalloc (d->dev,8 +1 +strlen (base_name) +1 + -strlen (postfix),GFP_KERNEL ); -if (!buf) -return NULL ; -sprintf (buf,"%08lx.%s.%s" , d->pa, base_name, postfix); - name = buf; + name =devm_kasprintf (d->dev,GFP_KERNEL ,"%08lx.adpll.%s" , + d->pa, postfix); }return name;Signature · 1 line
2.20.1
Stephen Boyd
maintainerQuoting Stephen Kitt (2019-10-19 07:06:34)
Quoted 6 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches todevm_kasprintfto avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>---
Please don't send as replies to existing threads. It screws up my tooling and makes it more manual to apply the patch. I guess I'll have to go fix my scripts to ignore certain emails.
Quoted 11 lines · Stephen Boyd
Quoting Stephen Kitt (2019-10-19 07:06:34)
Quoted 6 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches todevm_kasprintfto avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>---
Please don't send as replies to existing threads. It screws up my tooling and makes it more manual to apply the patch. I guess I'll have to go fix my scripts to ignore certain emails.
My bad, sorry about that, I misread the In-Reply-To section of submitting-patches :-(.
Regards,
Stephen
Quoting Stephen Kitt (2019-10-19 07:06:34)
Quoted 6 lines
The buffer allocated in
ti_adpll_clk_get_namedoesn't account for the terminating null. This patch switches todevm_kasprintfto avoid overflowing.Signed-off-by Stephen Kitt <[email protected]>---
Applied to clk-next