clk: x86: lpss-atom: A couple of cleanups
cover clk: x86: lpss-atom: A couple of cleanups
A couple of cleanups for the clk-lpss-atom driver. No functional changes intended.
Andy Shevchenko (2):
clk: x86: lpss-atom: Use predefined constants from units.h
clk: x86: lpss-atom: Use temporary variable for struct device
drivers/clk/x86/clk-lpss-atom.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 1/2 clk: x86: lpss-atom: Use predefined constants from units.h
Use predefined constants from units.h to make code robust against typos like how many zeros to put.
--- drivers/clk/x86/clk-lpss-atom.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clk/x86/clk-lpss-atom.c +6 -2
@@ -12,20 +12,24 @@#include <linux/module.h> #include <linux/platform_data/x86/clk-lpss.h> #include <linux/platform_device.h> +#include <linux/units.h> static int lpss_atom_clk_probe (struct platform_device *pdev) {struct lpss_clk_data *drvdata;struct clk *clk; +u32 rate; drvdata =devm_kzalloc (&pdev->dev,sizeof (*drvdata),GFP_KERNEL );if (!drvdata)return -ENOMEM ; +/* Default frequency is 100MHz */ + rate =100 *HZ_PER_MHZ ; +/* LPSS free running clock */ drvdata->name ="lpss_clk" ; - clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL , -0 ,100000000 ); + clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL ,0 , rate);if (IS_ERR (clk))return PTR_ERR (clk);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Stephen Boyd
maintainerRe: [PATCH v1 1/2] clk: x86: lpss-atom: Use predefined constants from units.h
Quoting Andy Shevchenko (2024-08-22 09:14:07)
Quoted 5 lines
drivers/clk/x86/clk-lpss-atom.c +0
-0
drivers/clk/x86/clk-lpss-atom.c line 21
Quoted 10 lines
drivers/clk/x86/clk-lpss-atom.c +2
-0@@ -12,20 +12,24 @@#include <linux/module.h> #include <linux/platform_data/x86/clk-lpss.h> #include <linux/platform_device.h> +#include <linux/units.h> static int lpss_atom_clk_probe (struct platform_device *pdev) {struct lpss_clk_data *drvdata;struct clk *clk; +u32 rate;
Do we need a local variable?
drivers/clk/x86/clk-lpss-atom.c line 32
Quoted 13 lines
drivers/clk/x86/clk-lpss-atom.c +4
-2drvdata =devm_kzalloc (&pdev->dev,sizeof (*drvdata),GFP_KERNEL );if (!drvdata)return -ENOMEM ; +/* Default frequency is 100MHz */ + rate =100 *HZ_PER_MHZ ; +/* LPSS free running clock */ drvdata->name ="lpss_clk" ; - clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL , -0 ,100000000 ); + clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL ,0 , rate);
This should be a one line patch.
Quoted 3 lines
drivers/clk/x86/clk-lpss-atom.c +0
-0if (IS_ERR (clk))return PTR_ERR (clk);
Re: [PATCH v1 1/2] clk: x86: lpss-atom: Use predefined constants from units.h
Quoted 1 line · Stephen Boyd
Quoting Andy Shevchenko (2024-08-22 09:14:07)
...
Quoted 7 lines
Quoted 5 lines
static int
lpss_atom_clk_probe(struct platform_device *pdev){ struct lpss_clk_data *drvdata; struct clk *clk;+ u32 rate;
Do we need a local variable?
Hmm... The idea was to allow retrieving this via device properties, that's why a separate variable, but that patch wasn't included here.
Nevertheless, despite above the separate variable makes code a bit better to read as we can see what is this value about.
Quoted 13 lines
drivers/clk/x86/clk-lpss-atom.c line 32
Quoted 12 lines
drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); if (!drvdata) return -ENOMEM;drivers/clk/x86/clk-lpss-atom.c +4
-2+/* Default frequency is 100MHz */ + rate =100 *HZ_PER_MHZ ; +/* LPSS free running clock */ drvdata->name ="lpss_clk" ; - clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL , -0 ,100000000 ); + clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL ,0 , rate);
Quoted 1 line
This should be a one line patch.
I don't get this. You mean the entire thingy?
It's possible, but as I mentioned above there is a rationale for making it with a temporary variable.
Quoted 2 lines
Quoted 2 lines
if (IS_ERR(clk)) return PTR_ERR(clk);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Stephen Boyd
maintainerRe: [PATCH v1 1/2] clk: x86: lpss-atom: Use predefined constants from units.h
Quoting Andy Shevchenko (2024-08-28 06:11:55)
Quoted 32 lines · Stephen Boyd
Quoted 1 line
Quoting Andy Shevchenko (2024-08-22 09:14:07)
...
Quoted 7 lines
Quoted 5 lines
static int
lpss_atom_clk_probe(struct platform_device *pdev){ struct lpss_clk_data *drvdata; struct clk *clk;+ u32 rate;
Do we need a local variable?
Hmm... The idea was to allow retrieving this via device properties, that's why a separate variable, but that patch wasn't included here.
Nevertheless, despite above the separate variable makes code a bit better to read as we can see what is this value about.
Quoted 13 lines
Quoted 12 lines
drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); if (!drvdata) return -ENOMEM;drivers/clk/x86/clk-lpss-atom.c +4
-2+/* Default frequency is 100MHz */ + rate =100 *HZ_PER_MHZ ; +/* LPSS free running clock */ drvdata->name ="lpss_clk" ; - clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL , -0 ,100000000 ); + clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL ,0 , rate);
Quoted 3 lines
Quoted 1 line
This should be a one line patch.
I don't get this. You mean the entire thingy?
Yes.
Quoted 3 lines
It's possible, but as I mentioned above there is a rationale for making it with a temporary variable.
The rationale looks like future code will want a local variable. When that happens the local variable would make sense.
PATCH 2/2 clk: x86: lpss-atom: Use temporary variable for struct device
In reply to Andy ShevchenkoUse temporary variable for struct device to make code neater.
--- drivers/clk/x86/clk-lpss-atom.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/x86/clk-lpss-atom.c +3 -2
@@ -16,11 +16,12 @@static int lpss_atom_clk_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev;struct lpss_clk_data *drvdata;struct clk *clk;u32 rate; - drvdata =devm_kzalloc (&pdev->dev,sizeof (*drvdata),GFP_KERNEL ); + drvdata =devm_kzalloc (dev,sizeof (*drvdata),GFP_KERNEL );if (!drvdata)return -ENOMEM ;
@@ -29,7 +30,7 @@ static int lpss_atom_clk_probe(struct platform_device *pdev)/* LPSS free running clock */ drvdata->name ="lpss_clk" ; - clk =clk_register_fixed_rate (&pdev->dev, drvdata->name,NULL ,0 , rate); + clk =clk_register_fixed_rate (dev, drvdata->name,NULL ,0 , rate);if (IS_ERR (clk))return PTR_ERR (clk);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac