linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function
@ 2021-09-10  9:26 Trevor Wu
  2021-09-10 10:23 ` Mark Brown
  2021-09-10 16:08 ` Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Trevor Wu @ 2021-09-10  9:26 UTC (permalink / raw)
  To: broonie, tiwai, matthias.bgg
  Cc: trevor.wu, alsa-devel, linux-mediatek, linux-arm-kernel,
	linux-kernel, dan.carpenter

When memory allocation for afe->reg_back_up fails, reg_back_up can't
be used.
Keep the suspend/resume flow but skip register backup when
afe->reg_back_up is NULL, in case illegal memory access happens.

Fixes: 283b612429a2 ("ASoC: mediatek: implement mediatek common structure")
Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Change since v1:
  add Reported-by tag
---
 sound/soc/mediatek/common/mtk-afe-fe-dai.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
index baaa5881b1d4..e95c7c018e7d 100644
--- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -334,9 +334,11 @@ int mtk_afe_suspend(struct snd_soc_component *component)
 			devm_kcalloc(dev, afe->reg_back_up_list_num,
 				     sizeof(unsigned int), GFP_KERNEL);
 
-	for (i = 0; i < afe->reg_back_up_list_num; i++)
-		regmap_read(regmap, afe->reg_back_up_list[i],
-			    &afe->reg_back_up[i]);
+	if (afe->reg_back_up) {
+		for (i = 0; i < afe->reg_back_up_list_num; i++)
+			regmap_read(regmap, afe->reg_back_up_list[i],
+				    &afe->reg_back_up[i]);
+	}
 
 	afe->suspended = true;
 	afe->runtime_suspend(dev);
@@ -356,12 +358,13 @@ int mtk_afe_resume(struct snd_soc_component *component)
 
 	afe->runtime_resume(dev);
 
-	if (!afe->reg_back_up)
+	if (!afe->reg_back_up) {
 		dev_dbg(dev, "%s no reg_backup\n", __func__);
-
-	for (i = 0; i < afe->reg_back_up_list_num; i++)
-		mtk_regmap_write(regmap, afe->reg_back_up_list[i],
-				 afe->reg_back_up[i]);
+	} else {
+		for (i = 0; i < afe->reg_back_up_list_num; i++)
+			mtk_regmap_write(regmap, afe->reg_back_up_list[i],
+					 afe->reg_back_up[i]);
+	}
 
 	afe->suspended = false;
 	return 0;
-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function
  2021-09-10  9:26 [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function Trevor Wu
@ 2021-09-10 10:23 ` Mark Brown
  2021-09-13  5:55   ` Trevor Wu
  2021-09-10 16:08 ` Mark Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Brown @ 2021-09-10 10:23 UTC (permalink / raw)
  To: Trevor Wu
  Cc: tiwai, matthias.bgg, alsa-devel, linux-mediatek,
	linux-arm-kernel, linux-kernel, dan.carpenter


[-- Attachment #1.1: Type: text/plain, Size: 487 bytes --]

On Fri, Sep 10, 2021 at 05:26:13PM +0800, Trevor Wu wrote:

> When memory allocation for afe->reg_back_up fails, reg_back_up can't
> be used.
> Keep the suspend/resume flow but skip register backup when
> afe->reg_back_up is NULL, in case illegal memory access happens.

It seems like it'd be better to just allocate the buffer at probe time
and fail in case we can't get it, I'd be surprised if there's many
platforms using this hardware that don't also end up suspending and
resuming.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function
  2021-09-10  9:26 [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function Trevor Wu
  2021-09-10 10:23 ` Mark Brown
@ 2021-09-10 16:08 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-09-10 16:08 UTC (permalink / raw)
  To: matthias.bgg, Trevor Wu, tiwai
  Cc: Mark Brown, linux-arm-kernel, dan.carpenter, linux-kernel,
	alsa-devel, linux-mediatek

On Fri, 10 Sep 2021 17:26:13 +0800, Trevor Wu wrote:
> When memory allocation for afe->reg_back_up fails, reg_back_up can't
> be used.
> Keep the suspend/resume flow but skip register backup when
> afe->reg_back_up is NULL, in case illegal memory access happens.
> 
> 

Applied to

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

Thanks!

[1/1] ASoC: mediatek: common: handle NULL case in suspend/resume function
      commit: 1dd038522615b70f5f8945c5631e9e2fa5bd58b1

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

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function
  2021-09-10 10:23 ` Mark Brown
@ 2021-09-13  5:55   ` Trevor Wu
  2021-09-13 15:32     ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Trevor Wu @ 2021-09-13  5:55 UTC (permalink / raw)
  To: Mark Brown
  Cc: tiwai, matthias.bgg, alsa-devel, linux-mediatek,
	linux-arm-kernel, linux-kernel, dan.carpenter

On Fri, 2021-09-10 at 11:23 +0100, Mark Brown wrote:
> On Fri, Sep 10, 2021 at 05:26:13PM +0800, Trevor Wu wrote:
> 
> > When memory allocation for afe->reg_back_up fails, reg_back_up
> > can't
> > be used.
> > Keep the suspend/resume flow but skip register backup when
> > afe->reg_back_up is NULL, in case illegal memory access happens.
> 
> It seems like it'd be better to just allocate the buffer at probe
> time
> and fail in case we can't get it, I'd be surprised if there's many
> platforms using this hardware that don't also end up suspending and
> resuming.

Hi Mark,

Thanks for your suggestion.
I agree it's better to allocate the memory at probe time.
I think we can still keep the implementation in the suspend/resume
function as a fallback solution if user doesn't allocate the memory in
probe function.

In the new mediatek SOCs, regcache has been used to handle register
backup.
Do I need to add the buffer allocation on probe function to the
platform in which mtk_afe_suspend and mtk_afe_resume are used?

Thanks,
Trevor


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function
  2021-09-13  5:55   ` Trevor Wu
@ 2021-09-13 15:32     ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-09-13 15:32 UTC (permalink / raw)
  To: Trevor Wu
  Cc: tiwai, matthias.bgg, alsa-devel, linux-mediatek,
	linux-arm-kernel, linux-kernel, dan.carpenter


[-- Attachment #1.1: Type: text/plain, Size: 1002 bytes --]

On Mon, Sep 13, 2021 at 01:55:38PM +0800, Trevor Wu wrote:
> On Fri, 2021-09-10 at 11:23 +0100, Mark Brown wrote:

> > It seems like it'd be better to just allocate the buffer at probe
> > time
> > and fail in case we can't get it, I'd be surprised if there's many
> > platforms using this hardware that don't also end up suspending and
> > resuming.

> Thanks for your suggestion.
> I agree it's better to allocate the memory at probe time.
> I think we can still keep the implementation in the suspend/resume
> function as a fallback solution if user doesn't allocate the memory in
> probe function.

If you can't allocate it at probe time you should probably just fail the
probe.

> In the new mediatek SOCs, regcache has been used to handle register
> backup.
> Do I need to add the buffer allocation on probe function to the
> platform in which mtk_afe_suspend and mtk_afe_resume are used?

I think you should have separate implementations if you have both regmap
and non-regmap versions of this.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-13 15:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10  9:26 [PATCH v2] ASoC: mediatek: common: handle NULL case in suspend/resume function Trevor Wu
2021-09-10 10:23 ` Mark Brown
2021-09-13  5:55   ` Trevor Wu
2021-09-13 15:32     ` Mark Brown
2021-09-10 16:08 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).