diff mbox series

soc: qcom: qmi: use const for struct qmi_elem_info

Message ID 20220822064648.30794-1-quic_jjohnson@quicinc.com (mailing list archive)
State Superseded
Headers show
Series soc: qcom: qmi: use const for struct qmi_elem_info | expand

Commit Message

Jeff Johnson Aug. 22, 2022, 6:46 a.m. UTC
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>
---
 drivers/soc/qcom/qmi_encdec.c    | 48 ++++++++++++++++----------------
 drivers/soc/qcom/qmi_interface.c | 12 ++++----
 include/linux/soc/qcom/qmi.h     | 20 ++++++-------
 samples/qmi/qmi_sample_client.c  | 10 +++----
 4 files changed, 46 insertions(+), 44 deletions(-)

Comments

kernel test robot Aug. 22, 2022, 8:47 a.m. UTC | #1
Hi Jeff,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc2 next-20220822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jeff-Johnson/soc-qcom-qmi-use-const-for-struct-qmi_elem_info/20220822-144905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1c23f9e627a7b412978b4e852793c5e3c3efc555
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220822/202208221632.bulgoDlE-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/84f0de3071b40fad5e5a48ad27b16ce28f9210fb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jeff-Johnson/soc-qcom-qmi-use-const-for-struct-qmi_elem_info/20220822-144905
        git checkout 84f0de3071b40fad5e5a48ad27b16ce28f9210fb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/soc/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/soc/qcom/qmi_encdec.c: In function 'skip_to_next_elem':
>> drivers/soc/qcom/qmi_encdec.c:94:16: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      94 |         return temp_ei;
         |                ^~~~~~~


vim +/const +94 drivers/soc/qcom/qmi_encdec.c

