scmi_protocols: update struct scmi_base_discover_list_protocols_out

@protocols is an array of protocol identifiers that are implemented,
excluding the Base protocol. Four protocol identifiers are packed into
each array element. The number of elements of @protocols is specified by
callee-side.

Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Alice Guo <alice.guo@nxp.com>
This commit is contained in:
Ye Li
2025-04-28 18:37:33 +08:00
committed by Fabio Estevam
parent ced74d88b2
commit a881951c63
2 changed files with 19 additions and 9 deletions

View File

@@ -258,7 +258,7 @@ static int scmi_base_discover_impl_version_int(struct udevice *dev,
static int scmi_base_discover_list_protocols_int(struct udevice *dev, static int scmi_base_discover_list_protocols_int(struct udevice *dev,
u8 **protocols) u8 **protocols)
{ {
struct scmi_base_discover_list_protocols_out out; struct scmi_base_discover_list_protocols_out *out;
int cur; int cur;
struct scmi_msg msg = { struct scmi_msg msg = {
.protocol_id = SCMI_PROTOCOL_ID_BASE, .protocol_id = SCMI_PROTOCOL_ID_BASE,
@@ -268,7 +268,7 @@ static int scmi_base_discover_list_protocols_int(struct udevice *dev,
.out_msg = (u8 *)&out, .out_msg = (u8 *)&out,
.out_msg_sz = sizeof(out), .out_msg_sz = sizeof(out),
}; };
u32 num_agents, num_protocols; u32 num_agents, num_protocols, out_size;
u8 *buf; u8 *buf;
int i, ret; int i, ret;
@@ -276,22 +276,31 @@ static int scmi_base_discover_list_protocols_int(struct udevice *dev,
if (ret) if (ret)
return ret; return ret;
buf = calloc(sizeof(u8), num_protocols); out_size = sizeof(*out) + sizeof(u32) * (1 + num_protocols / 4);
if (!buf) out = calloc(1, out_size);
if (!out)
return -ENOMEM; return -ENOMEM;
msg.out_msg = (u8 *)out;
msg.out_msg_sz = out_size;
buf = calloc(sizeof(u8), num_protocols);
if (!buf) {
free(out);
return -ENOMEM;
}
cur = 0; cur = 0;
do { do {
ret = devm_scmi_process_msg(dev, &msg); ret = devm_scmi_process_msg(dev, &msg);
if (ret) if (ret)
goto err; goto err;
if (out.status) { if (out->status) {
ret = scmi_to_linux_errno(out.status); ret = scmi_to_linux_errno(out->status);
goto err; goto err;
} }
for (i = 0; i < out.num_protocols; i++, cur++) for (i = 0; i < out->num_protocols; i++, cur++)
buf[cur] = out.protocols[i / 4] >> ((i % 4) * 8); buf[cur] = out->protocols[i / 4] >> ((i % 4) * 8);
} while (cur < num_protocols); } while (cur < num_protocols);
*protocols = buf; *protocols = buf;
@@ -299,6 +308,7 @@ static int scmi_base_discover_list_protocols_int(struct udevice *dev,
return num_protocols; return num_protocols;
err: err:
free(buf); free(buf);
free(out);
return ret; return ret;
} }

View File

@@ -145,7 +145,7 @@ struct scmi_base_discover_impl_version_out {
struct scmi_base_discover_list_protocols_out { struct scmi_base_discover_list_protocols_out {
s32 status; s32 status;
u32 num_protocols; u32 num_protocols;
u32 protocols[3]; u32 protocols[];
}; };
/** /**