Skip to content

Commit ff6d365

Browse files
Jeff Johnsonandersson
Jeff Johnson
authored andcommitted
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 <[email protected]> Signed-off-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7eb89c1 commit ff6d365

File tree

4 files changed

+47
-45
lines changed

4 files changed

+47
-45
lines changed

drivers/soc/qcom/qmi_encdec.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ do { \
5757
#define TLV_TYPE_SIZE sizeof(u8)
5858
#define OPTIONAL_TLV_TYPE_START 0x10
5959

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,
6161
const void *in_c_struct, u32 out_buf_len,
6262
int enc_level);
6363

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,
6565
const void *in_buf, u32 in_buf_len, int dec_level);
6666

6767
/**
@@ -76,10 +76,10 @@ static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
7676
*
7777
* Return: struct info of the next element that can be encoded.
7878
*/
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)
8181
{
82-
struct qmi_elem_info *temp_ei = ei_array;
82+
const struct qmi_elem_info *temp_ei = ei_array;
8383
u8 tlv_type;
8484

8585
if (level > 1) {
@@ -101,11 +101,11 @@ static struct qmi_elem_info *skip_to_next_elem(struct qmi_elem_info *ei_array,
101101
*
102102
* Return: Expected minimum length of the QMI message or 0 on error.
103103
*/
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,
105105
int level)
106106
{
107107
int min_msg_len = 0;
108-
struct qmi_elem_info *temp_ei = ei_array;
108+
const struct qmi_elem_info *temp_ei = ei_array;
109109

110110
if (!ei_array)
111111
return min_msg_len;
@@ -194,13 +194,13 @@ static int qmi_encode_basic_elem(void *buf_dst, const void *buf_src,
194194
* Return: The number of bytes of encoded information on success or negative
195195
* errno on error.
196196
*/
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,
198198
void *buf_dst, const void *buf_src,
199199
u32 elem_len, u32 out_buf_len,
200200
int enc_level)
201201
{
202202
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;
204204

205205
for (i = 0; i < elem_len; i++) {
206206
rc = qmi_encode(temp_ei->ei_array, buf_dst, buf_src,
@@ -233,13 +233,13 @@ static int qmi_encode_struct_elem(struct qmi_elem_info *ei_array,
233233
* Return: The number of bytes of encoded information on success or negative
234234
* errno on error.
235235
*/
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,
237237
void *buf_dst, const void *buf_src,
238238
u32 out_buf_len, int enc_level)
239239
{
240240
int rc;
241241
int encoded_bytes = 0;
242-
struct qmi_elem_info *temp_ei = ei_array;
242+
const struct qmi_elem_info *temp_ei = ei_array;
243243
u32 string_len = 0;
244244
u32 string_len_sz = 0;
245245

@@ -289,11 +289,11 @@ static int qmi_encode_string_elem(struct qmi_elem_info *ei_array,
289289
* Return: The number of bytes of encoded information on success or negative
290290
* errno on error.
291291
*/
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,
293293
const void *in_c_struct, u32 out_buf_len,
294294
int enc_level)
295295
{
296-
struct qmi_elem_info *temp_ei = ei_array;
296+
const struct qmi_elem_info *temp_ei = ei_array;
297297
u8 opt_flag_value = 0;
298298
u32 data_len_value = 0, data_len_sz;
299299
u8 *buf_dst = (u8 *)out_buf;
@@ -468,13 +468,13 @@ static int qmi_decode_basic_elem(void *buf_dst, const void *buf_src,
468468
* Return: The total size of the decoded data elements on success, negative
469469
* errno on error.
470470
*/
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,
472472
void *buf_dst, const void *buf_src,
473473
u32 elem_len, u32 tlv_len,
474474
int dec_level)
475475
{
476476
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;
478478

479479
for (i = 0; i < elem_len && decoded_bytes < tlv_len; i++) {
480480
rc = qmi_decode(temp_ei->ei_array, buf_dst, buf_src,
@@ -514,15 +514,15 @@ static int qmi_decode_struct_elem(struct qmi_elem_info *ei_array,
514514
* Return: The total size of the decoded data elements on success, negative
515515
* errno on error.
516516
*/
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,
518518
void *buf_dst, const void *buf_src,
519519
u32 tlv_len, int dec_level)
520520
{
521521
int rc;
522522
int decoded_bytes = 0;
523523
u32 string_len = 0;
524524
u32 string_len_sz = 0;
525-
struct qmi_elem_info *temp_ei = ei_array;
525+
const struct qmi_elem_info *temp_ei = ei_array;
526526

527527
if (dec_level == 1) {
528528
string_len = tlv_len;
@@ -564,10 +564,10 @@ static int qmi_decode_string_elem(struct qmi_elem_info *ei_array,
564564
*
565565
* Return: Pointer to struct info, if found
566566
*/
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)
569569
{
570-
struct qmi_elem_info *temp_ei = ei_array;
570+
const struct qmi_elem_info *temp_ei = ei_array;
571571

572572
while (temp_ei->data_type != QMI_EOTI) {
573573
if (temp_ei->tlv_type == (u8)type)
@@ -590,11 +590,11 @@ static struct qmi_elem_info *find_ei(struct qmi_elem_info *ei_array,
590590
* Return: The number of bytes of decoded information on success, negative
591591
* errno on error.
592592
*/
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,
594594
const void *in_buf, u32 in_buf_len,
595595
int dec_level)
596596
{
597-
struct qmi_elem_info *temp_ei = ei_array;
597+
const struct qmi_elem_info *temp_ei = ei_array;
598598
u8 opt_flag_value = 1;
599599
u32 data_len_value = 0, data_len_sz = 0;
600600
u8 *buf_dst = out_c_struct;
@@ -713,7 +713,7 @@ static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
713713
* Return: Buffer with encoded message, or negative ERR_PTR() on error
714714
*/
715715
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,
717717
const void *c_struct)
718718
{
719719
struct qmi_header *hdr;
@@ -767,7 +767,7 @@ EXPORT_SYMBOL(qmi_encode_message);
767767
* errno on error.
768768
*/
769769
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)
771771
{
772772
if (!ei)
773773
return -EINVAL;
@@ -781,7 +781,7 @@ int qmi_decode_message(const void *buf, size_t len,
781781
EXPORT_SYMBOL(qmi_decode_message);
782782

783783
/* 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[] = {
785785
{
786786
.data_type = QMI_SIGNED_2_BYTE_ENUM,
787787
.elem_len = 1,

drivers/soc/qcom/qmi_interface.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ EXPORT_SYMBOL(qmi_add_server);
305305
* Return: Transaction id on success, negative errno on failure.
306306
*/
307307
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)
309309
{
310310
int ret;
311311

@@ -736,7 +736,8 @@ EXPORT_SYMBOL(qmi_handle_release);
736736
static ssize_t qmi_send_message(struct qmi_handle *qmi,
737737
struct sockaddr_qrtr *sq, struct qmi_txn *txn,
738738
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)
740741
{
741742
struct msghdr msghdr = {};
742743
struct kvec iv;
@@ -787,7 +788,7 @@ static ssize_t qmi_send_message(struct qmi_handle *qmi,
787788
*/
788789
ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
789790
struct qmi_txn *txn, int msg_id, size_t len,
790-
struct qmi_elem_info *ei, const void *c_struct)
791+
const struct qmi_elem_info *ei, const void *c_struct)
791792
{
792793
return qmi_send_message(qmi, sq, txn, QMI_REQUEST, msg_id, len, ei,
793794
c_struct);
@@ -808,7 +809,7 @@ EXPORT_SYMBOL(qmi_send_request);
808809
*/
809810
ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
810811
struct qmi_txn *txn, int msg_id, size_t len,
811-
struct qmi_elem_info *ei, const void *c_struct)
812+
const struct qmi_elem_info *ei, const void *c_struct)
812813
{
813814
return qmi_send_message(qmi, sq, txn, QMI_RESPONSE, msg_id, len, ei,
814815
c_struct);
@@ -827,7 +828,8 @@ EXPORT_SYMBOL(qmi_send_response);
827828
* Return: 0 on success, negative errno on failure.
828829
*/
829830
ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
830-
int msg_id, size_t len, struct qmi_elem_info *ei,
831+
int msg_id, size_t len,
832+
const struct qmi_elem_info *ei,
831833
const void *c_struct)
832834
{
833835
struct qmi_txn txn;

include/linux/soc/qcom/qmi.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct qmi_elem_info {
7575
enum qmi_array_type array_type;
7676
u8 tlv_type;
7777
u32 offset;
78-
struct qmi_elem_info *ei_array;
78+
const struct qmi_elem_info *ei_array;
7979
};
8080

8181
#define QMI_RESULT_SUCCESS_V01 0
@@ -102,7 +102,7 @@ struct qmi_response_type_v01 {
102102
u16 error;
103103
};
104104

105-
extern struct qmi_elem_info qmi_response_type_v01_ei[];
105+
extern const struct qmi_elem_info qmi_response_type_v01_ei[];
106106

107107
/**
108108
* struct qmi_service - context to track lookup-results
@@ -173,7 +173,7 @@ struct qmi_txn {
173173
struct completion completion;
174174
int result;
175175

176-
struct qmi_elem_info *ei;
176+
const struct qmi_elem_info *ei;
177177
void *dest;
178178
};
179179

@@ -189,7 +189,7 @@ struct qmi_msg_handler {
189189
unsigned int type;
190190
unsigned int msg_id;
191191

192-
struct qmi_elem_info *ei;
192+
const struct qmi_elem_info *ei;
193193

194194
size_t decoded_size;
195195
void (*fn)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
@@ -249,23 +249,23 @@ void qmi_handle_release(struct qmi_handle *qmi);
249249

250250
ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
251251
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);
253253
ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
254254
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);
256256
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,
258258
const void *c_struct);
259259

260260
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,
262262
const void *c_struct);
263263

264264
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);
266266

267267
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);
269269
int qmi_txn_wait(struct qmi_txn *txn, unsigned long timeout);
270270
void qmi_txn_cancel(struct qmi_txn *txn);
271271

samples/qmi/qmi_sample_client.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct test_name_type_v01 {
4242
char name[TEST_MAX_NAME_SIZE_V01];
4343
};
4444

45-
static struct qmi_elem_info test_name_type_v01_ei[] = {
45+
static const struct qmi_elem_info test_name_type_v01_ei[] = {
4646
{
4747
.data_type = QMI_DATA_LEN,
4848
.elem_len = 1,
@@ -71,7 +71,7 @@ struct test_ping_req_msg_v01 {
7171
struct test_name_type_v01 client_name;
7272
};
7373

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[] = {
7575
{
7676
.data_type = QMI_UNSIGNED_1_BYTE,
7777
.elem_len = 4,
@@ -113,7 +113,7 @@ struct test_ping_resp_msg_v01 {
113113
struct test_name_type_v01 service_name;
114114
};
115115

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[] = {
117117
{
118118
.data_type = QMI_STRUCT,
119119
.elem_len = 1,
@@ -172,7 +172,7 @@ struct test_data_req_msg_v01 {
172172
struct test_name_type_v01 client_name;
173173
};
174174

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[] = {
176176
{
177177
.data_type = QMI_DATA_LEN,
178178
.elem_len = 1,
@@ -224,7 +224,7 @@ struct test_data_resp_msg_v01 {
224224
struct test_name_type_v01 service_name;
225225
};
226226

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[] = {
228228
{
229229
.data_type = QMI_STRUCT,
230230
.elem_len = 1,

0 commit comments

Comments
 (0)