diff mbox series

[1/5] nvmem: meson-efuse: Move data to a container struct

Message ID 20190729183941.18164-2-ccaione@baylibre.com (mailing list archive)
State Superseded
Headers show
Series Rework secure-monitor driver | expand

Commit Message

Carlo Caione July 29, 2019, 6:39 p.m. UTC
No functional changes, just a cleanup commit to tidy up a bit. Move the
nvmem_* and clk structures in a container struct.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/nvmem/meson-efuse.c | 47 ++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 21 deletions(-)

Comments

Jerome Brunet July 30, 2019, 9:04 a.m. UTC | #1
On Mon 29 Jul 2019 at 19:39, Carlo Caione <ccaione@baylibre.com> wrote:

> No functional changes, just a cleanup commit to tidy up a bit. Move the
> nvmem_* and clk structures in a container struct.
>
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> ---
>  drivers/nvmem/meson-efuse.c | 47 ++++++++++++++++++++-----------------
>  1 file changed, 26 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
> index 39bd76306033..9924b98db772 100644
> --- a/drivers/nvmem/meson-efuse.c
> +++ b/drivers/nvmem/meson-efuse.c
> @@ -14,6 +14,12 @@
>  
>  #include <linux/firmware/meson/meson_sm.h>
>  
> +struct meson_efuse {
> +	struct nvmem_device *nvmem;
> +	struct nvmem_config config;
> +	struct clk *clk;

since this driver uses devm_add_action_or_reset, I don't think you need
to keep the clk pointer around, unless you plan to do something with it
later on ?

It is kind of the same the other structure members, do we need to keep
them around ? We could just let devm deal with it ?

If you have a plan, could you share it ?

> +};
> +
>  static int meson_efuse_read(void *context, unsigned int offset,
>  			    void *val, size_t bytes)
>  {
> @@ -37,21 +43,23 @@ MODULE_DEVICE_TABLE(of, meson_efuse_match);
>  static int meson_efuse_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	struct nvmem_device *nvmem;
> -	struct nvmem_config *econfig;
> -	struct clk *clk;
> +	struct meson_efuse *efuse;
>  	unsigned int size;
>  	int ret;
>  
> -	clk = devm_clk_get(dev, NULL);
> -	if (IS_ERR(clk)) {
> -		ret = PTR_ERR(clk);
> +	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
> +	if (!efuse)
> +		return -ENOMEM;
> +
> +	efuse->clk = devm_clk_get(dev, NULL);
> +	if (IS_ERR(efuse->clk)) {
> +		ret = PTR_ERR(efuse->clk);
>  		if (ret != -EPROBE_DEFER)
>  			dev_err(dev, "failed to get efuse gate");
>  		return ret;
>  	}
>  
> -	ret = clk_prepare_enable(clk);
> +	ret = clk_prepare_enable(efuse->clk);
>  	if (ret) {
>  		dev_err(dev, "failed to enable gate");
>  		return ret;
> @@ -59,7 +67,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
>  
>  	ret = devm_add_action_or_reset(dev,
>  				       (void(*)(void *))clk_disable_unprepare,
> -				       clk);
> +				       efuse->clk);
>  	if (ret) {
>  		dev_err(dev, "failed to add disable callback");
>  		return ret;
> @@ -70,21 +78,18 @@ static int meson_efuse_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
> -	if (!econfig)
> -		return -ENOMEM;
> -
> -	econfig->dev = dev;
> -	econfig->name = dev_name(dev);
> -	econfig->stride = 1;
> -	econfig->word_size = 1;
> -	econfig->reg_read = meson_efuse_read;
> -	econfig->reg_write = meson_efuse_write;
> -	econfig->size = size;
> +	efuse->config.dev = dev;
> +	efuse->config.name = dev_name(dev);
> +	efuse->config.stride = 1;
> +	efuse->config.word_size = 1;
> +	efuse->config.reg_read = meson_efuse_read;
> +	efuse->config.reg_write = meson_efuse_write;
> +	efuse->config.size = size;
> +	efuse->config.priv = efuse;
>  
> -	nvmem = devm_nvmem_register(&pdev->dev, econfig);
> +	efuse->nvmem = devm_nvmem_register(&pdev->dev, &efuse->config);
>  
> -	return PTR_ERR_OR_ZERO(nvmem);
> +	return PTR_ERR_OR_ZERO(efuse->nvmem);
>  }
>  
>  static struct platform_driver meson_efuse_driver = {
> -- 
> 2.20.1
Carlo Caione July 30, 2019, 9:29 a.m. UTC | #2
On 30/07/2019 10:04, Jerome Brunet wrote:
> On Mon 29 Jul 2019 at 19:39, Carlo Caione <ccaione@baylibre.com> wrote:

/cut
>> +struct meson_efuse {
>> +	struct nvmem_device *nvmem;
>> +	struct nvmem_config config;
>> +	struct clk *clk;
> 
> since this driver uses devm_add_action_or_reset, I don't think you need
> to keep the clk pointer around, unless you plan to do something with it
> later on ?

Good point about the clk pointer.

> It is kind of the same the other structure members, do we need to keep
> them around ? We could just let devm deal with it ?
> 
> If you have a plan, could you share it ?

No plan. In the PATCH 4/5 I was going to add struct meson_sm_firmware to 
the bundle and to me it's a bit more elegant to have all the auxiliary 
structs together in a single container.

For the sake of keeping the diff size low I'm going to rework this in V2.

--
Carlo Caione
diff mbox series

Patch

diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index 39bd76306033..9924b98db772 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -14,6 +14,12 @@ 
 
 #include <linux/firmware/meson/meson_sm.h>
 
+struct meson_efuse {
+	struct nvmem_device *nvmem;
+	struct nvmem_config config;
+	struct clk *clk;
+};
+
 static int meson_efuse_read(void *context, unsigned int offset,
 			    void *val, size_t bytes)
 {
@@ -37,21 +43,23 @@  MODULE_DEVICE_TABLE(of, meson_efuse_match);
 static int meson_efuse_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct nvmem_device *nvmem;
-	struct nvmem_config *econfig;
-	struct clk *clk;
+	struct meson_efuse *efuse;
 	unsigned int size;
 	int ret;
 
-	clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(clk)) {
-		ret = PTR_ERR(clk);
+	efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
+	if (!efuse)
+		return -ENOMEM;
+
+	efuse->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(efuse->clk)) {
+		ret = PTR_ERR(efuse->clk);
 		if (ret != -EPROBE_DEFER)
 			dev_err(dev, "failed to get efuse gate");
 		return ret;
 	}
 
-	ret = clk_prepare_enable(clk);
+	ret = clk_prepare_enable(efuse->clk);
 	if (ret) {
 		dev_err(dev, "failed to enable gate");
 		return ret;
@@ -59,7 +67,7 @@  static int meson_efuse_probe(struct platform_device *pdev)
 
 	ret = devm_add_action_or_reset(dev,
 				       (void(*)(void *))clk_disable_unprepare,
-				       clk);
+				       efuse->clk);
 	if (ret) {
 		dev_err(dev, "failed to add disable callback");
 		return ret;
@@ -70,21 +78,18 @@  static int meson_efuse_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
-	if (!econfig)
-		return -ENOMEM;
-
-	econfig->dev = dev;
-	econfig->name = dev_name(dev);
-	econfig->stride = 1;
-	econfig->word_size = 1;
-	econfig->reg_read = meson_efuse_read;
-	econfig->reg_write = meson_efuse_write;
-	econfig->size = size;
+	efuse->config.dev = dev;
+	efuse->config.name = dev_name(dev);
+	efuse->config.stride = 1;
+	efuse->config.word_size = 1;
+	efuse->config.reg_read = meson_efuse_read;
+	efuse->config.reg_write = meson_efuse_write;
+	efuse->config.size = size;
+	efuse->config.priv = efuse;
 
-	nvmem = devm_nvmem_register(&pdev->dev, econfig);
+	efuse->nvmem = devm_nvmem_register(&pdev->dev, &efuse->config);
 
-	return PTR_ERR_OR_ZERO(nvmem);
+	return PTR_ERR_OR_ZERO(efuse->nvmem);
 }
 
 static struct platform_driver meson_efuse_driver = {