diff mbox series

[v3] clk/ti/adpll: allocate room for terminating null

Message ID 20191019140634.15596-1-steve@sk2.org (mailing list archive)
State New, archived
Headers show
Series [v3] clk/ti/adpll: allocate room for terminating null | expand

Commit Message

Stephen Kitt Oct. 19, 2019, 2:06 p.m. UTC
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.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
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(-)

Comments

Tony Lindgren Oct. 21, 2019, 2:31 p.m. UTC | #1
* Stephen Kitt <steve@sk2.org> [191019 14:07]:
> 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.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---
> 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.

Acked-by: Tony Lindgren <tony@atomide.com>

> ---
>  drivers/clk/ti/adpll.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
> index fdfb90058504..bb2f2836dab2 100644
> --- a/drivers/clk/ti/adpll.c
> +++ b/drivers/clk/ti/adpll.c
> @@ -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;
> -- 
> 2.20.1
>
Stephen Boyd Nov. 8, 2019, 5 p.m. UTC | #2
Quoting Stephen Kitt (2019-10-19 07:06:34)
> 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.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---

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.
Stephen Boyd Nov. 8, 2019, 5:01 p.m. UTC | #3
Quoting Stephen Kitt (2019-10-19 07:06:34)
> 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.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---

Applied to clk-next
Stephen Kitt Nov. 8, 2019, 8:17 p.m. UTC | #4
On Fri, 08 Nov 2019 09:00:25 -0800, Stephen Boyd <sboyd@kernel.org> wrote:
> Quoting Stephen Kitt (2019-10-19 07:06:34)
> > 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.
> > 
> > Signed-off-by: Stephen Kitt <steve@sk2.org>
> > ---  
> 
> 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
diff mbox series

Patch

diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
index fdfb90058504..bb2f2836dab2 100644
--- a/drivers/clk/ti/adpll.c
+++ b/drivers/clk/ti/adpll.c
@@ -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;