@@ -346,7 +346,7 @@ static bool sbsa_firmware_init(SBSAMachineState *sms,
sbsa_flash_map(sms, sysmem, secure_sysmem);
- pflash_blk0 = pflash_cfi01_get_blk(sms->flash[0]);
+ pflash_blk0 = pflash_cfi01_get_blk(DEVICE(sms->flash[0]));
bios_name = MACHINE(sms)->firmware;
if (bios_name) {
@@ -1233,7 +1233,7 @@ static bool virt_firmware_init(VirtMachineState *vms,
virt_flash_map(vms, sysmem, secure_sysmem);
- pflash_blk0 = pflash_cfi01_get_blk(vms->flash[0]);
+ pflash_blk0 = pflash_cfi01_get_blk(DEVICE(vms->flash[0]));
bios_name = MACHINE(vms)->firmware;
if (bios_name) {
@@ -984,8 +984,10 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
return PFLASH_CFI01(dev);
}
-BlockBackend *pflash_cfi01_get_blk(PFlashCFI01 *fl)
+BlockBackend *pflash_cfi01_get_blk(DeviceState *dev)
{
+ PFlashCFI01 *fl = PFLASH_CFI01(dev);
+
return fl->blk;
}
@@ -152,7 +152,7 @@ static void pc_system_flash_map(PCMachineState *pcms,
for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) {
system_flash = pcms->flash[i];
- blk = pflash_cfi01_get_blk(system_flash);
+ blk = pflash_cfi01_get_blk(DEVICE(system_flash));
if (!blk) {
break;
}
@@ -216,7 +216,7 @@ void pc_system_firmware_init(PCMachineState *pcms,
for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) {
pflash_cfi01_legacy_drive(pcms->flash[i],
drive_get(IF_PFLASH, 0, i));
- pflash_blk[i] = pflash_cfi01_get_blk(pcms->flash[i]);
+ pflash_blk[i] = pflash_cfi01_get_blk(DEVICE(pcms->flash[i]));
}
/* Reject gaps */
@@ -21,7 +21,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
uint16_t id0, uint16_t id1,
uint16_t id2, uint16_t id3,
int be);
-BlockBackend *pflash_cfi01_get_blk(PFlashCFI01 *fl);
+BlockBackend *pflash_cfi01_get_blk(DeviceState *dev);
MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
void pflash_cfi01_legacy_drive(PFlashCFI01 *dev, DriveInfo *dinfo);
The point of a getter() function is to not expose the structure internal fields. Otherwise callers could simply access the PFlashCFI01::blk field. Have the callers pass a DeviceState* argument. The QOM type check is done in the callee. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/arm/sbsa-ref.c | 2 +- hw/arm/virt.c | 2 +- hw/block/pflash_cfi01.c | 4 +++- hw/i386/pc_sysfw.c | 4 ++-- include/hw/block/flash.h | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-)