Skip to contentSkip to conversation

ASoC: sti: regmap_field usage improvements

PATCH In review Sander Vanheule 2 participants 4 messages Feb 20 – Mar 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: sti: regmap_field usage improvements

uni_player_parse_dt_audio_glue() allocates two regmap_field objects on the device's regmap. However, error codes from these allocations are not propagated correctly and the resources will leak on device removal.

These issues were found while looking for users of regmap_field_alloc(), to assess the impact of adding a cleanup helper for regmap_field. It appears this driver is the only (remaining) in-tree user of this allocator. Since the resources are long-lived, it may as well switch to devm_regmap_field_alloc().

As I don't have access to this hardware, these patches were only compile tested on a UM build.

Sander Vanheule (2):
ASoC: sti: Return errors from regmap_field_alloc()
ASoC: sti: use managed regmap_field allocations

 sound/soc/sti/uniperif_player.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 ASoC: sti: Return errors from regmap_field_alloc()

When regmap_field_alloc() fails, it can return an error. Specifically, it will return PTR_ERR(-ENOMEM) when the allocation returns a NULL pointer. The code then uses these allocations with a simple NULL check:

    if (player->clk_sel) {
        // May dereference invalid pointer (-ENOMEM)
        err = regmap_field_write(player->clk_sel, ...);
    }

Ensure initialization fails by forwarding the errors from regmap_field_alloc(), thus avoiding the use of the invalid pointers.

Fixes 76c2145ded6b ("ASoC: sti: Add CPU DAI driver for playback")
---
 sound/soc/sti/uniperif_player.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/soc/sti/uniperif_player.c +5 -0
index 6d1ce030963c..f1b7e76f97b5 100644
@@ -1029,7 +1029,12 @@ static int uni_player_parse_dt_audio_glue(struct platform_device *pdev,
 	}
 
 	player->clk_sel = regmap_field_alloc(regmap, regfield[0]);
+	if (IS_ERR(player->clk_sel))
+		return PTR_ERR(player->clk_sel);
+
 	player->valid_sel = regmap_field_alloc(regmap, regfield[1]);
+	if (IS_ERR(player->valid_sel))
+		return PTR_ERR(player->valid_sel);
 
 	return 0;
 }
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 ASoC: sti: use managed regmap_field allocations

In reply to Sander Vanheule

The regmap_field objects allocated at player init are never freed and may leak resources if the driver is removed.

Switch to devm_regmap_field_alloc() to automatically limit the lifetime of the allocations the lifetime of the device.

Fixes 76c2145ded6b ("ASoC: sti: Add CPU DAI driver for playback")
---
 sound/soc/sti/uniperif_player.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/sti/uniperif_player.c +2 -2
index f1b7e76f97b5..45d35b887e4e 100644
@@ -1028,11 +1028,11 @@ static int uni_player_parse_dt_audio_glue(struct platform_device *pdev,
 		return PTR_ERR(regmap);
 	}
 
-	player->clk_sel = regmap_field_alloc(regmap, regfield[0]);
+	player->clk_sel = devm_regmap_field_alloc(&pdev->dev, regmap, regfield[0]);
 	if (IS_ERR(player->clk_sel))
 		return PTR_ERR(player->clk_sel);
 
-	player->valid_sel = regmap_field_alloc(regmap, regfield[1]);
+	player->valid_sel = devm_regmap_field_alloc(&pdev->dev, regmap, regfield[1]);
 	if (IS_ERR(player->valid_sel))
 		return PTR_ERR(player->valid_sel);
 
Signature · 1 line
2.53.0
maintainer
#3 lore raw
In reply to Sander Vanheule
Quoted 11 lines · Sander Vanheule

uni_player_parse_dt_audio_glue() allocates two regmap_field objects on the device's regmap. However, error codes from these allocations are not propagated correctly and the resources will leak on device removal.

These issues were found while looking for users of regmap_field_alloc(), to assess the impact of adding a cleanup helper for regmap_field. It appears this driver is the only (remaining) in-tree user of this allocator. Since the resources are long-lived, it may as well switch to devm_regmap_field_alloc().

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: sti: Return errors from regmap_field_alloc()

      commit: 272aabef50bc3fe58edd26de000f4cdd41bdbe60
[2/2] ASoC: sti: use managed regmap_field allocations
      commit: 1696fad8b259a2d46e51cd6e17e4bcdbe02279fa

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark