[PATCH v3 3/6] soc/tegra: fuse: Add function to add lookups

Kartik posted 6 patches 2 years, 3 months ago
There is a newer version of this series
[PATCH v3 3/6] soc/tegra: fuse: Add function to add lookups
Posted by Kartik 2 years, 3 months ago
Add helper function tegra_fuse_add_lookups() to register Tegra fuse
nvmem lookups. So, this can be shared between tegra_fuse_init() and
ACPI probe, which is to be introduced later.

Signed-off-by: Kartik <kkartik@nvidia.com>
---
v1 -> v2:
	* Use size_mul to calculate lookups array size.
---
 drivers/soc/tegra/fuse/fuse-tegra.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index a2c28f493a75..821bb485ec45 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -113,6 +113,24 @@ static void tegra_fuse_restore(void *base)
 	fuse->clk = NULL;
 }
 
+static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
+{
+	size_t size;
+
+	if (!fuse->soc->lookups)
+		return 0;
+
+	size = size_mul(sizeof(*fuse->lookups), fuse->soc->num_lookups);
+
+	fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL);
+	if (!fuse->lookups)
+		return -ENOMEM;
+
+	nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups);
+
+	return 0;
+}
+
 static int tegra_fuse_probe(struct platform_device *pdev)
 {
 	void __iomem *base = fuse->base;
@@ -407,6 +425,7 @@ static int __init tegra_init_fuse(void)
 	const struct of_device_id *match;
 	struct device_node *np;
 	struct resource regs;
+	int err;
 
 	tegra_init_apbmisc();
 
@@ -504,12 +523,10 @@ static int __init tegra_init_fuse(void)
 	pr_debug("Tegra CPU Speedo ID %d, SoC Speedo ID %d\n",
 		 tegra_sku_info.cpu_speedo_id, tegra_sku_info.soc_speedo_id);
 
-	if (fuse->soc->lookups) {
-		size_t size = sizeof(*fuse->lookups) * fuse->soc->num_lookups;
-
-		fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL);
-		if (fuse->lookups)
-			nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups);
+	err = tegra_fuse_add_lookups(fuse);
+	if (err) {
+		pr_err("failed to add FUSE lookups\n");
+		return err;
 	}
 
 	return 0;
-- 
2.34.1
Re: [PATCH v3 3/6] soc/tegra: fuse: Add function to add lookups
Posted by Andy Shevchenko 2 years, 3 months ago
On Thu, Sep 07, 2023 at 12:40:49PM +0530, Kartik wrote:
> Add helper function tegra_fuse_add_lookups() to register Tegra fuse
> nvmem lookups. So, this can be shared between tegra_fuse_init() and
> ACPI probe, which is to be introduced later.

...

> +static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
> +{
> +	size_t size;
> +
> +	if (!fuse->soc->lookups)
> +		return 0;

> +	size = size_mul(sizeof(*fuse->lookups), fuse->soc->num_lookups);
> +
> +	fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL);
> +	if (!fuse->lookups)
> +		return -ENOMEM;

Why not introducing kmemdup_array()?

> +	nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups);
> +
> +	return 0;
> +}

...

> +	err = tegra_fuse_add_lookups(fuse);
> +	if (err) {
> +		pr_err("failed to add FUSE lookups\n");

Why pr_err() and not dev_err()?

> +		return err;
>  	}
>  
>  	return 0;

These four lines can be just shortened to

	return err;

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 3/6] soc/tegra: fuse: Add function to add lookups
Posted by Kartik 2 years, 2 months ago
On Thu, 2023-09-07 at 14:35, Andy Shevchenko wrote:
>On Thu, Sep 07, 2023 at 12:40:49PM +0530, Kartik wrote:
>> Add helper function tegra_fuse_add_lookups() to register Tegra fuse
>> nvmem lookups. So, this can be shared between tegra_fuse_init() and
>> ACPI probe, which is to be introduced later.
>
>...
>
>> +static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
>> +{
>> +	size_t size;
>> +
>> +	if (!fuse->soc->lookups)
>> +		return 0;
>
>> +	size = size_mul(sizeof(*fuse->lookups), fuse->soc->num_lookups);
>> +
>> +	fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL);
>> +	if (!fuse->lookups)
>> +		return -ENOMEM;
>
>Why not introducing kmemdup_array()?

Introduced this in v4.

>
>> +	nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups);
>> +
>> +	return 0;
>> +}
>
>...
>
>> +	err = tegra_fuse_add_lookups(fuse);
>> +	if (err) {
>> +		pr_err("failed to add FUSE lookups\n");
>
>Why pr_err() and not dev_err()?

This is called before tegra_fuse_probe in device-tree boot hence the
reason behing using pr_err instead of dev_err.

>
>> +		return err;
>>  	}
>>  
>>  	return 0;
>
>These four lines can be just shortened to
>
>	return err;
>

Updated this in v4.

>-- 
>With Best Regards,
>Andy Shevchenko

Regards,
Kartik