hw/nvram/fw_cfg: Move boot_splash_filedata variables into fw_cfg.c
PATCH 1/1 hw/nvram/fw_cfg: Move boot_splash_filedata variables into fw_cfg.c
The global boot_splash_filedata and boot_splash_filedata_size variables are only used in fw_cfg.c. So there is really no need that these need to be global and reside in vl.c. Move them to fw_cfg.c instead.
--- hw/nvram/fw_cfg.c | 9 +++++++++ include/hw/nvram/fw_cfg.h | 1 + include/sysemu/sysemu.h | 2 -- vl.c | 10 +--------- 4 files changed, 11 insertions(+), 11 deletions(-)
hw/nvram/fw_cfg.c +9 -0
@@ -63,6 +63,9 @@ struct FWCfgEntry {#define JPG_FILE 0#define BMP_FILE 1 +static uint8_t *boot_splash_filedata; +static size_t boot_splash_filedata_size; +static char *read_splashfile (char *filename,gsize *file_sizep,int *file_typep) {
@@ -175,6 +178,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) } } +void fw_cfg_res_free (void ) +{ +g_free (boot_splash_filedata); + boot_splash_filedata =NULL ; +} +static void fw_cfg_reboot (FWCfgState *s) {const char *reboot_timeout =NULL ;
include/hw/nvram/fw_cfg.h +1 -0
@@ -225,5 +225,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,FWCfgState *fw_cfg_find (void );bool fw_cfg_dma_enabled (void *opaque); +void fw_cfg_res_free (void );#endif
include/sysemu/sysemu.h +0 -2
@@ -111,8 +111,6 @@ extern int no_shutdown;extern int old_param;extern int boot_menu;extern bool boot_strict; -extern uint8_t *boot_splash_filedata; -extern size_t boot_splash_filedata_size;extern bool enable_mlock;extern bool enable_cpu_pm;extern QEMUClockType rtc_clock;
vl.c +1 -9
@@ -187,8 +187,6 @@ unsigned int nb_prom_envs = 0;const char *prom_envs[MAX_PROM_ENVS ];int boot_menu;bool boot_strict; -uint8_t *boot_splash_filedata; -size_t boot_splash_filedata_size;bool wakeup_suspend_enabled;int icount_align_option;
@@ -559,12 +557,6 @@ const char *qemu_get_vm_name(void)return qemu_name; } -static void res_free (void ) -{ -g_free (boot_splash_filedata); - boot_splash_filedata =NULL ; -} -static int default_driver_check (void *opaque,QemuOpts *opts,Error **errp) {const char *driver =qemu_opt_get (opts,"driver" );
@@ -4585,7 +4577,7 @@ int main(int argc, char **argv, char **envp)job_cancel_sync_all ();bdrv_close_all (); -res_free (); +fw_cfg_res_free ();/* vhost-user must be cleaned up before chardevs. */ tpm_cleanup ();
Signature · 1 line
1.8.3.1
Hi Thomas,
Quoted 91 lines · Thomas Huth
The global
boot_splash_filedataandboot_splash_filedata_sizevariables are only used infw_cfg.c. So there is really no need that these need to be global and reside invl.c. Move them tofw_cfg.cinstead.Signed-off-by Thomas Huth <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++++++ include/hw/nvram/fw_cfg.h | 1 + include/sysemu/sysemu.h | 2 -- vl.c | 10 +--------- 4 files changed, 11 insertions(+), 11 deletions(-)hw/nvram/fw_cfg.c +9
-0@@ -63,6 +63,9 @@ struct FWCfgEntry {#define JPG_FILE 0#define BMP_FILE 1 +static uint8_t *boot_splash_filedata; +static size_t boot_splash_filedata_size; +static char *read_splashfile (char *filename,gsize *file_sizep,int *file_typep) {@@ -175,6 +178,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) } } +void fw_cfg_res_free (void ) +{ +g_free (boot_splash_filedata); + boot_splash_filedata =NULL ; +} +static void fw_cfg_reboot (FWCfgState *s) {const char *reboot_timeout =NULL ;include/hw/nvram/fw_cfg.h +1
-0@@ -225,5 +225,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,FWCfgState *fw_cfg_find (void );bool fw_cfg_dma_enabled (void *opaque); +void fw_cfg_res_free (void );#endif include/sysemu/sysemu.h +0
-2@@ -111,8 +111,6 @@ extern int no_shutdown;extern int old_param;extern int boot_menu;extern bool boot_strict; -extern uint8_t *boot_splash_filedata; -extern size_t boot_splash_filedata_size;extern bool enable_mlock;extern bool enable_cpu_pm;extern QEMUClockType rtc_clock;vl.c +0
-8@@ -187,8 +187,6 @@ unsigned int nb_prom_envs = 0;const char *prom_envs[MAX_PROM_ENVS ];int boot_menu;bool boot_strict; -uint8_t *boot_splash_filedata; -size_t boot_splash_filedata_size;bool wakeup_suspend_enabled;int icount_align_option;@@ -559,12 +557,6 @@ const char *qemu_get_vm_name(void)return qemu_name; } -static void res_free (void ) -{ -g_free (boot_splash_filedata); - boot_splash_filedata =NULL ; -} -static int default_driver_check (void *opaque,QemuOpts *opts,Error **errp) {const char *driver =qemu_opt_get (opts,"driver" );
vl.c int main(int argc, char **argv, char **envp) · line 4583
Quoted 8 lines
vl.c +1
-1@@ -4585,7 +4577,7 @@ int main(int argc, char **argv, char **envp)job_cancel_sync_all ();bdrv_close_all (); -res_free (); +fw_cfg_res_free ();/* vhost-user must be cleaned up before chardevs. */ tpm_cleanup ();
The res_free() function call in main() goes back to commit 3d3b8303c6f8 ("showing a splash picture when start", 2011-07-29). That seems to be the original addition of the bootsplash feature. And, res_free() appears to simply release dynamic memory before the QEMU process exits.
Do we release malloc'd memory, as a general rule, before we exit the QEMU process (with exit status 0)? My impression has been that we don't care; we just let the kernel forget about all memory that the QEMU process used to own.
If that's the case, I suggest to respin this patch, deleting res_free() completely. AFAICS there are no other call sites. That would be a nice improvement IMO (we wouldn't have to extend "include/hw/nvram/fw_cfg.h").
Thanks!
Laszlo
Quoted 108 lines · Laszlo Ersek
Hi Thomas,
Quoted 91 lines · Thomas Huth
The global
boot_splash_filedataandboot_splash_filedata_sizevariables are only used infw_cfg.c. So there is really no need that these need to be global and reside invl.c. Move them tofw_cfg.cinstead.Signed-off-by Thomas Huth <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++++++ include/hw/nvram/fw_cfg.h | 1 + include/sysemu/sysemu.h | 2 -- vl.c | 10 +--------- 4 files changed, 11 insertions(+), 11 deletions(-)hw/nvram/fw_cfg.c +9
-0@@ -63,6 +63,9 @@ struct FWCfgEntry {#define JPG_FILE 0#define BMP_FILE 1 +static uint8_t *boot_splash_filedata; +static size_t boot_splash_filedata_size; +static char *read_splashfile (char *filename,gsize *file_sizep,int *file_typep) {@@ -175,6 +178,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) } } +void fw_cfg_res_free (void ) +{ +g_free (boot_splash_filedata); + boot_splash_filedata =NULL ; +} +static void fw_cfg_reboot (FWCfgState *s) {const char *reboot_timeout =NULL ;include/hw/nvram/fw_cfg.h +1
-0@@ -225,5 +225,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,FWCfgState *fw_cfg_find (void );bool fw_cfg_dma_enabled (void *opaque); +void fw_cfg_res_free (void );#endif include/sysemu/sysemu.h +0
-2@@ -111,8 +111,6 @@ extern int no_shutdown;extern int old_param;extern int boot_menu;extern bool boot_strict; -extern uint8_t *boot_splash_filedata; -extern size_t boot_splash_filedata_size;extern bool enable_mlock;extern bool enable_cpu_pm;extern QEMUClockType rtc_clock;vl.c +0
-8@@ -187,8 +187,6 @@ unsigned int nb_prom_envs = 0;const char *prom_envs[MAX_PROM_ENVS ];int boot_menu;bool boot_strict; -uint8_t *boot_splash_filedata; -size_t boot_splash_filedata_size;bool wakeup_suspend_enabled;int icount_align_option;@@ -559,12 +557,6 @@ const char *qemu_get_vm_name(void)return qemu_name; } -static void res_free (void ) -{ -g_free (boot_splash_filedata); - boot_splash_filedata =NULL ; -} -static int default_driver_check (void *opaque,QemuOpts *opts,Error **errp) {const char *driver =qemu_opt_get (opts,"driver" );vl.c int main(int argc, char **argv, char **envp) · line 4583
Quoted 8 lines
vl.c +1
-1@@ -4585,7 +4577,7 @@ int main(int argc, char **argv, char **envp)job_cancel_sync_all ();bdrv_close_all (); -res_free (); +fw_cfg_res_free ();/* vhost-user must be cleaned up before chardevs. */ tpm_cleanup ();The
res_free()function call inmain()goes back to commit3d3b8303c6f8("showing a splash picture when start", 2011-07-29). That seems to be the original addition of the bootsplash feature. And,res_free()appears to simply release dynamic memory before the QEMU process exits.
Quoted 8 lines
Do we release malloc'd memory, as a general rule, before we exit the QEMU process (with exit status 0)? My impression has been that we don't care; we just let the kernel forget about all memory that the QEMU process used to own.
If that's the case, I suggest to respin this patch, deleting
res_free()completely. AFAICS there are no other call sites. That would be a nice improvement IMO (we wouldn't have to extend "include/hw/nvram/fw_cfg.h").
Hmm, thinking about this for a while, the fw_cfg is a qdev device, so I think we should at least add an unrealize() function where we clean up the allocated memory, even if the unrealize function is currently not called yet, since the device never gets destroyed...
Thomas
Quoted 121 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 118 lines · Thomas Huth
Quoted 116 lines · Laszlo Ersek
Hi Thomas,
Quoted 91 lines · Thomas Huth
The global
boot_splash_filedataandboot_splash_filedata_sizevariables are only used infw_cfg.c. So there is really no need that these need to be global and reside invl.c. Move them tofw_cfg.cinstead.Signed-off-by Thomas Huth <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++++++ include/hw/nvram/fw_cfg.h | 1 + include/sysemu/sysemu.h | 2 -- vl.c | 10 +--------- 4 files changed, 11 insertions(+), 11 deletions(-)hw/nvram/fw_cfg.c +9
-0@@ -63,6 +63,9 @@ struct FWCfgEntry {#define JPG_FILE 0#define BMP_FILE 1 +static uint8_t *boot_splash_filedata; +static size_t boot_splash_filedata_size; +static char *read_splashfile (char *filename,gsize *file_sizep,int *file_typep) {@@ -175,6 +178,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) } } +void fw_cfg_res_free (void ) +{ +g_free (boot_splash_filedata); + boot_splash_filedata =NULL ; +} +static void fw_cfg_reboot (FWCfgState *s) {const char *reboot_timeout =NULL ;include/hw/nvram/fw_cfg.h +1
-0@@ -225,5 +225,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,FWCfgState *fw_cfg_find (void );bool fw_cfg_dma_enabled (void *opaque); +void fw_cfg_res_free (void );#endif include/sysemu/sysemu.h +0
-2@@ -111,8 +111,6 @@ extern int no_shutdown;extern int old_param;extern int boot_menu;extern bool boot_strict; -extern uint8_t *boot_splash_filedata; -extern size_t boot_splash_filedata_size;extern bool enable_mlock;extern bool enable_cpu_pm;extern QEMUClockType rtc_clock;vl.c +0
-8@@ -187,8 +187,6 @@ unsigned int nb_prom_envs = 0;const char *prom_envs[MAX_PROM_ENVS ];int boot_menu;bool boot_strict; -uint8_t *boot_splash_filedata; -size_t boot_splash_filedata_size;bool wakeup_suspend_enabled;int icount_align_option;@@ -559,12 +557,6 @@ const char *qemu_get_vm_name(void)return qemu_name; } -static void res_free (void ) -{ -g_free (boot_splash_filedata); - boot_splash_filedata =NULL ; -} -static int default_driver_check (void *opaque,QemuOpts *opts,Error **errp) {const char *driver =qemu_opt_get (opts,"driver" );vl.c int main(int argc, char **argv, char **envp) · line 4583
Quoted 8 lines
vl.c +1
-1@@ -4585,7 +4577,7 @@ int main(int argc, char **argv, char **envp)job_cancel_sync_all ();bdrv_close_all (); -res_free (); +fw_cfg_res_free ();/* vhost-user must be cleaned up before chardevs. */ tpm_cleanup ();The
res_free()function call inmain()goes back to commit3d3b8303c6f8("showing a splash picture when start", 2011-07-29). That seems to be the original addition of the bootsplash feature. And,res_free()appears to simply release dynamic memory before the QEMU process exits.Do we release malloc'd memory, as a general rule, before we exit the QEMU process (with exit status 0)? My impression has been that we don't care; we just let the kernel forget about all memory that the QEMU process used to own.
If that's the case, I suggest to respin this patch, deleting
res_free()completely. AFAICS there are no other call sites. That would be a nice improvement IMO (we wouldn't have to extend "include/hw/nvram/fw_cfg.h").
Quoted 7 lines
Quoted 4 lines
Hmm, thinking about this for a while, the
fw_cfgis a qdev device, so I think we should at least add anunrealize()function where we clean up the allocated memory, even if the unrealize function is currently not called yet, since the device never gets destroyed...I worked on a similar cleanup last month, I can submit it this afternoon. Do you mind having a look at it before reworking this patch?
Sure, just put me on CC: so that I don't miss it.
Thomas
Hi Thomas,
Quoted 114 lines · Thomas Huth
Quoted 113 lines · Laszlo Ersek
Hi Thomas,
Quoted 91 lines · Thomas Huth
The global
boot_splash_filedataandboot_splash_filedata_sizevariables are only used infw_cfg.c. So there is really no need that these need to be global and reside invl.c. Move them tofw_cfg.cinstead.Signed-off-by Thomas Huth <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++++++ include/hw/nvram/fw_cfg.h | 1 + include/sysemu/sysemu.h | 2 -- vl.c | 10 +--------- 4 files changed, 11 insertions(+), 11 deletions(-)hw/nvram/fw_cfg.c +9
-0@@ -63,6 +63,9 @@ struct FWCfgEntry {#define JPG_FILE 0#define BMP_FILE 1 +static uint8_t *boot_splash_filedata; +static size_t boot_splash_filedata_size; +static char *read_splashfile (char *filename,gsize *file_sizep,int *file_typep) {@@ -175,6 +178,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) } } +void fw_cfg_res_free (void ) +{ +g_free (boot_splash_filedata); + boot_splash_filedata =NULL ; +} +static void fw_cfg_reboot (FWCfgState *s) {const char *reboot_timeout =NULL ;include/hw/nvram/fw_cfg.h +1
-0@@ -225,5 +225,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,FWCfgState *fw_cfg_find (void );bool fw_cfg_dma_enabled (void *opaque); +void fw_cfg_res_free (void );#endif include/sysemu/sysemu.h +0
-2@@ -111,8 +111,6 @@ extern int no_shutdown;extern int old_param;extern int boot_menu;extern bool boot_strict; -extern uint8_t *boot_splash_filedata; -extern size_t boot_splash_filedata_size;extern bool enable_mlock;extern bool enable_cpu_pm;extern QEMUClockType rtc_clock;vl.c +0
-8@@ -187,8 +187,6 @@ unsigned int nb_prom_envs = 0;const char *prom_envs[MAX_PROM_ENVS ];int boot_menu;bool boot_strict; -uint8_t *boot_splash_filedata; -size_t boot_splash_filedata_size;bool wakeup_suspend_enabled;int icount_align_option;@@ -559,12 +557,6 @@ const char *qemu_get_vm_name(void)return qemu_name; } -static void res_free (void ) -{ -g_free (boot_splash_filedata); - boot_splash_filedata =NULL ; -} -static int default_driver_check (void *opaque,QemuOpts *opts,Error **errp) {const char *driver =qemu_opt_get (opts,"driver" );vl.c int main(int argc, char **argv, char **envp) · line 4583
Quoted 8 lines
vl.c +1
-1@@ -4585,7 +4577,7 @@ int main(int argc, char **argv, char **envp)job_cancel_sync_all ();bdrv_close_all (); -res_free (); +fw_cfg_res_free ();/* vhost-user must be cleaned up before chardevs. */ tpm_cleanup ();The
res_free()function call inmain()goes back to commit3d3b8303c6f8("showing a splash picture when start", 2011-07-29). That seems to be the original addition of the bootsplash feature. And,res_free()appears to simply release dynamic memory before the QEMU process exits.Do we release malloc'd memory, as a general rule, before we exit the QEMU process (with exit status 0)? My impression has been that we don't care; we just let the kernel forget about all memory that the QEMU process used to own.
Quoted 8 lines
Quoted 3 lines
If that's the case, I suggest to respin this patch, deleting
res_free()completely. AFAICS there are no other call sites. That would be a nice improvement IMO (we wouldn't have to extend "include/hw/nvram/fw_cfg.h").Hmm, thinking about this for a while, the
fw_cfgis a qdev device, so I think we should at least add anunrealize()function where we clean up the allocated memory, even if the unrealize function is currently not called yet, since the device never gets destroyed...
I worked on a similar cleanup last month, I can submit it this afternoon. Do you mind having a look at it before reworking this patch? I'm not sure which one is the best, but since the work is already done I don't want any of us waste his time :)
Thanks,
Phil.