[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 04/21] hw/block: Pass DeviceState to pflash_cfi01_get_memo
From: |
Peter Maydell |
Subject: |
Re: [PATCH v2 04/21] hw/block: Pass DeviceState to pflash_cfi01_get_memory() |
Date: |
Fri, 13 Jan 2023 13:40:55 +0000 |
On Mon, 9 Jan 2023 at 23:43, Bernhard Beschow <shentey@gmail.com> wrote:
>
>
>
> Am 9. Januar 2023 12:08:16 UTC schrieb "Philippe Mathieu-Daudé"
> <philmd@linaro.org>:
> >The point of a getter() function is to not expose the structure
> >internal fields. Otherwise callers could simply access the
> >PFlashCFI01::mem field.
"modern" QOM style somewhat relies on providing a struct definition
for a device and trusting the code that uses the device not to
peek into its private fields. In this case we're only passing
a pointer anyway, so as you say we can just use a typedef if we want.
> The getter also works with a typedef which doesn't need the structure exposed.
>
> >Have the callers pass a DeviceState* argument. The QOM
> >type check is done in the callee.
>
> Performing the cast inside the getter is essentially "lying" about the
> getter's real interface which requires a PFlashCFI01 type to work properly.
> Weakening the typing to the super type also weakens the compiler's ability to
> catch mistakes at compile time. These mistakes can now only be found by
> actually running the code or by analyzing the code very, very carefully.
Yes, I'm not super-opposed to these patches but I did find
myself wondering whether adding all these casts in the caller
is really an improvement and what we're trying to achieve.
thanks
-- PMM
- Re: [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', (continued)
- Re: [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', Philippe Mathieu-Daudé, 2023/01/09
- Re: [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', Peter Maydell, 2023/01/13
- Re: [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', Markus Armbruster, 2023/01/16
- Re: [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', Philippe Mathieu-Daudé, 2023/01/16
- Re: [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', Markus Armbruster, 2023/01/17
[PATCH v2 03/21] hw/block: Use pflash_cfi01_get_blk() in pflash_cfi01_legacy_drive(), Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 02/21] hw/block: Pass DeviceState to pflash_cfi01_get_blk(), Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 06/21] hw/loongarch: Use generic DeviceState instead of PFlashCFI01, Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 04/21] hw/block: Pass DeviceState to pflash_cfi01_get_memory(), Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 05/21] hw/arm: Use generic DeviceState instead of PFlashCFI01, Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 07/21] hw/riscv: Use generic DeviceState instead of PFlashCFI01, Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 08/21] hw/i386: Use generic DeviceState instead of PFlashCFI01, Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 09/21] hw/xtensa: Use generic DeviceState instead of PFlashCFI01, Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 10/21] hw/sh4: Open-code pflash_cfi02_register(), Philippe Mathieu-Daudé, 2023/01/09
[PATCH v2 11/21] hw/arm/digic: Open-code pflash_cfi02_register(), Philippe Mathieu-Daudé, 2023/01/09