Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc: qcom: qmi: use const for struct qmi_elem_info

Currently all usage of struct qmi_elem_info, which is used to define
the QMI message encoding/decoding rules, does not use const. This
prevents clients from registering const arrays. Since these arrays are
always pre-defined, they should be const, so add the const qualifier
to all places in the QMI interface where struct qmi_elem_info is used.

Once this patch is in place, clients can independently update their
pre-defined arrays to be const, as demonstrated in the QMI sample
code.

Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
Link: https://lore.kernel.org/r/20220822153435.7856-1-quic_jjohnson@quicinc.com

authored by

Jeff Johnson and committed by
Bjorn Andersson
ff6d3658 7eb89c17

+47 -45
+25 -25
drivers/soc/qcom/qmi_encdec.c
··· 57 57 #define TLV_TYPE_SIZE sizeof(u8) 58 58 #define OPTIONAL_TLV_TYPE_START 0x10 59 59 60 - static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf, 60 + static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf, 61 61 const void *in_c_struct, u32 out_buf_len, 62 62 int enc_level); 63 63 64 - static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct, 64 + static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct, 65 65 const void *in_buf, u32 in_buf_len, int dec_level); 66 66 67 67 /** ··· 76 76 * 77 77 * Return: struct info of the next element that can be encoded. 78 78 */ 79 - static struct qmi_elem_info *skip_to_next_elem(struct qmi_elem_info *ei_array, 80 - int level) 79 + static const struct qmi_elem_info * 80 + skip_to_next_elem(const struct qmi_elem_info *ei_array, int level) 81 81 { 82 - struct qmi_elem_info *temp_ei = ei_array; 82 + const struct qmi_elem_info *temp_ei = ei_array; 83 83 u8 tlv_type; 84 84 85 85 if (level > 1) { ··· 101 101 * 102 102 * Return: Expected minimum length of the QMI message or 0 on error. 103 103 */ 104 - static int qmi_calc_min_msg_len(struct qmi_elem_info *ei_array, 104 + static int qmi_calc_min_msg_len(const struct qmi_elem_info *ei_array, 105 105 int level) 106 106 { 107 107 int min_msg_len = 0; 108 - struct qmi_elem_info *temp_ei = ei_array; 108 + const struct qmi_elem_info *temp_ei = ei_array; 109 109 110 110 if (!ei_array) 111 111 return min_msg_len; ··· 194 194 * Return: The number of bytes of encoded information on success or negative 195 195 * errno on error. 196 196 */ 197 - static int qmi_encode_struct_elem(struct qmi_elem_info *ei_array, 197 + static int qmi_encode_struct_elem(const struct qmi_elem_info *ei_array, 198 198 void *buf_dst, const void *buf_src, 199 199 u32 elem_len, u32 out_buf_len, 200 200 int enc_level) 201 201 { 202 202 int i, rc, encoded_bytes = 0; 203 - struct qmi_elem_info *temp_ei = ei_array; 203 + const struct qmi_elem_info *temp_ei = ei_array; 204 204 205 205 for (i = 0; i < elem_len; i++) { 206 206 rc = qmi_encode(temp_ei->ei_array, buf_dst, buf_src, ··· 233 233 * Return: The number of bytes of encoded information on success or negative 234 234 * errno on error. 235 235 */ 236 - static int qmi_encode_string_elem(struct qmi_elem_info *ei_array, 236 + static int qmi_encode_string_elem(const struct qmi_elem_info *ei_array, 237 237 void *buf_dst, const void *buf_src, 238 238 u32 out_buf_len, int enc_level) 239 239 { 240 240 int rc; 241 241 int encoded_bytes = 0; 242 - struct qmi_elem_info *temp_ei = ei_array; 242 + const struct qmi_elem_info *temp_ei = ei_array; 243 243 u32 string_len = 0; 244 244 u32 string_len_sz = 0; 245 245 ··· 289 289 * Return: The number of bytes of encoded information on success or negative 290 290 * errno on error. 291 291 */ 292 - static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf, 292 + static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf, 293 293 const void *in_c_struct, u32 out_buf_len, 294 294 int enc_level) 295 295 { 296 - struct qmi_elem_info *temp_ei = ei_array; 296 + const struct qmi_elem_info *temp_ei = ei_array; 297 297 u8 opt_flag_value = 0; 298 298 u32 data_len_value = 0, data_len_sz; 299 299 u8 *buf_dst = (u8 *)out_buf; ··· 468 468 * Return: The total size of the decoded data elements on success, negative 469 469 * errno on error. 470 470 */ 471 - static int qmi_decode_struct_elem(struct qmi_elem_info *ei_array, 471 + static int qmi_decode_struct_elem(const struct qmi_elem_info *ei_array, 472 472 void *buf_dst, const void *buf_src, 473 473 u32 elem_len, u32 tlv_len, 474 474 int dec_level) 475 475 { 476 476 int i, rc, decoded_bytes = 0; 477 - struct qmi_elem_info *temp_ei = ei_array; 477 + const struct qmi_elem_info *temp_ei = ei_array; 478 478 479 479 for (i = 0; i < elem_len && decoded_bytes < tlv_len; i++) { 480 480 rc = qmi_decode(temp_ei->ei_array, buf_dst, buf_src, ··· 514 514 * Return: The total size of the decoded data elements on success, negative 515 515 * errno on error. 516 516 */ 517 - static int qmi_decode_string_elem(struct qmi_elem_info *ei_array, 517 + static int qmi_decode_string_elem(const struct qmi_elem_info *ei_array, 518 518 void *buf_dst, const void *buf_src, 519 519 u32 tlv_len, int dec_level) 520 520 { ··· 522 522 int decoded_bytes = 0; 523 523 u32 string_len = 0; 524 524 u32 string_len_sz = 0; 525 - struct qmi_elem_info *temp_ei = ei_array; 525 + const struct qmi_elem_info *temp_ei = ei_array; 526 526 527 527 if (dec_level == 1) { 528 528 string_len = tlv_len; ··· 564 564 * 565 565 * Return: Pointer to struct info, if found 566 566 */ 567 - static struct qmi_elem_info *find_ei(struct qmi_elem_info *ei_array, 568 - u32 type) 567 + static const struct qmi_elem_info *find_ei(const struct qmi_elem_info *ei_array, 568 + u32 type) 569 569 { 570 - struct qmi_elem_info *temp_ei = ei_array; 570 + const struct qmi_elem_info *temp_ei = ei_array; 571 571 572 572 while (temp_ei->data_type != QMI_EOTI) { 573 573 if (temp_ei->tlv_type == (u8)type) ··· 590 590 * Return: The number of bytes of decoded information on success, negative 591 591 * errno on error. 592 592 */ 593 - static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct, 593 + static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct, 594 594 const void *in_buf, u32 in_buf_len, 595 595 int dec_level) 596 596 { 597 - struct qmi_elem_info *temp_ei = ei_array; 597 + const struct qmi_elem_info *temp_ei = ei_array; 598 598 u8 opt_flag_value = 1; 599 599 u32 data_len_value = 0, data_len_sz = 0; 600 600 u8 *buf_dst = out_c_struct; ··· 713 713 * Return: Buffer with encoded message, or negative ERR_PTR() on error 714 714 */ 715 715 void *qmi_encode_message(int type, unsigned int msg_id, size_t *len, 716 - unsigned int txn_id, struct qmi_elem_info *ei, 716 + unsigned int txn_id, const struct qmi_elem_info *ei, 717 717 const void *c_struct) 718 718 { 719 719 struct qmi_header *hdr; ··· 767 767 * errno on error. 768 768 */ 769 769 int qmi_decode_message(const void *buf, size_t len, 770 - struct qmi_elem_info *ei, void *c_struct) 770 + const struct qmi_elem_info *ei, void *c_struct) 771 771 { 772 772 if (!ei) 773 773 return -EINVAL; ··· 781 781 EXPORT_SYMBOL(qmi_decode_message); 782 782 783 783 /* Common header in all QMI responses */ 784 - struct qmi_elem_info qmi_response_type_v01_ei[] = { 784 + const struct qmi_elem_info qmi_response_type_v01_ei[] = { 785 785 { 786 786 .data_type = QMI_SIGNED_2_BYTE_ENUM, 787 787 .elem_len = 1,
+7 -5
drivers/soc/qcom/qmi_interface.c
··· 305 305 * Return: Transaction id on success, negative errno on failure. 306 306 */ 307 307 int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn, 308 - struct qmi_elem_info *ei, void *c_struct) 308 + const struct qmi_elem_info *ei, void *c_struct) 309 309 { 310 310 int ret; 311 311 ··· 736 736 static ssize_t qmi_send_message(struct qmi_handle *qmi, 737 737 struct sockaddr_qrtr *sq, struct qmi_txn *txn, 738 738 int type, int msg_id, size_t len, 739 - struct qmi_elem_info *ei, const void *c_struct) 739 + const struct qmi_elem_info *ei, 740 + const void *c_struct) 740 741 { 741 742 struct msghdr msghdr = {}; 742 743 struct kvec iv; ··· 788 787 */ 789 788 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, 790 789 struct qmi_txn *txn, int msg_id, size_t len, 791 - struct qmi_elem_info *ei, const void *c_struct) 790 + const struct qmi_elem_info *ei, const void *c_struct) 792 791 { 793 792 return qmi_send_message(qmi, sq, txn, QMI_REQUEST, msg_id, len, ei, 794 793 c_struct); ··· 809 808 */ 810 809 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, 811 810 struct qmi_txn *txn, int msg_id, size_t len, 812 - struct qmi_elem_info *ei, const void *c_struct) 811 + const struct qmi_elem_info *ei, const void *c_struct) 813 812 { 814 813 return qmi_send_message(qmi, sq, txn, QMI_RESPONSE, msg_id, len, ei, 815 814 c_struct); ··· 828 827 * Return: 0 on success, negative errno on failure. 829 828 */ 830 829 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, 831 - int msg_id, size_t len, struct qmi_elem_info *ei, 830 + int msg_id, size_t len, 831 + const struct qmi_elem_info *ei, 832 832 const void *c_struct) 833 833 { 834 834 struct qmi_txn txn;
+10 -10
include/linux/soc/qcom/qmi.h
··· 75 75 enum qmi_array_type array_type; 76 76 u8 tlv_type; 77 77 u32 offset; 78 - struct qmi_elem_info *ei_array; 78 + const struct qmi_elem_info *ei_array; 79 79 }; 80 80 81 81 #define QMI_RESULT_SUCCESS_V01 0 ··· 102 102 u16 error; 103 103 }; 104 104 105 - extern struct qmi_elem_info qmi_response_type_v01_ei[]; 105 + extern const struct qmi_elem_info qmi_response_type_v01_ei[]; 106 106 107 107 /** 108 108 * struct qmi_service - context to track lookup-results ··· 173 173 struct completion completion; 174 174 int result; 175 175 176 - struct qmi_elem_info *ei; 176 + const struct qmi_elem_info *ei; 177 177 void *dest; 178 178 }; 179 179 ··· 189 189 unsigned int type; 190 190 unsigned int msg_id; 191 191 192 - struct qmi_elem_info *ei; 192 + const struct qmi_elem_info *ei; 193 193 194 194 size_t decoded_size; 195 195 void (*fn)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, ··· 249 249 250 250 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, 251 251 struct qmi_txn *txn, int msg_id, size_t len, 252 - struct qmi_elem_info *ei, const void *c_struct); 252 + const struct qmi_elem_info *ei, const void *c_struct); 253 253 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, 254 254 struct qmi_txn *txn, int msg_id, size_t len, 255 - struct qmi_elem_info *ei, const void *c_struct); 255 + const struct qmi_elem_info *ei, const void *c_struct); 256 256 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, 257 - int msg_id, size_t len, struct qmi_elem_info *ei, 257 + int msg_id, size_t len, const struct qmi_elem_info *ei, 258 258 const void *c_struct); 259 259 260 260 void *qmi_encode_message(int type, unsigned int msg_id, size_t *len, 261 - unsigned int txn_id, struct qmi_elem_info *ei, 261 + unsigned int txn_id, const struct qmi_elem_info *ei, 262 262 const void *c_struct); 263 263 264 264 int qmi_decode_message(const void *buf, size_t len, 265 - struct qmi_elem_info *ei, void *c_struct); 265 + const struct qmi_elem_info *ei, void *c_struct); 266 266 267 267 int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn, 268 - struct qmi_elem_info *ei, void *c_struct); 268 + const struct qmi_elem_info *ei, void *c_struct); 269 269 int qmi_txn_wait(struct qmi_txn *txn, unsigned long timeout); 270 270 void qmi_txn_cancel(struct qmi_txn *txn); 271 271
+5 -5
samples/qmi/qmi_sample_client.c
··· 42 42 char name[TEST_MAX_NAME_SIZE_V01]; 43 43 }; 44 44 45 - static struct qmi_elem_info test_name_type_v01_ei[] = { 45 + static const struct qmi_elem_info test_name_type_v01_ei[] = { 46 46 { 47 47 .data_type = QMI_DATA_LEN, 48 48 .elem_len = 1, ··· 71 71 struct test_name_type_v01 client_name; 72 72 }; 73 73 74 - static struct qmi_elem_info test_ping_req_msg_v01_ei[] = { 74 + static const struct qmi_elem_info test_ping_req_msg_v01_ei[] = { 75 75 { 76 76 .data_type = QMI_UNSIGNED_1_BYTE, 77 77 .elem_len = 4, ··· 113 113 struct test_name_type_v01 service_name; 114 114 }; 115 115 116 - static struct qmi_elem_info test_ping_resp_msg_v01_ei[] = { 116 + static const struct qmi_elem_info test_ping_resp_msg_v01_ei[] = { 117 117 { 118 118 .data_type = QMI_STRUCT, 119 119 .elem_len = 1, ··· 172 172 struct test_name_type_v01 client_name; 173 173 }; 174 174 175 - static struct qmi_elem_info test_data_req_msg_v01_ei[] = { 175 + static const struct qmi_elem_info test_data_req_msg_v01_ei[] = { 176 176 { 177 177 .data_type = QMI_DATA_LEN, 178 178 .elem_len = 1, ··· 224 224 struct test_name_type_v01 service_name; 225 225 }; 226 226 227 - static struct qmi_elem_info test_data_resp_msg_v01_ei[] = { 227 + static const struct qmi_elem_info test_data_resp_msg_v01_ei[] = { 228 228 { 229 229 .data_type = QMI_STRUCT, 230 230 .elem_len = 1,