drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/qcom/linux [email protected] head: 5c720260e840b508053dd5338577e0175ef31739 commit: 8b9d2050cfa0c22c05622df103e366933fc045ed [11/13] firmware: qcom_scm: Add qcom_scm_pas_get_rsc_table() to get resource table config: powerpc-randconfig-r061-20260114 (https://download.01.org/0day-ci/archive/20260114/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
cocci warnings: (new ones prefixed by >>)
>> drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup
vim +916 drivers/firmware/qcom/qcom_scm.c
823
824 /**
825 * qcom_scm_pas_get_rsc_table() - Retrieve the resource table in passed output buffer
826 * for a given peripheral.
827 *
828 * Qualcomm remote processor may rely on both static and dynamic resources for
829 * its functionality. Static resources typically refer to memory-mapped addresses
830 * required by the subsystem and are often embedded within the firmware binary
831 * and dynamic resources, such as shared memory in DDR etc., are determined at
832 * runtime during the boot process.
833 *
834 * On Qualcomm Technologies devices, it's possible that static resources are not
835 * embedded in the firmware binary and instead are provided by TrustZone However,
836 * dynamic resources are always expected to come from TrustZone. This indicates
837 * that for Qualcomm devices, all resources (static and dynamic) will be provided
838 * by TrustZone via the SMC call.
839 *
840 * If the remote processor firmware binary does contain static resources, they
841 * should be passed in input_rt. These will be forwarded to TrustZone for
842 * authentication. TrustZone will then append the dynamic resources and return
843 * the complete resource table in output_rt_tzm.
844 *
845 * If the remote processor firmware binary does not include a resource table,
846 * the caller of this function should set input_rt as NULL and input_rt_size
847 * as zero respectively.
848 *
849 * More about documentation on resource table data structures can be found in
850 * include/linux/remoteproc.h
851 *
852 * @ctx: PAS context
853 * @pas_id: peripheral authentication service id
854 * @input_rt: resource table buffer which is present in firmware binary
855 * @input_rt_size: size of the resource table present in firmware binary
856 * @output_rt_size: TrustZone expects caller should pass worst case size for
857 * the output_rt_tzm.
858 *
859 * Return:
860 * On success, returns a pointer to the allocated buffer containing the final
861 * resource table and output_rt_size will have actual resource table size from
862 * TrustZone. The caller is responsible for freeing the buffer. On failure,
863 * returns ERR_PTR(-errno).
864 */
865 struct resource_table *qcom_scm_pas_get_rsc_table(struct qcom_scm_pas_context *ctx,
866 void *input_rt,
867 size_t input_rt_size,
868 size_t *output_rt_size)
869 {
870 struct resource_table empty_rsc = {};
871 size_t size = SZ_16K;
872 void *output_rt_tzm;
873 void *input_rt_tzm;
874 void *tbl_ptr;
875 int ret;
876
877 ret = qcom_scm_clk_enable();
878 if (ret)
879 return ERR_PTR(ret);
880
881 ret = qcom_scm_bw_enable();
882 if (ret)
883 goto disable_clk;
884
885 /*
886 * TrustZone can not accept buffer as NULL value as argument hence,
887 * we need to pass a input buffer indicating that subsystem firmware
888 * does not have resource table by filling resource table structure.
889 */
890 if (!input_rt) {
891 input_rt = &empty_rsc;
892 input_rt_size = sizeof(empty_rsc);
893 }
894
895 input_rt_tzm = qcom_tzmem_alloc(__scm->mempool, input_rt_size, GFP_KERNEL);
896 if (!input_rt_tzm) {
897 ret = -ENOMEM;
898 goto disable_scm_bw;
899 }
900
901 memcpy(input_rt_tzm, input_rt, input_rt_size);
902
903 output_rt_tzm = __qcom_scm_pas_get_rsc_table(ctx->pas_id, input_rt_tzm,
904 input_rt_size, &size);
905 if (PTR_ERR(output_rt_tzm) == -EOVERFLOW)
906 /* Try again with the size requested by the TZ */
907 output_rt_tzm = __qcom_scm_pas_get_rsc_table(ctx->pas_id,
908 input_rt_tzm,
909 input_rt_size,
910 &size);
911 if (IS_ERR(output_rt_tzm)) {
912 ret = PTR_ERR(output_rt_tzm);
913 goto free_input_rt;
914 }
915
> 916 tbl_ptr = kzalloc(size, GFP_KERNEL); 917 if (!tbl_ptr) {
918 qcom_tzmem_free(output_rt_tzm);
919 ret = -ENOMEM;
920 goto free_input_rt;
921 }
922
923 memcpy(tbl_ptr, output_rt_tzm, size);
924 *output_rt_size = size;
925 qcom_tzmem_free(output_rt_tzm);
926
927 free_input_rt:
928 qcom_tzmem_free(input_rt_tzm);
929
930 disable_scm_bw:
931 qcom_scm_bw_disable();
932
933 disable_clk:
934 qcom_scm_clk_disable();
935
936 return ret ? ERR_PTR(ret) : tbl_ptr;
937 }
938 EXPORT_SYMBOL_GPL(qcom_scm_pas_get_rsc_table);
939
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki