]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
soc: qcom: preserve CPU endianness for QMI_DATA_LEN
authorAlexander Wilhelm <alexander.wilhelm@westermo.com>
Wed, 19 Nov 2025 10:40:07 +0000 (11:40 +0100)
committerBjorn Andersson <andersson@kernel.org>
Fri, 16 Jan 2026 14:19:46 +0000 (08:19 -0600)
To ensure correct handling of endianness in the QMI subsystem, the
QMI_DATA_LEN field used in host-side drivers remains in CPU-native byte
order. Remove unnecessary endianness conversions, considering that
QMI_DATA_LEN is always of type `u32` on the host. On the QMI wire
interface, however, its representation is variable and may use either 1 or
2 bytes.

Signed-off-by: Alexander Wilhelm <alexander.wilhelm@westermo.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20251119104008.3505152-4-alexander.wilhelm@westermo.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/soc/qcom/qmi_encdec.c

index 030b18fa086a436440949ca974b4931ac0e10674..28ce6f130b6ac355820bb295c8c96f9c6a6e385f 100644 (file)
@@ -406,6 +406,7 @@ static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
                        break;
 
                case QMI_DATA_LEN:
+                       memcpy(&data_len_value, buf_src, sizeof(u32));
                        data_len_sz = temp_ei->elem_size == sizeof(u8) ?
                                        sizeof(u8) : sizeof(u16);
                        /* Check to avoid out of range buffer access */
@@ -416,15 +417,13 @@ static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
                                return -ETOOSMALL;
                        }
                        if (data_len_sz == sizeof(u8)) {
-                               val8 = *(u8 *)buf_src;
-                               data_len_value = (u32)val8;
+                               val8 = data_len_value;
                                rc = qmi_encode_basic_elem(buf_dst, &val8,
                                                           1, data_len_sz);
                                if (rc < 0)
                                        return rc;
                        } else {
-                               val16 = *(u16 *)buf_src;
-                               data_len_value = (u32)le16_to_cpu(val16);
+                               val16 = data_len_value;
                                rc = qmi_encode_basic_elem(buf_dst, &val16,
                                                           1, data_len_sz);
                                if (rc < 0)
@@ -721,7 +720,6 @@ static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
        int rc;
        u8 val8;
        u16 val16;
-       u32 val32;
 
        while (decoded_bytes < in_buf_len) {
                if (dec_level >= 2 && temp_ei->data_type == QMI_EOTI)
@@ -773,8 +771,7 @@ static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
                                        return rc;
                                data_len_value = (u32)val16;
                        }
-                       val32 = cpu_to_le32(data_len_value);
-                       memcpy(buf_dst, &val32, sizeof(u32));
+                       memcpy(buf_dst, &data_len_value, sizeof(u32));
                        temp_ei = temp_ei + 1;
                        buf_dst = out_c_struct + temp_ei->offset;
                        tlv_len -= data_len_sz;