platform: pldm_msgbuf for decode_sensor_op_data()
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I032977b888338d31bfd2b8bfd3ccdc3da75f85b2
diff --git a/src/platform.c b/src/platform.c
index fe41073..c3b658f 100644
--- a/src/platform.c
+++ b/src/platform.c
@@ -1211,20 +1211,25 @@
int decode_sensor_op_data(const uint8_t *sensor_data, size_t sensor_data_length,
uint8_t *present_op_state, uint8_t *previous_op_state)
{
- if (sensor_data == NULL || present_op_state == NULL ||
- previous_op_state == NULL) {
+ struct pldm_msgbuf _buf;
+ struct pldm_msgbuf *buf = &_buf;
+ int rc;
+
+ if (present_op_state == NULL || previous_op_state == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
- if (sensor_data_length !=
- PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH) {
- return PLDM_ERROR_INVALID_LENGTH;
+
+ rc =
+ pldm_msgbuf_init(buf, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH,
+ sensor_data, sensor_data_length);
+ if (rc) {
+ return rc;
}
- struct pldm_sensor_event_sensor_op_state *sensor_op_data =
- (struct pldm_sensor_event_sensor_op_state *)sensor_data;
- *present_op_state = sensor_op_data->present_op_state;
- *previous_op_state = sensor_op_data->previous_op_state;
- return PLDM_SUCCESS;
+ pldm_msgbuf_extract(buf, present_op_state);
+ pldm_msgbuf_extract(buf, previous_op_state);
+
+ return pldm_msgbuf_destroy_consumed(buf);
}
int decode_state_sensor_data(const uint8_t *sensor_data,