diff mbox series

tools/xl: fix channel configuration setting

Message ID 20250224142005.24172-1-jgross@suse.com (mailing list archive)
State Superseded
Headers show
Series tools/xl: fix channel configuration setting | expand

Commit Message

Jürgen Groß Feb. 24, 2025, 2:20 p.m. UTC
Channels work differently than other device types: their devid should
be -1 initially in order to distinguish them from the primary console
which has the devid of 0.

So when parsing the channel configuration, set devid explicitly to -1
after expanding the channels array, as this expansion of the array will
have set the devid to the index of the item in the array, overwriting
the -1 initialization done by libxl_device_channel_init().

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/xl/xl_parse.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Anthony PERARD Feb. 24, 2025, 4:40 p.m. UTC | #1
On Mon, Feb 24, 2025 at 03:20:05PM +0100, Juergen Gross wrote:
> Channels work differently than other device types: their devid should
> be -1 initially in order to distinguish them from the primary console
> which has the devid of 0.
> 
> So when parsing the channel configuration, set devid explicitly to -1
> after expanding the channels array, as this expansion of the array will
> have set the devid to the index of the item in the array, overwriting
> the -1 initialization done by libxl_device_channel_init().
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  tools/xl/xl_parse.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
> index 3d85be7dd4..4705f6fd4b 100644
> --- a/tools/xl/xl_parse.c
> +++ b/tools/xl/xl_parse.c
> @@ -2426,6 +2426,9 @@ void parse_config_data(const char *config_source,
>              chn = ARRAY_EXTEND_INIT(d_config->channels, d_config->num_channels,
>                                     libxl_device_channel_init);
>  
> +            /* ARRAY_EXTEND_INIT() has set the devid, but it must be -1. */
> +            chn->devid = -1;
> +

You can use ARRAY_EXTEND_INIT_NODEVID() instead which doesn't touch
`devid` and let the value set by libxl_device_channel_init().

Cheers,
diff mbox series

Patch

diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index 3d85be7dd4..4705f6fd4b 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -2426,6 +2426,9 @@  void parse_config_data(const char *config_source,
             chn = ARRAY_EXTEND_INIT(d_config->channels, d_config->num_channels,
                                    libxl_device_channel_init);
 
+            /* ARRAY_EXTEND_INIT() has set the devid, but it must be -1. */
+            chn->devid = -1;
+
             split_string_into_string_list(buf, ",", &pairs);
             len = libxl_string_list_length(&pairs);
             for (i = 0; i < len; i++) {