9b8a11e8261527 Bjorn Andersson 2017-12-05  59  
84f0de3071b40f Jeff Johnson    2022-08-21  60  static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
9b8a11e8261527 Bjorn Andersson 2017-12-05  61  		      const void *in_c_struct, u32 out_buf_len,
9b8a11e8261527 Bjorn Andersson 2017-12-05  62  		      int enc_level);
9b8a11e8261527 Bjorn Andersson 2017-12-05  63  
84f0de3071b40f Jeff Johnson    2022-08-21  64  static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
9b8a11e8261527 Bjorn Andersson 2017-12-05  65  		      const void *in_buf, u32 in_buf_len, int dec_level);
9b8a11e8261527 Bjorn Andersson 2017-12-05  66  
9b8a11e8261527 Bjorn Andersson 2017-12-05  67  /**
9b8a11e8261527 Bjorn Andersson 2017-12-05  68   * skip_to_next_elem() - Skip to next element in the structure to be encoded
9b8a11e8261527 Bjorn Andersson 2017-12-05  69   * @ei_array: Struct info describing the element to be skipped.
9b8a11e8261527 Bjorn Andersson 2017-12-05  70   * @level: Depth level of encoding/decoding to identify nested structures.
9b8a11e8261527 Bjorn Andersson 2017-12-05  71   *
9b8a11e8261527 Bjorn Andersson 2017-12-05  72   * This function is used while encoding optional elements. If the flag
9b8a11e8261527 Bjorn Andersson 2017-12-05  73   * corresponding to an optional element is not set, then encoding the
9b8a11e8261527 Bjorn Andersson 2017-12-05  74   * optional element can be skipped. This function can be used to perform
9b8a11e8261527 Bjorn Andersson 2017-12-05  75   * that operation.
9b8a11e8261527 Bjorn Andersson 2017-12-05  76   *
9b8a11e8261527 Bjorn Andersson 2017-12-05  77   * Return: struct info of the next element that can be encoded.
9b8a11e8261527 Bjorn Andersson 2017-12-05  78   */
84f0de3071b40f Jeff Johnson    2022-08-21  79  static struct qmi_elem_info *skip_to_next_elem(const struct qmi_elem_info *ei_array,
9b8a11e8261527 Bjorn Andersson 2017-12-05  80  					       int level)
9b8a11e8261527 Bjorn Andersson 2017-12-05  81  {
84f0de3071b40f Jeff Johnson    2022-08-21  82  	const struct qmi_elem_info *temp_ei = ei_array;
9b8a11e8261527 Bjorn Andersson 2017-12-05  83  	u8 tlv_type;
9b8a11e8261527 Bjorn Andersson 2017-12-05  84  
9b8a11e8261527 Bjorn Andersson 2017-12-05  85  	if (level > 1) {
9b8a11e8261527 Bjorn Andersson 2017-12-05  86  		temp_ei = temp_ei + 1;
9b8a11e8261527 Bjorn Andersson 2017-12-05  87  	} else {
9b8a11e8261527 Bjorn Andersson 2017-12-05  88  		do {
9b8a11e8261527 Bjorn Andersson 2017-12-05  89  			tlv_type = temp_ei->tlv_type;
9b8a11e8261527 Bjorn Andersson 2017-12-05  90  			temp_ei = temp_ei + 1;
9b8a11e8261527 Bjorn Andersson 2017-12-05  91  		} while (tlv_type == temp_ei->tlv_type);
9b8a11e8261527 Bjorn Andersson 2017-12-05  92  	}
9b8a11e8261527 Bjorn Andersson 2017-12-05  93  
9b8a11e8261527 Bjorn Andersson 2017-12-05 @94  	return temp_ei;
9b8a11e8261527 Bjorn Andersson 2017-12-05  95  }
9b8a11e8261527 Bjorn Andersson 2017-12-05  96
kernel test robot Aug. 22, 2022, 2:05 p.m. UTC | #2
Hi Jeff,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc2 next-20220822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jeff-Johnson/soc-qcom-qmi-use-const-for-struct-qmi_elem_info/20220822-144905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1c23f9e627a7b412978b4e852793c5e3c3efc555
config: nios2-randconfig-s051-20220821 (https://download.01.org/0day-ci/archive/20220822/202208222141.fcwTIcFt-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 12.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://github.com/intel-lab-lkp/linux/commit/84f0de3071b40fad5e5a48ad27b16ce28f9210fb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jeff-Johnson/soc-qcom-qmi-use-const-for-struct-qmi_elem_info/20220822-144905
        git checkout 84f0de3071b40fad5e5a48ad27b16ce28f9210fb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=nios2 SHELL=/bin/bash drivers/soc/qcom/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

sparse warnings: (new ones prefixed by >>)
>> drivers/soc/qcom/qmi_encdec.c:94:16: sparse: sparse: incorrect type in return expression (different modifiers) @@     expected struct qmi_elem_info * @@     got struct qmi_elem_info const *[assigned] temp_ei @@
   drivers/soc/qcom/qmi_encdec.c:94:16: sparse:     expected struct qmi_elem_info *
   drivers/soc/qcom/qmi_encdec.c:94:16: sparse:     got struct qmi_elem_info const *[assigned] temp_ei

vim +94 drivers/soc/qcom/qmi_encdec.c

9b8a11e8261527 Bjorn Andersson 2017-12-05  59  
84f0de3071b40f Jeff Johnson    2022-08-21  60  static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
9b8a11e8261527 Bjorn Andersson 2017-12-05  61  		      const void *in_c_struct, u32 out_buf_len,
9b8a11e8261527 Bjorn Andersson 2017-12-05  62  		      int enc_level);
9b8a11e8261527 Bjorn Andersson 2017-12-05  63  
84f0de3071b40f Jeff Johnson    2022-08-21  64  static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
9b8a11e8261527 Bjorn Andersson 2017-12-05  65  		      const void *in_buf, u32 in_buf_len, int dec_level);
9b8a11e8261527 Bjorn Andersson 2017-12-05  66  
9b8a11e8261527 Bjorn Andersson 2017-12-05  67  /**
9b8a11e8261527 Bjorn Andersson 2017-12-05  68   * skip_to_next_elem() - Skip to next element in the structure to be encoded
9b8a11e8261527 Bjorn Andersson 2017-12-05  69   * @ei_array: Struct info describing the element to be skipped.
9b8a11e8261527 Bjorn Andersson 2017-12-05  70   * @level: Depth level of encoding/decoding to identify nested structures.
9b8a11e8261527 Bjorn Andersson 2017-12-05  71   *
9b8a11e8261527 Bjorn Andersson 2017-12-05  72   * This function is used while encoding optional elements. If the flag
9b8a11e8261527 Bjorn Andersson 2017-12-05  73   * corresponding to an optional element is not set, then encoding the
9b8a11e8261527 Bjorn Andersson 2017-12-05  74   * optional element can be skipped. This function can be used to perform
9b8a11e8261527 Bjorn Andersson 2017-12-05  75   * that operation.
9b8a11e8261527 Bjorn Andersson 2017-12-05  76   *
9b8a11e8261527 Bjorn Andersson 2017-12-05  77   * Return: struct info of the next element that can be encoded.
9b8a11e8261527 Bjorn Andersson 2017-12-05  78   */
84f0de3071b40f Jeff Johnson    2022-08-21  79  static struct qmi_elem_info *skip_to_next_elem(const struct qmi_elem_info *ei_array,
9b8a11e8261527 Bjorn Andersson 2017-12-05  80  					       int level)
9b8a11e8261527 Bjorn Andersson 2017-12-05  81  {
84f0de3071b40f Jeff Johnson    2022-08-21  82  	const struct qmi_elem_info *temp_ei = ei_array;
9b8a11e8261527 Bjorn Andersson 2017-12-05  83  	u8 tlv_type;
9b8a11e8261527 Bjorn Andersson 2017-12-05  84  
9b8a11e8261527 Bjorn Andersson 2017-12-05  85  	if (level > 1) {
9b8a11e8261527 Bjorn Andersson 2017-12-05  86  		temp_ei = temp_ei + 1;
9b8a11e8261527 Bjorn Andersson 2017-12-05  87  	} else {
9b8a11e8261527 Bjorn Andersson 2017-12-05  88  		do {
9b8a11e8261527 Bjorn Andersson 2017-12-05  89  			tlv_type = temp_ei->tlv_type;
9b8a11e8261527 Bjorn Andersson 2017-12-05  90  			temp_ei = temp_ei + 1;
9b8a11e8261527 Bjorn Andersson 2017-12-05  91  		} while (tlv_type == temp_ei->tlv_type);
9b8a11e8261527 Bjorn Andersson 2017-12-05  92  	}
9b8a11e8261527 Bjorn Andersson 2017-12-05  93  
9b8a11e8261527 Bjorn Andersson 2017-12-05 @94  	return temp_ei;
9b8a11e8261527 Bjorn Andersson 2017-12-05  95  }
9b8a11e8261527 Bjorn Andersson 2017-12-05  96
kernel test robot Aug. 22, 2022, 2:45 p.m. UTC | #3
Hi Jeff,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc2 next-20220822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jeff-Johnson/soc-qcom-qmi-use-const-for-struct-qmi_elem_info/20220822-144905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1c23f9e627a7b412978b4e852793c5e3c3efc555
config: mips-buildonly-randconfig-r002-20220821 (https://download.01.org/0day-ci/archive/20220822/202208222238.2bPtxE6h-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project abce7acebd4c06c977bc4bd79170697f1122bc5e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/84f0de3071b40fad5e5a48ad27b16ce28f9210fb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jeff-Johnson/soc-qcom-qmi-use-const-for-struct-qmi_elem_info/20220822-144905
        git checkout 84f0de3071b40fad5e5a48ad27b16ce28f9210fb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash drivers/soc/qcom/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/soc/qcom/qmi_encdec.c:94:9: error: returning 'const struct qmi_elem_info *' from a function with result type 'struct qmi_elem_info *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
           return temp_ei;
                  ^~~~~~~
   1 error generated.


vim +94 drivers/soc/qcom/qmi_encdec.c

9b8a11e82615274 Bjorn Andersson 2017-12-05  59  
84f0de3071b40fa Jeff Johnson    2022-08-21  60  static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
9b8a11e82615274 Bjorn Andersson 2017-12-05  61  		      const void *in_c_struct, u32 out_buf_len,
9b8a11e82615274 Bjorn Andersson 2017-12-05  62  		      int enc_level);
9b8a11e82615274 Bjorn Andersson 2017-12-05  63  
84f0de3071b40fa Jeff Johnson    2022-08-21  64  static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
9b8a11e82615274 Bjorn Andersson 2017-12-05  65  		      const void *in_buf, u32 in_buf_len, int dec_level);
9b8a11e82615274 Bjorn Andersson 2017-12-05  66  
9b8a11e82615274 Bjorn Andersson 2017-12-05  67  /**
9b8a11e82615274 Bjorn Andersson 2017-12-05  68   * skip_to_next_elem() - Skip to next element in the structure to be encoded
9b8a11e82615274 Bjorn Andersson 2017-12-05  69   * @ei_array: Struct info describing the element to be skipped.
9b8a11e82615274 Bjorn Andersson 2017-12-05  70   * @level: Depth level of encoding/decoding to identify nested structures.
9b8a11e82615274 Bjorn Andersson 2017-12-05  71   *
9b8a11e82615274 Bjorn Andersson 2017-12-05  72   * This function is used while encoding optional elements. If the flag
9b8a11e82615274 Bjorn Andersson 2017-12-05  73   * corresponding to an optional element is not set, then encoding the
9b8a11e82615274 Bjorn Andersson 2017-12-05  74   * optional element can be skipped. This function can be used to perform
9b8a11e82615274 Bjorn Andersson 2017-12-05  75   * that operation.
9b8a11e82615274 Bjorn Andersson 2017-12-05  76   *
9b8a11e82615274 Bjorn Andersson 2017-12-05  77   * Return: struct info of the next element that can be encoded.
9b8a11e82615274 Bjorn Andersson 2017-12-05  78   */
84f0de3071b40fa Jeff Johnson    2022-08-21  79  static struct qmi_elem_info *skip_to_next_elem(const struct qmi_elem_info *ei_array,
9b8a11e82615274 Bjorn Andersson 2017-12-05  80  					       int level)
9b8a11e82615274 Bjorn Andersson 2017-12-05  81  {
84f0de3071b40fa Jeff Johnson    2022-08-21  82  	const struct qmi_elem_info *temp_ei = ei_array;
9b8a11e82615274 Bjorn Andersson 2017-12-05  83  	u8 tlv_type;
9b8a11e82615274 Bjorn Andersson 2017-12-05  84  
9b8a11e82615274 Bjorn Andersson 2017-12-05  85  	if (level > 1) {
9b8a11e82615274 Bjorn Andersson 2017-12-05  86  		temp_ei = temp_ei + 1;
9b8a11e82615274 Bjorn Andersson 2017-12-05  87  	} else {
9b8a11e82615274 Bjorn Andersson 2017-12-05  88  		do {
9b8a11e82615274 Bjorn Andersson 2017-12-05  89  			tlv_type = temp_ei->tlv_type;
9b8a11e82615274 Bjorn Andersson 2017-12-05  90  			temp_ei = temp_ei + 1;
9b8a11e82615274 Bjorn Andersson 2017-12-05  91  		} while (tlv_type == temp_ei->tlv_type);
9b8a11e82615274 Bjorn Andersson 2017-12-05  92  	}
9b8a11e82615274 Bjorn Andersson 2017-12-05  93  
9b8a11e82615274 Bjorn Andersson 2017-12-05 @94  	return temp_ei;
9b8a11e82615274 Bjorn Andersson 2017-12-05  95  }
9b8a11e82615274 Bjorn Andersson 2017-12-05  96
diff mbox series

