From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: "Gerd Hoffmann" <kraxel@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
qemu-devel@nongnu.org
Cc: devel@daynix.com,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Phil Dennis-Jordan" <phil@philjordan.eu>,
"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>
Subject: Re: [PATCH v8 5/6] audio: Add functions to initialize buffers
Date: Wed, 04 Mar 2026 12:17:14 +0100 [thread overview]
Message-ID: <3742853.R56niFO833@weasel> (raw)
In-Reply-To: <8d6f53c2-417a-4e4e-a75e-e0038cfd7f9c@rsg.ci.i.u-tokyo.ac.jp>
On Wednesday, 4 March 2026 11:47:01 CET Akihiko Odaki wrote:
> On 2026/03/04 17:36, Christian Schoenebeck wrote:
> > On Wednesday, 4 March 2026 07:16:58 CET Akihiko Odaki wrote:
> >> These functions can be used to re-initialize buffers when hardware
> >> parameters change due to device hotplug, for example.
> >>
> >> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> >> Reviewed-by: Phil Dennis-Jordan <phil@philjordan.eu>
> >> Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> >> ---
[...]
> >>
> >> +void audio_generic_initialize_buffer_in(HWVoiceIn *hw)
> >> +{
> >> + g_free(hw->buf_emul);
> >> + hw->size_emul = hw->samples * hw->info.bytes_per_frame;
> >> + hw->buf_emul = g_malloc(hw->size_emul);
> >> + hw->pos_emul = hw->pending_emul = 0;
> >> +}
> >> +
> >>
> >> void audio_generic_run_buffer_in(HWVoiceIn *hw)
> >> {
> >>
> >> AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_GET_CLASS(hw->s);
> >>
> >> if (unlikely(!hw->buf_emul)) {
> >>
> >> - hw->size_emul = hw->samples * hw->info.bytes_per_frame;
> >> - hw->buf_emul = g_malloc(hw->size_emul);
> >> - hw->pos_emul = hw->pending_emul = 0;
> >> + audio_generic_initialize_buffer_in(hw);
> >>
> >> }
> >
> > It would be cleaner having split this patch over 2 patches. One for pure
> > refactoring (no behaviour change), and one that adds g_free(hw->buf_emul);
>
> g_free() was added because the extracted function can be called with
> hw->buf_emul set. Extracting this into a function without adding
> g_free() makes the function dangerous with non-NULL hw->buf_emul. Adding
> g_free() without extracting it into a function doesn't make sense as it
> checks !hw->buf_emul immediate above.
You are adding the function. So at this point, nobody could have called the
function by accident except you. And as you would have added g_malloc()
immediately with the next patch, there would be no danger.
In general it does make sense splitting pure refactoring from behaviour
changes. And by adding g_free() you are changing existing behaviour. That's
not bike shedding, it's for the sake of being able to skip all those white
noise changes when investigating if something breaks.
And the potential danger argument contradicts itself, because if the function
was called with an uninitialized structure then g_free() would crash. Without
g_free() it was just a potential memory leak OTOH. Choose your poison.
/Christian
next prev parent reply other threads:[~2026-03-04 11:18 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 6:16 [PATCH v8 0/6] coreaudio fixes Akihiko Odaki
2026-03-04 6:16 ` [PATCH v8 1/6] coreaudio: Remove unnecessary explicit casts Akihiko Odaki
2026-03-04 8:07 ` Marc-André Lureau
2026-03-04 6:16 ` [PATCH v8 2/6] coreaudio: Remove extra whitespaces Akihiko Odaki
2026-03-04 8:06 ` Marc-André Lureau
2026-03-04 6:16 ` [PATCH v8 3/6] coreaudio: Improve naming Akihiko Odaki
2026-03-04 8:07 ` Marc-André Lureau
2026-03-04 9:25 ` Christian Schoenebeck
2026-03-04 10:42 ` Akihiko Odaki
2026-03-04 10:52 ` Christian Schoenebeck
2026-03-04 12:00 ` BALATON Zoltan
2026-03-04 6:16 ` [PATCH v8 4/6] coreaudio: Commit the result of init in the end Akihiko Odaki
2026-03-04 11:56 ` Christian Schoenebeck
2026-03-07 4:10 ` Akihiko Odaki
2026-03-04 6:16 ` [PATCH v8 5/6] audio: Add functions to initialize buffers Akihiko Odaki
2026-03-04 8:11 ` Marc-André Lureau
2026-03-04 8:36 ` Christian Schoenebeck
2026-03-04 10:47 ` Akihiko Odaki
2026-03-04 11:17 ` Christian Schoenebeck [this message]
2026-03-07 4:17 ` Akihiko Odaki
2026-03-04 6:16 ` [PATCH v8 6/6] coreaudio: Initialize the buffer for device change Akihiko Odaki
2026-03-04 8:11 ` Marc-André Lureau
2026-03-04 11:39 ` Christian Schoenebeck
2026-03-07 5:29 ` Akihiko Odaki
2026-03-04 8:42 ` [PATCH v8 0/6] coreaudio fixes Christian Schoenebeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3742853.R56niFO833@weasel \
--to=qemu_oss@crudebyte.com \
--cc=balaton@eik.bme.hu \
--cc=devel@daynix.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=phil@philjordan.eu \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.