[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 25/41] hw/i2c/pmbus_device: Fix modifying QOM class internals from
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 25/41] hw/i2c/pmbus_device: Fix modifying QOM class internals from instance |
Date: |
Thu, 31 Aug 2023 14:56:27 +0200 |
QOM object instance should not modify its class state (because
all other objects instanciated from this class get affected).
Instead of modifying the PMBusDeviceClass 'device_num_pages' field
the first time a instance is initialized (in pmbus_pages_alloc),
introduce a new pmbus_pages_num() helper which returns the page
number from the class without modifying the class state.
The code logic become slighly simplified.
Inspired-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230523064408.57941-4-philmd@linaro.org>
---
hw/i2c/pmbus_device.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c
index 44fe4eddbb..8bc9d5108a 100644
--- a/hw/i2c/pmbus_device.c
+++ b/hw/i2c/pmbus_device.c
@@ -190,15 +190,18 @@ static void pmbus_quick_cmd(SMBusDevice *smd, uint8_t
read)
}
}
+static uint8_t pmbus_pages_num(PMBusDevice *pmdev)
+{
+ const PMBusDeviceClass *k = PMBUS_DEVICE_GET_CLASS(pmdev);
+
+ /* some PMBus devices don't use the PAGE command, so they get 1 page */
+ return k->device_num_pages ? : 1;
+}
+
static void pmbus_pages_alloc(PMBusDevice *pmdev)
{
- /* some PMBus devices don't use the PAGE command, so they get 1 page */
- PMBusDeviceClass *k = PMBUS_DEVICE_GET_CLASS(pmdev);
- if (k->device_num_pages == 0) {
- k->device_num_pages = 1;
- }
- pmdev->num_pages = k->device_num_pages;
- pmdev->pages = g_new0(PMBusPage, k->device_num_pages);
+ pmdev->num_pages = pmbus_pages_num(pmdev);
+ pmdev->pages = g_new0(PMBusPage, pmdev->num_pages);
}
void pmbus_check_limits(PMBusDevice *pmdev)
--
2.41.0
- [PULL 15/41] target/mips: Remove unused headers in lcsr_helper.c, (continued)
- [PULL 15/41] target/mips: Remove unused headers in lcsr_helper.c, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 17/41] qemu/processor: Remove unused 'qemu/atomic.h' header, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 18/41] exec/translation-block: Clean up includes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 19/41] chardev/char-fe: Document FEWatchFunc typedef, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 22/41] hw/char/pl011: Display register name in trace events, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 20/41] hw/char: Have FEWatchFunc handlers return G_SOURCE_CONTINUE/REMOVE, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 16/41] target/xtensa: Include missing 'qemu/atomic.h' header, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 21/41] hw/char/pl011: Restrict MemoryRegionOps implementation access sizes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 24/41] hw/char/pl011: Replace magic values by register field definitions, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 23/41] hw/char/pl011: Remove duplicated PL011_INT_[RT]X definitions, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 25/41] hw/i2c/pmbus_device: Fix modifying QOM class internals from instance,
Philippe Mathieu-Daudé <=
- [PULL 26/41] hw/i2c: spelling fixes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 27/41] hw/ide: spelling fixes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 29/41] hw/mips: spelling fixes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 30/41] hw/sd: spelling fixes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 31/41] hw/usb: spelling fixes, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 32/41] hw/usb/hcd-xhci: Avoid variable-length array in xhci_get_port_bandwidth(), Philippe Mathieu-Daudé, 2023/08/31
- [PULL 33/41] hw/i386: Remove unuseful kvmclock_create() stub, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 35/41] util/fifo8: Fix typo in fifo8_push_all() description, Philippe Mathieu-Daudé, 2023/08/31
- [PULL 34/41] hw/i386: Rename 'hw/kvm/clock.h' -> 'hw/i386/kvm/clock.h', Philippe Mathieu-Daudé, 2023/08/31
- [PULL 36/41] util: spelling fixes, Philippe Mathieu-Daudé, 2023/08/31