diff mbox series

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

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

Commit Message

Stephen Kitt Sept. 27, 2019, 6:05 p.m. UTC
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.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 drivers/clk/ti/adpll.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Stephen Kitt Sept. 27, 2019, 6:18 p.m. UTC | #1
Le 27/09/2019 20:05, Stephen Kitt a écrit :
> The buffer allocated in ti_adpll_clk_get_name doesn't account for the
> terminating null. This patch switches to ka_sprintf to avoid

Aargh, devm_kasprintf of course...

> overflowing.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---
>  drivers/clk/ti/adpll.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
> index fdfb90058504..021cf9e2b4db 100644
> --- a/drivers/clk/ti/adpll.c
> +++ b/drivers/clk/ti/adpll.c
> @@ -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;
Stephen Boyd Oct. 17, 2019, 3:48 p.m. UTC | #2
Quoting Stephen Kitt (2019-09-27 11:05:59)
> 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.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---
>  drivers/clk/ti/adpll.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
> index fdfb90058504..021cf9e2b4db 100644
> --- a/drivers/clk/ti/adpll.c
> +++ b/drivers/clk/ti/adpll.c
> @@ -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.

> -               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"?

> +                                     d->pa, base_name, postfix);
>         }
Stephen Kitt Oct. 19, 2019, 1:54 p.m. UTC | #3
On Thu, 17 Oct 2019 08:48:53 -0700, Stephen Boyd <sboyd@kernel.org> wrote:
> Quoting Stephen Kitt (2019-09-27 11:05:59)
> > 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.
> > 
> > Signed-off-by: Stephen Kitt <steve@sk2.org>
> > ---
> >  drivers/clk/ti/adpll.c | 10 ++--------
> >  1 file changed, 2 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
> > index fdfb90058504..021cf9e2b4db 100644
> > --- a/drivers/clk/ti/adpll.c
> > +++ b/drivers/clk/ti/adpll.c
> > @@ -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.
> 
> > -               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"?

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
diff mbox series

Patch

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