* [PATCH v3] hw/audio/fmopl: Convert malloc/free to g_malloc/g_free
@ 2026-03-14 8:22 Aadhya-R
0 siblings, 0 replies; 2+ messages in thread
From: Aadhya-R @ 2026-03-14 8:22 UTC (permalink / raw)
To: kraxel; +Cc: qemu-devel
As per the QEMU coding style guide, replace standard C malloc()
and free() with GLib's g_malloc() and g_free().
Since g_malloc() safely aborts on out-of-memory errors, the
redundant NULL checks and their associated error-handling paths
have been removed.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1798
Signed-off-by: Aadhya-R <aadhyar.cs24@rvce.edu.in>
---
hw/audio/fmopl.c | 41 ++++++++++++-----------------------------
1 file changed, 12 insertions(+), 29 deletions(-)
diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index a63ad0f04d..79e43d5410 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -50,7 +50,6 @@ static int opl_dbg_maxchip,opl_dbg_chip;
/* attack/decay rate time rate */
#define OPL_ARRATE 141280 /* RATE 4 = 2826.24ms @ 3.6MHz */
#define OPL_DRRATE 1956000 /* RATE 4 = 39280.64ms @ 3.6MHz */
-
#define DELTAT_MIXING_LEVEL (1) /* DELTA-T ADPCM MIXING LEVEL */
#define FREQ_BITS 24 /* frequency turn */
@@ -607,26 +606,10 @@ static int OPLOpenTable( void )
double pom;
/* allocate dynamic tables */
- if( (TL_TABLE = malloc(TL_MAX*2*sizeof(int32_t))) == NULL)
- return 0;
- if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(int32_t *))) == NULL)
- {
- free(TL_TABLE);
- return 0;
- }
- if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(int32_t))) == NULL)
- {
- free(TL_TABLE);
- free(SIN_TABLE);
- return 0;
- }
- if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(int32_t))) == NULL)
- {
- free(TL_TABLE);
- free(SIN_TABLE);
- free(AMS_TABLE);
- return 0;
- }
+ TL_TABLE = g_malloc(TL_MAX * 2 * sizeof(int32_t));
+ SIN_TABLE = g_malloc(SIN_ENT * 4 * sizeof(int32_t *));
+ AMS_TABLE = g_malloc(AMS_ENT * 2 * sizeof(int32_t));
+ VIB_TABLE = g_malloc(VIB_ENT * 2 * sizeof(int32_t));
ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
/* make total level table */
for (t = 0;t < EG_ENT-1 ;t++){
@@ -696,10 +679,10 @@ static int OPLOpenTable( void )
static void OPLCloseTable( void )
{
g_free(ENV_CURVE);
- free(TL_TABLE);
- free(SIN_TABLE);
- free(AMS_TABLE);
- free(VIB_TABLE);
+ g_free(TL_TABLE);
+ g_free(SIN_TABLE);
+ g_free(AMS_TABLE);
+ g_free(VIB_TABLE);
}
/* CSM Key Control */
@@ -1082,9 +1065,9 @@ FM_OPL *OPLCreate(int clock, int rate)
state_size = sizeof(FM_OPL);
state_size += sizeof(OPL_CH)*max_ch;
/* allocate memory block */
- ptr = malloc(state_size);
- if(ptr==NULL) return NULL;
- /* clear */
+ ptr = g_malloc(state_size);
+
+ /* clear */
memset(ptr,0,state_size);
OPL = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL);
OPL->P_CH = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch;
@@ -1128,7 +1111,7 @@ void OPLDestroy(FM_OPL *OPL)
}
#endif
OPL_UnLockTable();
- free(OPL);
+ g_free(OPL);
}
/* ---------- Option handlers ---------- */
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v3] hw/audio/fmopl: Convert malloc/free to g_malloc/g_free
@ 2026-03-15 5:30 AADHYA R
0 siblings, 0 replies; 2+ messages in thread
From: AADHYA R @ 2026-03-15 5:30 UTC (permalink / raw)
To: kraxel; +Cc: qemu-trivial, qemu-devel
From 4311b6e7ea205c16a96cb7f4392b26db9e7b4d6f Mon Sep 17 00:00:00 2001
From: Aadhya R <aadhyar.cs24@rvce.edu.in>
Date: Sat, 14 Mar 2026 08:22:51 +0000
Subject: [PATCH v3] hw/audio/fmopl: Convert malloc/free to g_malloc/g_free
As per the QEMU coding style guide, replace standard C malloc()
and free() with GLib's g_malloc() and g_free().
Since g_malloc() safely aborts on out-of-memory errors, the
redundant NULL checks and their associated error-handling paths
have been removed.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1798
Signed-off-by: Aadhya R <aadhyar.cs24@rvce.edu.in>
---
hw/audio/fmopl.c | 41 ++++++++++++-----------------------------
1 file changed, 12 insertions(+), 29 deletions(-)
diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index a63ad0f04d..79e43d5410 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -50,7 +50,6 @@ static int opl_dbg_maxchip,opl_dbg_chip;
/* attack/decay rate time rate */
#define OPL_ARRATE 141280 /* RATE 4 = 2826.24ms @ 3.6MHz */
#define OPL_DRRATE 1956000 /* RATE 4 = 39280.64ms @ 3.6MHz */
-
#define DELTAT_MIXING_LEVEL (1) /* DELTA-T ADPCM MIXING LEVEL */
#define FREQ_BITS 24 /* frequency turn */
@@ -607,26 +606,10 @@ static int OPLOpenTable( void )
double pom;
/* allocate dynamic tables */
- if( (TL_TABLE = malloc(TL_MAX*2*sizeof(int32_t))) == NULL)
- return 0;
- if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(int32_t *))) == NULL)
- {
- free(TL_TABLE);
- return 0;
- }
- if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(int32_t))) == NULL)
- {
- free(TL_TABLE);
- free(SIN_TABLE);
- return 0;
- }
- if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(int32_t))) == NULL)
- {
- free(TL_TABLE);
- free(SIN_TABLE);
- free(AMS_TABLE);
- return 0;
- }
+ TL_TABLE = g_malloc(TL_MAX * 2 * sizeof(int32_t));
+ SIN_TABLE = g_malloc(SIN_ENT * 4 * sizeof(int32_t *));
+ AMS_TABLE = g_malloc(AMS_ENT * 2 * sizeof(int32_t));
+ VIB_TABLE = g_malloc(VIB_ENT * 2 * sizeof(int32_t));
ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
/* make total level table */
for (t = 0;t < EG_ENT-1 ;t++){
@@ -696,10 +679,10 @@ static int OPLOpenTable( void )
static void OPLCloseTable( void )
{
g_free(ENV_CURVE);
- free(TL_TABLE);
- free(SIN_TABLE);
- free(AMS_TABLE);
- free(VIB_TABLE);
+ g_free(TL_TABLE);
+ g_free(SIN_TABLE);
+ g_free(AMS_TABLE);
+ g_free(VIB_TABLE);
}
/* CSM Key Control */
@@ -1082,9 +1065,9 @@ FM_OPL *OPLCreate(int clock, int rate)
state_size = sizeof(FM_OPL);
state_size += sizeof(OPL_CH)*max_ch;
/* allocate memory block */
- ptr = malloc(state_size);
- if(ptr==NULL) return NULL;
- /* clear */
+ ptr = g_malloc(state_size);
+
+ /* clear */
memset(ptr,0,state_size);
OPL = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL);
OPL->P_CH = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch;
@@ -1128,7 +1111,7 @@ void OPLDestroy(FM_OPL *OPL)
}
#endif
OPL_UnLockTable();
- free(OPL);
+ g_free(OPL);
}
/* ---------- Option handlers ---------- */
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-15 12:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-15 5:30 [PATCH v3] hw/audio/fmopl: Convert malloc/free to g_malloc/g_free AADHYA R
-- strict thread matches above, loose matches on Subject: below --
2026-03-14 8:22 Aadhya-R
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox