ASoC: sti: regmap_field usage improvements
Subsystems (3)
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
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.
--- sound/soc/sti/uniperif_player.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/soc/sti/uniperif_player.c +5 -0
@@ -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
PATCH 2/2 ASoC: sti: use managed regmap_field allocations
In reply to Sander VanheuleThe 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.
--- sound/soc/sti/uniperif_player.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/sti/uniperif_player.c +2 -2
@@ -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
Mark Brown
maintainerQuoted 11 lines · Sander Vanheule
uni_player_parse_dt_audio_glue()allocates tworegmap_fieldobjects 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 forregmap_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 todevm_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: 1696fad8b259a2d46e51cd6e17e4bcdbe02279faAll 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