Re: [PATCH v2] hw/audio/fmopl.c: Convert malloc, free to g_malloc0, g_new and g_free

Peter Maydell <[email protected]> Mon, 8 Jun 2026 14:42:01 +0100
Newsgroups org.nongnu.qemu-trivial,org.nongnu.qemu-devel
Message-ID <CAFEAcA8nmKBbhkxzgF2diV41pqez3=m5hnx_qUZ2+5DCLqG3ag@mail.gmail.com>
On Mon, 8 Jun 2026 at 14:33, Alex BennĂ©e <[email protected]> wrote:
> Yeah I just scanned though:
>
>   /* lock/unlock for common table */
>   static int OPL_LockTable(void)
>   {
>           num_lock++;
>           if(num_lock>1) return 0;
>           /* first time */
>           cur_chip = NULL;
>           /* allocate total level table (128kb space) */
>           if( !OPLOpenTable() )
>           {
>                   num_lock--;
>                   return -1;
>           }
>           return 0;
>   }
>
>
> which needless to say is faking a lock with num_lock++ which should
> totally be using qemu_mutex - although even that might need some
> handling to make sure its initialised properly.

It's not really a lock -- it's just a reference count of the number
of devices using the shared data tables (if you have two adlib
sound cards in the system, they share the data). The locking here
is provided by the big-qemu-lock, as usual (OPL_LockTable() is
called from OPLCreate(), which is called from adlib_realizefn(),
which will always be called with the BQL held).

thanks
-- PMM