[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 4/9] hw/i2c: pmbus: refactor uint handling
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 4/9] hw/i2c: pmbus: refactor uint handling |
Date: |
Tue, 8 Mar 2022 19:13:15 +0100 |
From: Titus Rwantare <titusr@google.com>
This change cleans up the inputs to pmbus_receive uint, the length of
received data is contained in PMBusDevice state and doesn't need to be
passed around.
Signed-off-by: Titus Rwantare <titusr@google.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Corey Minyard <cminyard@mvista.com>
Message-Id: <20220307200605.4001451-5-titusr@google.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/i2c/pmbus_device.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c
index ff644c1d4a..8cb9db0f80 100644
--- a/hw/i2c/pmbus_device.c
+++ b/hw/i2c/pmbus_device.c
@@ -89,16 +89,16 @@ void pmbus_send_string(PMBusDevice *pmdev, const char *data)
}
-static uint64_t pmbus_receive_uint(const uint8_t *buf, uint8_t len)
+static uint64_t pmbus_receive_uint(PMBusDevice *pmdev)
{
uint64_t ret = 0;
/* Exclude command code from return value */
- buf++;
- len--;
+ pmdev->in_buf++;
+ pmdev->in_buf_len--;
- for (int i = len - 1; i >= 0; i--) {
- ret = ret << 8 | buf[i];
+ for (int i = pmdev->in_buf_len - 1; i >= 0; i--) {
+ ret = ret << 8 | pmdev->in_buf[i];
}
return ret;
}
@@ -110,7 +110,7 @@ uint8_t pmbus_receive8(PMBusDevice *pmdev)
"%s: length mismatch. Expected 1 byte, got %d bytes\n",
__func__, pmdev->in_buf_len - 1);
}
- return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len);
+ return pmbus_receive_uint(pmdev);
}
uint16_t pmbus_receive16(PMBusDevice *pmdev)
@@ -120,7 +120,7 @@ uint16_t pmbus_receive16(PMBusDevice *pmdev)
"%s: length mismatch. Expected 2 bytes, got %d bytes\n",
__func__, pmdev->in_buf_len - 1);
}
- return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len);
+ return pmbus_receive_uint(pmdev);
}
uint32_t pmbus_receive32(PMBusDevice *pmdev)
@@ -130,7 +130,7 @@ uint32_t pmbus_receive32(PMBusDevice *pmdev)
"%s: length mismatch. Expected 4 bytes, got %d bytes\n",
__func__, pmdev->in_buf_len - 1);
}
- return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len);
+ return pmbus_receive_uint(pmdev);
}
uint64_t pmbus_receive64(PMBusDevice *pmdev)
@@ -140,7 +140,7 @@ uint64_t pmbus_receive64(PMBusDevice *pmdev)
"%s: length mismatch. Expected 8 bytes, got %d bytes\n",
__func__, pmdev->in_buf_len - 1);
}
- return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len);
+ return pmbus_receive_uint(pmdev);
}
static uint8_t pmbus_out_buf_pop(PMBusDevice *pmdev)
--
2.34.1
- [PULL 0/9] I²C / SMBus / PMBus patches for 2022-03-08, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 1/9] hw/i2c: pmbus: add registers, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 2/9] hw/i2c: pmbus: fix error returns and guard against out of range accesses, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 3/9] hw/i2c: pmbus: add PEC unsupported warning, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 4/9] hw/i2c: pmbus: refactor uint handling,
Philippe Mathieu-Daudé <=
- [PULL 5/9] hw/i2c: pmbus: update MAINTAINERS, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 6/9] hw/i2c: Added linear mode translation for pmbus devices, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 7/9] hw/sensor: add Intersil ISL69260 device model, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 8/9] hw/sensor: add Renesas raa229004 PMBus device, Philippe Mathieu-Daudé, 2022/03/08
- [PULL 9/9] hw/sensor: add Renesas raa228000 device, Philippe Mathieu-Daudé, 2022/03/08
- Re: [PULL 0/9] I²C / SMBus / PMBus patches for 2022-03-08, Peter Maydell, 2022/03/10