Patch

diff --git a/drivers/soc/qcom/qmi_encdec.c b/drivers/soc/qcom/qmi_encdec.c
index 328cc8237191..6144bf6fe1e4 100644
--- a/drivers/soc/qcom/qmi_encdec.c
+++ b/drivers/soc/qcom/qmi_encdec.c
@@ -57,11 +57,11 @@  do { \
 #define TLV_TYPE_SIZE sizeof(u8)
 #define OPTIONAL_TLV_TYPE_START 0x10
 
-static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf,
+static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
 		      const void *in_c_struct, u32 out_buf_len,
 		      int enc_level);
 
-static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
+static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
 		      const void *in_buf, u32 in_buf_len, int dec_level);
 
 /**
@@ -76,10 +76,10 @@  static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
  *
  * Return: struct info of the next element that can be encoded.
  */
-static struct qmi_elem_info *skip_to_next_elem(struct qmi_elem_info *ei_array,
+static struct qmi_elem_info *skip_to_next_elem(const struct qmi_elem_info *ei_array,
 					       int level)
 {
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 	u8 tlv_type;
 
 	if (level > 1) {
@@ -101,11 +101,11 @@  static struct qmi_elem_info *skip_to_next_elem(struct qmi_elem_info *ei_array,
  *
  * Return: Expected minimum length of the QMI message or 0 on error.
  */
-static int qmi_calc_min_msg_len(struct qmi_elem_info *ei_array,
+static int qmi_calc_min_msg_len(const struct qmi_elem_info *ei_array,
 				int level)
 {
 	int min_msg_len = 0;
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 
 	if (!ei_array)
 		return min_msg_len;
@@ -194,13 +194,13 @@  static int qmi_encode_basic_elem(void *buf_dst, const void *buf_src,
  * Return: The number of bytes of encoded information on success or negative
  * errno on error.
  */
-static int qmi_encode_struct_elem(struct qmi_elem_info *ei_array,
+static int qmi_encode_struct_elem(const struct qmi_elem_info *ei_array,
 				  void *buf_dst, const void *buf_src,
 				  u32 elem_len, u32 out_buf_len,
 				  int enc_level)
 {
 	int i, rc, encoded_bytes = 0;
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 
 	for (i = 0; i < elem_len; i++) {
 		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,
  * Return: The number of bytes of encoded information on success or negative
  * errno on error.
  */
-static int qmi_encode_string_elem(struct qmi_elem_info *ei_array,
+static int qmi_encode_string_elem(const struct qmi_elem_info *ei_array,
 				  void *buf_dst, const void *buf_src,
 				  u32 out_buf_len, int enc_level)
 {
 	int rc;
 	int encoded_bytes = 0;
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 	u32 string_len = 0;
 	u32 string_len_sz = 0;
 
@@ -289,11 +289,11 @@  static int qmi_encode_string_elem(struct qmi_elem_info *ei_array,
  * Return: The number of bytes of encoded information on success or negative
  * errno on error.
  */
-static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf,
+static int qmi_encode(const struct qmi_elem_info *ei_array, void *out_buf,
 		      const void *in_c_struct, u32 out_buf_len,
 		      int enc_level)
 {
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 	u8 opt_flag_value = 0;
 	u32 data_len_value = 0, data_len_sz;
 	u8 *buf_dst = (u8 *)out_buf;
@@ -468,13 +468,13 @@  static int qmi_decode_basic_elem(void *buf_dst, const void *buf_src,
  * Return: The total size of the decoded data elements on success, negative
  * errno on error.
  */
-static int qmi_decode_struct_elem(struct qmi_elem_info *ei_array,
+static int qmi_decode_struct_elem(const struct qmi_elem_info *ei_array,
 				  void *buf_dst, const void *buf_src,
 				  u32 elem_len, u32 tlv_len,
 				  int dec_level)
 {
 	int i, rc, decoded_bytes = 0;
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 
 	for (i = 0; i < elem_len && decoded_bytes < tlv_len; i++) {
 		rc = qmi_decode(temp_ei->ei_array, buf_dst, buf_src,
@@ -514,7 +514,7 @@  static int qmi_decode_struct_elem(struct qmi_elem_info *ei_array,
  * Return: The total size of the decoded data elements on success, negative
  * errno on error.
  */
-static int qmi_decode_string_elem(struct qmi_elem_info *ei_array,
+static int qmi_decode_string_elem(const struct qmi_elem_info *ei_array,
 				  void *buf_dst, const void *buf_src,
 				  u32 tlv_len, int dec_level)
 {
@@ -522,7 +522,7 @@  static int qmi_decode_string_elem(struct qmi_elem_info *ei_array,
 	int decoded_bytes = 0;
 	u32 string_len = 0;
 	u32 string_len_sz = 0;
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 
 	if (dec_level == 1) {
 		string_len = tlv_len;
@@ -564,10 +564,10 @@  static int qmi_decode_string_elem(struct qmi_elem_info *ei_array,
  *
  * Return: Pointer to struct info, if found
  */
-static struct qmi_elem_info *find_ei(struct qmi_elem_info *ei_array,
-				     u32 type)
+static const struct qmi_elem_info *find_ei(const struct qmi_elem_info *ei_array,
+					   u32 type)
 {
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 
 	while (temp_ei->data_type != QMI_EOTI) {
 		if (temp_ei->tlv_type == (u8)type)
@@ -590,11 +590,11 @@  static struct qmi_elem_info *find_ei(struct qmi_elem_info *ei_array,
  * Return: The number of bytes of decoded information on success, negative
  * errno on error.
  */
-static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
+static int qmi_decode(const struct qmi_elem_info *ei_array, void *out_c_struct,
 		      const void *in_buf, u32 in_buf_len,
 		      int dec_level)
 {
-	struct qmi_elem_info *temp_ei = ei_array;
+	const struct qmi_elem_info *temp_ei = ei_array;
 	u8 opt_flag_value = 1;
 	u32 data_len_value = 0, data_len_sz = 0;
 	u8 *buf_dst = out_c_struct;
@@ -713,7 +713,7 @@  static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
  * Return: Buffer with encoded message, or negative ERR_PTR() on error
  */
 void *qmi_encode_message(int type, unsigned int msg_id, size_t *len,
-			 unsigned int txn_id, struct qmi_elem_info *ei,
+			 unsigned int txn_id, const struct qmi_elem_info *ei,
 			 const void *c_struct)
 {
 	struct qmi_header *hdr;
@@ -767,7 +767,7 @@  EXPORT_SYMBOL(qmi_encode_message);
  * errno on error.
  */
 int qmi_decode_message(const void *buf, size_t len,
-		       struct qmi_elem_info *ei, void *c_struct)
+		       const struct qmi_elem_info *ei, void *c_struct)
 {
 	if (!ei)
 		return -EINVAL;
@@ -781,7 +781,7 @@  int qmi_decode_message(const void *buf, size_t len,
 EXPORT_SYMBOL(qmi_decode_message);
 
 /* Common header in all QMI responses */
-struct qmi_elem_info qmi_response_type_v01_ei[] = {
+const struct qmi_elem_info qmi_response_type_v01_ei[] = {
 	{
 		.data_type	= QMI_SIGNED_2_BYTE_ENUM,
 		.elem_len	= 1,
diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c
index c8c4c730b135..57052726299d 100644
--- a/drivers/soc/qcom/qmi_interface.c
+++ b/drivers/soc/qcom/qmi_interface.c
@@ -305,7 +305,7 @@  EXPORT_SYMBOL(qmi_add_server);
  * Return: Transaction id on success, negative errno on failure.
  */
 int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
-		 struct qmi_elem_info *ei, void *c_struct)
+		 const struct qmi_elem_info *ei, void *c_struct)
 {
 	int ret;
 
@@ -736,7 +736,8 @@  EXPORT_SYMBOL(qmi_handle_release);
 static ssize_t qmi_send_message(struct qmi_handle *qmi,
 				struct sockaddr_qrtr *sq, struct qmi_txn *txn,
 				int type, int msg_id, size_t len,
-				struct qmi_elem_info *ei, const void *c_struct)
+				const struct qmi_elem_info *ei,
+				const void *c_struct)
 {
 	struct msghdr msghdr = {};
 	struct kvec iv;
@@ -787,7 +788,7 @@  static ssize_t qmi_send_message(struct qmi_handle *qmi,
  */
 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
 			 struct qmi_txn *txn, int msg_id, size_t len,
-			 struct qmi_elem_info *ei, const void *c_struct)
+			 const struct qmi_elem_info *ei, const void *c_struct)
 {
 	return qmi_send_message(qmi, sq, txn, QMI_REQUEST, msg_id, len, ei,
 				c_struct);
@@ -808,7 +809,7 @@  EXPORT_SYMBOL(qmi_send_request);
  */
 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
 			  struct qmi_txn *txn, int msg_id, size_t len,
-			  struct qmi_elem_info *ei, const void *c_struct)
+			  const struct qmi_elem_info *ei, const void *c_struct)
 {
 	return qmi_send_message(qmi, sq, txn, QMI_RESPONSE, msg_id, len, ei,
 				c_struct);
@@ -827,7 +828,8 @@  EXPORT_SYMBOL(qmi_send_response);
  * Return: 0 on success, negative errno on failure.
  */
 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
-			    int msg_id, size_t len, struct qmi_elem_info *ei,
+			    int msg_id, size_t len,
+			    const struct qmi_elem_info *ei,
 			    const void *c_struct)
 {
 	struct qmi_txn txn;
diff --git a/include/linux/soc/qcom/qmi.h b/include/linux/soc/qcom/qmi.h
index b1f80e756d2a..469e02d2aa0d 100644
--- a/include/linux/soc/qcom/qmi.h
+++ b/include/linux/soc/qcom/qmi.h
@@ -75,7 +75,7 @@  struct qmi_elem_info {
 	enum qmi_array_type array_type;
 	u8 tlv_type;
 	u32 offset;
-	struct qmi_elem_info *ei_array;
+	const struct qmi_elem_info *ei_array;
 };
 
 #define QMI_RESULT_SUCCESS_V01			0
@@ -102,7 +102,7 @@  struct qmi_response_type_v01 {
 	u16 error;
 };
 
-extern struct qmi_elem_info qmi_response_type_v01_ei[];
+extern const struct qmi_elem_info qmi_response_type_v01_ei[];
 
 /**
  * struct qmi_service - context to track lookup-results
@@ -173,7 +173,7 @@  struct qmi_txn {
 	struct completion completion;
 	int result;
 
-	struct qmi_elem_info *ei;
+	const struct qmi_elem_info *ei;
 	void *dest;
 };
 
@@ -189,7 +189,7 @@  struct qmi_msg_handler {
 	unsigned int type;
 	unsigned int msg_id;
 
-	struct qmi_elem_info *ei;
+	const struct qmi_elem_info *ei;
 
 	size_t decoded_size;
 	void (*fn)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
@@ -249,23 +249,23 @@  void qmi_handle_release(struct qmi_handle *qmi);
 
 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
 			 struct qmi_txn *txn, int msg_id, size_t len,
-			 struct qmi_elem_info *ei, const void *c_struct);
+			 const struct qmi_elem_info *ei, const void *c_struct);
 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
 			  struct qmi_txn *txn, int msg_id, size_t len,
-			  struct qmi_elem_info *ei, const void *c_struct);
+			  const struct qmi_elem_info *ei, const void *c_struct);
 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
-			    int msg_id, size_t len, struct qmi_elem_info *ei,
+			    int msg_id, size_t len, const struct qmi_elem_info *ei,
 			    const void *c_struct);
 
 void *qmi_encode_message(int type, unsigned int msg_id, size_t *len,
-			 unsigned int txn_id, struct qmi_elem_info *ei,
+			 unsigned int txn_id, const struct qmi_elem_info *ei,
 			 const void *c_struct);
 
 int qmi_decode_message(const void *buf, size_t len,
-		       struct qmi_elem_info *ei, void *c_struct);
+		       const struct qmi_elem_info *ei, void *c_struct);
 
 int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
-		 struct qmi_elem_info *ei, void *c_struct);
+		 const struct qmi_elem_info *ei, void *c_struct);
 int qmi_txn_wait(struct qmi_txn *txn, unsigned long timeout);
 void qmi_txn_cancel(struct qmi_txn *txn);
 
diff --git a/samples/qmi/qmi_sample_client.c b/samples/qmi/qmi_sample_client.c
index 78fcedbd25e2..c045e3d24326 100644
--- a/samples/qmi/qmi_sample_client.c
+++ b/samples/qmi/qmi_sample_client.c
@@ -42,7 +42,7 @@  struct test_name_type_v01 {
 	char name[TEST_MAX_NAME_SIZE_V01];
 };
 
-static struct qmi_elem_info test_name_type_v01_ei[] = {
+static const struct qmi_elem_info test_name_type_v01_ei[] = {
 	{
 		.data_type	= QMI_DATA_LEN,
 		.elem_len	= 1,
@@ -71,7 +71,7 @@  struct test_ping_req_msg_v01 {
 	struct test_name_type_v01 client_name;
 };
 
-static struct qmi_elem_info test_ping_req_msg_v01_ei[] = {
+static const struct qmi_elem_info test_ping_req_msg_v01_ei[] = {
 	{
 		.data_type	= QMI_UNSIGNED_1_BYTE,
 		.elem_len	= 4,
@@ -113,7 +113,7 @@  struct test_ping_resp_msg_v01 {
 	struct test_name_type_v01 service_name;
 };
 
-static struct qmi_elem_info test_ping_resp_msg_v01_ei[] = {
+static const struct qmi_elem_info test_ping_resp_msg_v01_ei[] = {
 	{
 		.data_type	= QMI_STRUCT,
 		.elem_len	= 1,
@@ -172,7 +172,7 @@  struct test_data_req_msg_v01 {
 	struct test_name_type_v01 client_name;
 };
 
-static struct qmi_elem_info test_data_req_msg_v01_ei[] = {
+static const struct qmi_elem_info test_data_req_msg_v01_ei[] = {
 	{
 		.data_type	= QMI_DATA_LEN,
 		.elem_len	= 1,
@@ -224,7 +224,7 @@  struct test_data_resp_msg_v01 {
 	struct test_name_type_v01 service_name;
 };
 
-static struct qmi_elem_info test_data_resp_msg_v01_ei[] = {
+static const struct qmi_elem_info test_data_resp_msg_v01_ei[] = {
 	{
 		.data_type	= QMI_STRUCT,
 		.elem_len	= 1,