diff mbox series

[v3,08/10] clk: clock-wizard: Make the output names unique

Message ID d9277db2692bb77a41dfed927cfb791bdcced17d.1574922435.git.shubhrajyoti.datta@xilinx.com (mailing list archive)
State Changes Requested, archived
Headers show
Series clk: clk-wizard: clock-wizard: Driver updates | expand

Commit Message

Shubhrajyoti Datta Nov. 28, 2019, 6:36 a.m. UTC
From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>

Incase there are more than one instance of the clocking wizard.
And if the output name given is the same then the probe fails.
Fix the same by appending the device name to the output name to
make it unique.

Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
---
 drivers/clk/clk-xlnx-clock-wizard.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Dan Carpenter Nov. 28, 2019, 7:45 a.m. UTC | #1
On Thu, Nov 28, 2019 at 12:06:15PM +0530, shubhrajyoti.datta@gmail.com wrote:
> From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> 
> Incase there are more than one instance of the clocking wizard.
> And if the output name given is the same then the probe fails.
> Fix the same by appending the device name to the output name to
> make it unique.
> 
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> ---
>  drivers/clk/clk-xlnx-clock-wizard.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clk/clk-xlnx-clock-wizard.c b/drivers/clk/clk-xlnx-clock-wizard.c
> index 75ea745..9993543 100644
> --- a/drivers/clk/clk-xlnx-clock-wizard.c
> +++ b/drivers/clk/clk-xlnx-clock-wizard.c
> @@ -555,6 +555,9 @@ static int clk_wzrd_probe(struct platform_device *pdev)
>  		ret = -ENOMEM;
>  		goto err_disable_clk;
>  	}
> +	outputs = of_property_count_strings(np, "clock-output-names");
> +	if (outputs == 1)
> +		flags = CLK_SET_RATE_PARENT;
>  	clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor
>  			(&pdev->dev, clk_name,
>  			 __clk_get_name(clk_wzrd->clk_in1),
> @@ -566,9 +569,6 @@ static int clk_wzrd_probe(struct platform_device *pdev)
>  		goto err_disable_clk;
>  	}
>  
> -	outputs = of_property_count_strings(np, "clock-output-names");
> -	if (outputs == 1)
> -		flags = CLK_SET_RATE_PARENT;
>  	clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev));
>  	if (!clk_name) {
>  		ret = -ENOMEM;
> @@ -591,6 +591,7 @@ static int clk_wzrd_probe(struct platform_device *pdev)
>  	/* register div per output */
>  	for (i = outputs - 1; i >= 0 ; i--) {
>  		const char *clkout_name;
> +		const char *clkout_name_wiz;
>  
>  		if (of_property_read_string_index(np, "clock-output-names", i,
>  						  &clkout_name)) {
> @@ -599,9 +600,11 @@ static int clk_wzrd_probe(struct platform_device *pdev)
>  			ret = -EINVAL;
>  			goto err_rm_int_clks;
>  		}
> +		clkout_name_wiz = kasprintf(GFP_KERNEL, "%s_%s",
> +					    dev_name(&pdev->dev), clkout_name);

If this kasprintf() crashes then clk_wzrd_register_divf() will fail.
But that was a headache to review.  Just add a check for NULL.  We need
a kfree() as well.

One alternative would be to just declare a buffer on the stack and use
snprintf().  We don't need to keep the name around after the call to
clk_wzrd_register_divf().

regards,
dan carpenter
Shubhrajyoti Datta Nov. 29, 2019, 12:07 p.m. UTC | #2
On Thu, Nov 28, 2019 at 1:15 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Thu, Nov 28, 2019 at 12:06:15PM +0530, shubhrajyoti.datta@gmail.com wrote:
> > From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> >
> > Incase there are more than one instance of the clocking wizard.
> > And if the output name given is the same then the probe fails.
> > Fix the same by appending the device name to the output name to
> > make it unique.
> >
> > Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> > ---
> >  drivers/clk/clk-xlnx-clock-wizard.c | 13 ++++++++-----
> >  1 file changed, 8 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/clk/clk-xlnx-clock-wizard.c b/drivers/clk/clk-xlnx-clock-wizard.c
> > index 75ea745..9993543 100644
> > --- a/drivers/clk/clk-xlnx-clock-wizard.c
> > +++ b/drivers/clk/clk-xlnx-clock-wizard.c
> > @@ -555,6 +555,9 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> >               ret = -ENOMEM;
> >               goto err_disable_clk;
> >       }
> > +     outputs = of_property_count_strings(np, "clock-output-names");
> > +     if (outputs == 1)
> > +             flags = CLK_SET_RATE_PARENT;
> >       clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor
> >                       (&pdev->dev, clk_name,
> >                        __clk_get_name(clk_wzrd->clk_in1),
> > @@ -566,9 +569,6 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> >               goto err_disable_clk;
> >       }
> >
> > -     outputs = of_property_count_strings(np, "clock-output-names");
> > -     if (outputs == 1)
> > -             flags = CLK_SET_RATE_PARENT;
> >       clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev));
> >       if (!clk_name) {
> >               ret = -ENOMEM;
> > @@ -591,6 +591,7 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> >       /* register div per output */
> >       for (i = outputs - 1; i >= 0 ; i--) {
> >               const char *clkout_name;
> > +             const char *clkout_name_wiz;
> >
> >               if (of_property_read_string_index(np, "clock-output-names", i,
> >                                                 &clkout_name)) {
> > @@ -599,9 +600,11 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> >                       ret = -EINVAL;
> >                       goto err_rm_int_clks;
> >               }
> > +             clkout_name_wiz = kasprintf(GFP_KERNEL, "%s_%s",
> > +                                         dev_name(&pdev->dev), clkout_name);
>
> If this kasprintf() crashes then clk_wzrd_register_divf() will fail.
> But that was a headache to review.  Just add a check for NULL.  We need
> a kfree() as well.
>
> One alternative would be to just declare a buffer on the stack and use
> snprintf().  We don't need to keep the name around after the call to
> clk_wzrd_register_divf().

Will fix in next version.

>
> regards,
> dan carpenter
>
Dan Carpenter Nov. 29, 2019, 7:02 p.m. UTC | #3
On Fri, Nov 29, 2019 at 05:37:57PM +0530, Shubhrajyoti Datta wrote:
> On Thu, Nov 28, 2019 at 1:15 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Thu, Nov 28, 2019 at 12:06:15PM +0530, shubhrajyoti.datta@gmail.com wrote:
> > > From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> > >
> > > Incase there are more than one instance of the clocking wizard.
> > > And if the output name given is the same then the probe fails.
> > > Fix the same by appending the device name to the output name to
> > > make it unique.
> > >
> > > Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> > > ---
> > >  drivers/clk/clk-xlnx-clock-wizard.c | 13 ++++++++-----
> > >  1 file changed, 8 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/clk/clk-xlnx-clock-wizard.c b/drivers/clk/clk-xlnx-clock-wizard.c
> > > index 75ea745..9993543 100644
> > > --- a/drivers/clk/clk-xlnx-clock-wizard.c
> > > +++ b/drivers/clk/clk-xlnx-clock-wizard.c
> > > @@ -555,6 +555,9 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> > >               ret = -ENOMEM;
> > >               goto err_disable_clk;
> > >       }
> > > +     outputs = of_property_count_strings(np, "clock-output-names");
> > > +     if (outputs == 1)
> > > +             flags = CLK_SET_RATE_PARENT;
> > >       clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor
> > >                       (&pdev->dev, clk_name,
> > >                        __clk_get_name(clk_wzrd->clk_in1),
> > > @@ -566,9 +569,6 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> > >               goto err_disable_clk;
> > >       }
> > >
> > > -     outputs = of_property_count_strings(np, "clock-output-names");
> > > -     if (outputs == 1)
> > > -             flags = CLK_SET_RATE_PARENT;
> > >       clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev));
> > >       if (!clk_name) {
> > >               ret = -ENOMEM;
> > > @@ -591,6 +591,7 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> > >       /* register div per output */
> > >       for (i = outputs - 1; i >= 0 ; i--) {
> > >               const char *clkout_name;
> > > +             const char *clkout_name_wiz;
> > >
> > >               if (of_property_read_string_index(np, "clock-output-names", i,
> > >                                                 &clkout_name)) {
> > > @@ -599,9 +600,11 @@ static int clk_wzrd_probe(struct platform_device *pdev)
> > >                       ret = -EINVAL;
> > >                       goto err_rm_int_clks;
> > >               }
> > > +             clkout_name_wiz = kasprintf(GFP_KERNEL, "%s_%s",
> > > +                                         dev_name(&pdev->dev), clkout_name);
> >
> > If this kasprintf() crashes then clk_wzrd_register_divf() will fail.

I meant if kasprintf() returns NULL not crashes...  :/

> > But that was a headache to review.  Just add a check for NULL.  We need
> > a kfree() as well.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/clk/clk-xlnx-clock-wizard.c b/drivers/clk/clk-xlnx-clock-wizard.c
index 75ea745..9993543 100644
--- a/drivers/clk/clk-xlnx-clock-wizard.c
+++ b/drivers/clk/clk-xlnx-clock-wizard.c
@@ -555,6 +555,9 @@  static int clk_wzrd_probe(struct platform_device *pdev)
 		ret = -ENOMEM;
 		goto err_disable_clk;
 	}
+	outputs = of_property_count_strings(np, "clock-output-names");
+	if (outputs == 1)
+		flags = CLK_SET_RATE_PARENT;
 	clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor
 			(&pdev->dev, clk_name,
 			 __clk_get_name(clk_wzrd->clk_in1),
@@ -566,9 +569,6 @@  static int clk_wzrd_probe(struct platform_device *pdev)
 		goto err_disable_clk;
 	}
 
-	outputs = of_property_count_strings(np, "clock-output-names");
-	if (outputs == 1)
-		flags = CLK_SET_RATE_PARENT;
 	clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev));
 	if (!clk_name) {
 		ret = -ENOMEM;
@@ -591,6 +591,7 @@  static int clk_wzrd_probe(struct platform_device *pdev)
 	/* register div per output */
 	for (i = outputs - 1; i >= 0 ; i--) {
 		const char *clkout_name;
+		const char *clkout_name_wiz;
 
 		if (of_property_read_string_index(np, "clock-output-names", i,
 						  &clkout_name)) {
@@ -599,9 +600,11 @@  static int clk_wzrd_probe(struct platform_device *pdev)
 			ret = -EINVAL;
 			goto err_rm_int_clks;
 		}
+		clkout_name_wiz = kasprintf(GFP_KERNEL, "%s_%s",
+					    dev_name(&pdev->dev), clkout_name);
 		if (!i)
 			clk_wzrd->clkout[i] = clk_wzrd_register_divf
-				(&pdev->dev, clkout_name,
+				(&pdev->dev, clkout_name_wiz,
 				clk_name, flags,
 				clk_wzrd->base, (WZRD_CLK_CFG_REG(2) + i * 12),
 				WZRD_CLKOUT_DIVIDE_SHIFT,
@@ -610,7 +613,7 @@  static int clk_wzrd_probe(struct platform_device *pdev)
 				NULL, &clkwzrd_lock);
 		else
 			clk_wzrd->clkout[i] = clk_wzrd_register_divider
-				(&pdev->dev, clkout_name,
+				(&pdev->dev, clkout_name_wiz,
 				clk_name, 0,
 				clk_wzrd->base, (WZRD_CLK_CFG_REG(2) + i * 12),
 				WZRD_CLKOUT_DIVIDE_SHIFT,