diff options
author | Hsin-yu Chao <hychao@google.com> | 2024-06-11 03:49:03 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-06-11 08:02:51 +0000 |
commit | 79bead91426c37aecb29405b0deb1b0673ebe2e0 (patch) | |
tree | ec2a6996bd5e68f42db6071d74a226dcb235213b | |
parent | 2db92ac048298a52f5bf7f532e561cc7d743e034 (diff) | |
download | adhd-upstream-main.tar.gz |
CRAS: iodev - free dsp at set format errorupstream-main
Opening an iodev has several stages and cras_iodev_set_format is one
that determines the final format and dsp_context that will be used
on this runing iodev.
This change fixes a bug that at set format error, the exit path cleans
up the format but forgot about dsp_context, in which case leaving the
iodev at "Closed" state but with a valid dsp_context to mislead some
other checks and cause crashes.
BUG=b:346439159
TEST=unittest
Change-Id: I20a0856f75ff36beb388a86ee55e2ed8dc0742c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5620133
Reviewed-by: Li-Yu Yu <aaronyu@google.com>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Auto-Submit: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
-rw-r--r-- | cras/src/server/cras_iodev.c | 1 | ||||
-rw-r--r-- | cras/src/tests/iodev_unittest.cc | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/cras/src/server/cras_iodev.c b/cras/src/server/cras_iodev.c index 68b0fd99..bf78c856 100644 --- a/cras/src/server/cras_iodev.c +++ b/cras/src/server/cras_iodev.c @@ -558,6 +558,7 @@ int cras_iodev_set_format(struct cras_iodev* iodev, return 0; error: + cras_iodev_free_dsp(iodev); free(iodev->format); iodev->format = NULL; return rc; diff --git a/cras/src/tests/iodev_unittest.cc b/cras/src/tests/iodev_unittest.cc index 1a43defb..c7874849 100644 --- a/cras/src/tests/iodev_unittest.cc +++ b/cras/src/tests/iodev_unittest.cc @@ -329,6 +329,23 @@ class IoDevSetFormatTestSuite : public testing::Test { snd_pcm_format_t pcm_formats_[3]; }; +TEST_F(IoDevSetFormatTestSuite, SetFormatFailure) { + struct cras_audio_format fmt; + int rc; + + iodev_.direction = CRAS_STREAM_OUTPUT; + ResetStubData(); + + // Simulate the case that HW reports no rate supported. + iodev_.supported_rates = 0; + cras_dsp_context_new_return = reinterpret_cast<cras_dsp_context*>(0xf0f); + + rc = cras_iodev_set_format(&iodev_, &fmt); + EXPECT_NE(0, rc); + EXPECT_EQ((void*)NULL, iodev_.format); + EXPECT_EQ((void*)NULL, iodev_.dsp_context); +} + TEST_F(IoDevSetFormatTestSuite, SupportedFormatSecondary) { struct cras_audio_format fmt; int rc; |