Re: [PATCH 1/4] hw/gpio/pca9552: Avoid using g_newa()
Reviewed-by: Glenn Miles
Thanks!
Glenn
On Thu, 2025-06-05 at 21:35 +0200, Philippe Mathieu-Daudé wrote:
> We have pin_count <= PCA955X_PIN_COUNT_MAX. Having
> PCA955X_PIN_COUNT_MAX = 16, it is safe to explicitly
> allocate the char buffer on the stack, without g_newa().
>
> Signed-off-by: Philippe Mathieu-Daudé
> ---
> hw/gpio/pca9552.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/gpio/pca9552.c b/hw/gpio/pca9552.c
> index d65c0a2e90f..1e10238b2e0 100644
> --- a/hw/gpio/pca9552.c
> +++ b/hw/gpio/pca9552.c
> @@ -76,7 +76,7 @@ static void pca955x_display_pins_status(PCA955xState *s,
> return;
> }
> if (trace_event_get_state_backends(TRACE_PCA955X_GPIO_STATUS)) {
> -char *buf = g_newa(char, k->pin_count + 1);
> +char buf[PCA955X_PIN_COUNT_MAX + 1];
>
> for (i = 0; i < k->pin_count; i++) {
> if (extract32(pins_status, i, 1)) {
[PATCH 1/4] hw/gpio/pca9552: Avoid using g_newa()
We have pin_count <= PCA955X_PIN_COUNT_MAX. Having
PCA955X_PIN_COUNT_MAX = 16, it is safe to explicitly
allocate the char buffer on the stack, without g_newa().
Signed-off-by: Philippe Mathieu-Daudé
---
hw/gpio/pca9552.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/gpio/pca9552.c b/hw/gpio/pca9552.c
index d65c0a2e90f..1e10238b2e0 100644
--- a/hw/gpio/pca9552.c
+++ b/hw/gpio/pca9552.c
@@ -76,7 +76,7 @@ static void pca955x_display_pins_status(PCA955xState *s,
return;
}
if (trace_event_get_state_backends(TRACE_PCA955X_GPIO_STATUS)) {
-char *buf = g_newa(char, k->pin_count + 1);
+char buf[PCA955X_PIN_COUNT_MAX + 1];
for (i = 0; i < k->pin_count; i++) {
if (extract32(pins_status, i, 1)) {
--
2.49.0
