soc/tegra: fuse: Fix SMCCC and probe error paths
cover soc/tegra: fuse: Fix SMCCC and probe error paths
This series fixes three error paths in the Tegra fuse driver:
- avoid dereferencing a NULL APBMISC mapping in tegra_read_chipid();
- remove and free nvmem lookups when probe fails or resources are released;
- avoid indexing tegra_platform_name[] with an unknown platform ID.
The first two issues were introduced by the SMCCC and probe-time lookup changes. The platform bounds issue predates SMCCC, whose wider platform field increases the range of invalid values.
AI assistance disclosure:
Qoder AI coding assistant was used with the Kitta review findings and the relevant ANCK/mainline source as inputs. It contributed to the problem analysis, code changes, and changelog drafts. checkpatch.pl and make were used for local validation. The human submitter reviewed the complete series and added their own Signed-off-by tags.
Validation:
- patches apply to torvalds/linux master 8d7fe9885c62 (7.4.0-rc4);
- current mainline sources are identical to the base for both touched files;
- independent review found no High/Medium/Low code defects;
- checkpatch.pl reports 0 errors and 0 warnings for each signed patch;
- drivers/soc/tegra/fuse/ builds on aarch64 defconfig;
- a complete aarch64 defconfig Image builds successfully with SHA-256 8e35101c2745bd2d64ebad1065685c4d76b662d154d411a34d391820bd1f2c60;
- the final tree is e35c03a0ccbe95b1d49caeeb713b5019adbefec7;
- the three fixes also built previously in the ANCK devel-6.6-arm tree.
NOT_RUN:
- runtime APBMISC mapping failure injection;
- runtime probe-defer retry and lookup lifetime validation;
- Vera hardware and ECS workloads.
Jiangtian Feng (3):
soc/tegra: fuse: Fix NULL dereference when APBMISC is unavailable soc/tegra: fuse: Clean up nvmem lookups on probe failure soc/tegra: fuse: Handle unknown platform IDs safely
drivers/soc/tegra/fuse/fuse-tegra.c | 24 ++++++++++++++++++++---- drivers/soc/tegra/fuse/tegra-apbmisc.c | 3 ++- 2 files changed, 22 insertions(+), 5 deletions(-)
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
Signature · 1 line
2.47.3
PATCH 1/3 soc/tegra: fuse: Fix NULL dereference when APBMISC is unavailable
When APBMISC is unavailable, the warning in tegra_read_chipid() does not stop execution and the subsequent lazy HIDREV read can dereference a NULL apbmisc_base.
Return 0 after the warning, matching the behavior before the lazy read was introduced.
The issue was identified by Kitta automated review. Qoder AI coding assistant was used to analyze the problem and draft this fix and changelog.
--- drivers/soc/tegra/fuse/tegra-apbmisc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soc/tegra/fuse/tegra-apbmisc.c +2 -1
@@ -39,7 +39,8 @@ static u32 chipid;u32 tegra_read_chipid (void ) { -WARN (!apbmisc_base,"Tegra APB MISC not yet available\n" ); +if (WARN (!apbmisc_base,"Tegra APB MISC not yet available\n" )) +return 0 ;if (!chipid) chipid =readl_relaxed (apbmisc_base +4 );
Signature · 1 line
2.47.3
PATCH 2/3 soc/tegra: fuse: Clean up nvmem lookups on probe failure
In reply to Jiangtian FengLookup registration in the common probe path can be followed by a probe failure, leaving the entries on the global lookup list. A subsequent probe allocates a new array and overwrites fuse->lookups, leaking the old array and adding duplicate entries on every retry.
Add a devres cleanup that removes the entries and frees the array. Using devm_add_action_or_reset() also cleans up correctly if registering the cleanup action itself fails.
The issue was identified by Kitta automated review. Qoder AI coding assistant was used to analyze the problem and draft this fix and changelog.
--- drivers/soc/tegra/fuse/fuse-tegra.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/soc/tegra/fuse/fuse-tegra.c +13 -0
@@ -140,6 +140,15 @@ static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)return 0 ; } +static void tegra_fuse_del_lookups (void *data) +{ +struct tegra_fuse *fuse = data; + +nvmem_del_cell_lookups (fuse->lookups, fuse->soc->num_lookups); +kfree (fuse->lookups); + fuse->lookups =NULL ; +} +static int tegra_fuse_probe (struct platform_device *pdev) {void __iomem *base = fuse->base;
@@ -239,6 +248,10 @@ static int tegra_fuse_probe(struct platform_device *pdev)if (err)return dev_err_probe (&pdev->dev, err,"failed to add FUSE lookups\n" ); + err =devm_add_action_or_reset (&pdev->dev, tegra_fuse_del_lookups, fuse); +if (err) +return err; + fuse->rst =devm_reset_control_get_optional (&pdev->dev,"fuse" );if (IS_ERR (fuse->rst))return dev_err_probe (&pdev->dev,PTR_ERR (fuse->rst),"failed to get FUSE reset\n" );
Signature · 1 line
2.47.3
PATCH 3/3 soc/tegra: fuse: Handle unknown platform IDs safely
In reply to Jiangtian Fengtegra_sku_info.platform comes from either a 4-bit HIDREV field or an 8-bit SMCCC field, but tegra_platform_name[] has only TEGRA_PLATFORM_MAX entries. Using the value directly as an array index can therefore read past the array or select an unpopulated entry.
Resolve the platform name once and use "Unknown" when the value has no valid name. Names for all existing valid platform IDs remain unchanged.
The issue was identified by Kitta automated review. Qoder AI coding assistant was used to analyze the problem and draft this fix and changelog.
--- drivers/soc/tegra/fuse/fuse-tegra.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/soc/tegra/fuse/fuse-tegra.c +7 -4
@@ -466,20 +466,23 @@ const struct attribute_group tegra194_soc_attr_group = {struct device *tegra_soc_device_register (void ) {struct soc_device_attribute *attr; +const char *platform_name ="Unknown" ;struct soc_device *dev; attr =kzalloc_obj (*attr);if (!attr)return NULL ; +if ((unsigned int )tegra_sku_info.platform <TEGRA_PLATFORM_MAX && + tegra_platform_name[tegra_sku_info.platform]) + platform_name = tegra_platform_name[tegra_sku_info.platform]; + attr->family =kasprintf (GFP_KERNEL ,"Tegra" );if (tegra_is_silicon ()) - attr->revision =kasprintf (GFP_KERNEL ,"%s %s" , - tegra_platform_name[tegra_sku_info.platform], + attr->revision =kasprintf (GFP_KERNEL ,"%s %s" , platform_name, tegra_revision_name[tegra_sku_info.revision]);else - attr->revision =kasprintf (GFP_KERNEL ,"%s" , - tegra_platform_name[tegra_sku_info.platform]); + attr->revision =kasprintf (GFP_KERNEL ,"%s" , platform_name); attr->soc_id =kasprintf (GFP_KERNEL ,"%u" ,tegra_get_chip_id ()); attr->custom_attr_group = fuse->soc->soc_attr_group;
Signature · 1 line
2.47.3