diff mbox series

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

Message ID 20230818093028.7807-4-kkartik@nvidia.com
State Superseded
Headers show
Series soc/tegra: fuse: Add ACPI support | expand

Commit Message

Kartik Rajput Aug. 18, 2023, 9:30 a.m. UTC
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>
---
 drivers/soc/tegra/fuse/fuse-tegra.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

Comments

Andy Shevchenko Aug. 18, 2023, 2:06 p.m. UTC | #1
On Fri, Aug 18, 2023 at 03:00:25PM +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.

...

> +	size = sizeof(*fuse->lookups) * fuse->soc->num_lookups;

At least this should use size_mul().

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

But ideally you need to add a patch that brings kmemdup_array().

Okay, it seems it's in the original code :-(
Can you add in your ToDo list to amend this?
Kartik Rajput Aug. 21, 2023, 11:36 a.m. UTC | #2
On Fri, 2023-08-18 at 17:06 +0300, Andy Shevchenko wrote:
>On Fri, Aug 18, 2023 at 03:00:25PM +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.
>
>...
>
>> +	size = sizeof(*fuse->lookups) * fuse->soc->num_lookups;
>
>At least this should use size_mul().
>
>> +	fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL);
>> +	if (!fuse->lookups)
>> +		return -ENOMEM;
>
>But ideally you need to add a patch that brings kmemdup_array().
>
>Okay, it seems it's in the original code :-(
>Can you add in your ToDo list to amend this?
>
>-- 
>With Best Regards,
>Andy Shevchenko

I will update this in the next patch.

Regards,
Kartik
diff mbox series

Patch

diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index 45784ac6393d..bbb1a5c4823b 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -148,6 +148,24 @@  static int tegra_fuse_nvmem_register(struct tegra_fuse *fuse,
 	return 0;
 }
 
+static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
+{
+	size_t size;
+
+	if (!fuse->soc->lookups)
+		return 0;
+
+	size = 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;
@@ -419,6 +437,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();
 
@@ -516,12 +535,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;