[linux-next:master 4321/9096] drivers/scsi/mpi3mr/mpi3mr_app.c:1096:14-15: WARNING opportunity for min() (fwd)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just a suggestion.  Maybe the code seems more readable as is.

thanks,
julia

---------- Forwarded message ----------
Date: Wed, 20 Dec 2023 15:39:28 +0800
From: kernel test robot <lkp@xxxxxxxxx>
To: oe-kbuild@xxxxxxxxxxxxxxx
Cc: lkp@xxxxxxxxx, Julia Lawall <julia.lawall@xxxxxxxx>
Subject: [linux-next:master 4321/9096]
    drivers/scsi/mpi3mr/mpi3mr_app.c:1096:14-15: WARNING opportunity for min()

BCC: lkp@xxxxxxxxx
CC: oe-kbuild-all@xxxxxxxxxxxxxxx
CC: Linux Memory Management List <linux-mm@xxxxxxxxx>
TO: Chandrakanth patil <chandrakanth.patil@xxxxxxxxxxxx>
CC: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
CC: Sathya Prakash <sathya.prakash@xxxxxxxxxxxx>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   aa4db8324c4d0e67aa4670356df4e9fae14b4d37
commit: fb231d7deffb41fd445929a3b79815277b883fec [4321/9096] scsi: mpi3mr: Support for preallocation of SGL BSG data buffers part-2
:::::: branch date: 27 hours ago
:::::: commit date: 2 weeks ago
config: i386-randconfig-051-20231220 (https://download.01.org/0day-ci/archive/20231220/202312201503.1ZYNkA6N-lkp@xxxxxxxxx/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0

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 <lkp@xxxxxxxxx>
| Reported-by: Julia Lawall <julia.lawall@xxxxxxxx>
| Closes: https://lore.kernel.org/r/202312201503.1ZYNkA6N-lkp@xxxxxxxxx/

cocci warnings: (new ones prefixed by >>)
>> drivers/scsi/mpi3mr/mpi3mr_app.c:1096:14-15: WARNING opportunity for min()

vim +1096 drivers/scsi/mpi3mr/mpi3mr_app.c

fb231d7deffb41 Chandrakanth patil 2023-12-06  1057
fb231d7deffb41 Chandrakanth patil 2023-12-06  1058  /**
fb231d7deffb41 Chandrakanth patil 2023-12-06  1059   * mpi3mr_map_data_buffer_dma - build dma descriptors for data
fb231d7deffb41 Chandrakanth patil 2023-12-06  1060   *                              buffers
fb231d7deffb41 Chandrakanth patil 2023-12-06  1061   * @mrioc: Adapter instance reference
fb231d7deffb41 Chandrakanth patil 2023-12-06  1062   * @drv_buf: buffer map descriptor
fb231d7deffb41 Chandrakanth patil 2023-12-06  1063   * @desc_count: Number of already consumed dma descriptors
fb231d7deffb41 Chandrakanth patil 2023-12-06  1064   *
fb231d7deffb41 Chandrakanth patil 2023-12-06  1065   * This function computes how many pre-allocated DMA descriptors
fb231d7deffb41 Chandrakanth patil 2023-12-06  1066   * are required for the given data buffer and if those number of
fb231d7deffb41 Chandrakanth patil 2023-12-06  1067   * descriptors are free, then setup the mapping of the scattered
fb231d7deffb41 Chandrakanth patil 2023-12-06  1068   * DMA address to the given data buffer, if the data direction
fb231d7deffb41 Chandrakanth patil 2023-12-06  1069   * of the buffer is DMA_TO_DEVICE then the actual data is copied to
fb231d7deffb41 Chandrakanth patil 2023-12-06  1070   * the DMA buffers
fb231d7deffb41 Chandrakanth patil 2023-12-06  1071   *
fb231d7deffb41 Chandrakanth patil 2023-12-06  1072   * Return: 0 on success, -1 on failure
fb231d7deffb41 Chandrakanth patil 2023-12-06  1073   */
fb231d7deffb41 Chandrakanth patil 2023-12-06  1074  static int mpi3mr_map_data_buffer_dma(struct mpi3mr_ioc *mrioc,
fb231d7deffb41 Chandrakanth patil 2023-12-06  1075  				      struct mpi3mr_buf_map *drv_buf,
fb231d7deffb41 Chandrakanth patil 2023-12-06  1076  				      u16 desc_count)
fb231d7deffb41 Chandrakanth patil 2023-12-06  1077  {
fb231d7deffb41 Chandrakanth patil 2023-12-06  1078  	u16 i, needed_desc = drv_buf->kern_buf_len / MPI3MR_IOCTL_SGE_SIZE;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1079  	u32 buf_len = drv_buf->kern_buf_len, copied_len = 0;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1080
fb231d7deffb41 Chandrakanth patil 2023-12-06  1081  	if (drv_buf->kern_buf_len % MPI3MR_IOCTL_SGE_SIZE)
fb231d7deffb41 Chandrakanth patil 2023-12-06  1082  		needed_desc++;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1083  	if ((needed_desc + desc_count) > MPI3MR_NUM_IOCTL_SGE) {
fb231d7deffb41 Chandrakanth patil 2023-12-06  1084  		dprint_bsg_err(mrioc, "%s: DMA descriptor mapping error %d:%d:%d\n",
fb231d7deffb41 Chandrakanth patil 2023-12-06  1085  			       __func__, needed_desc, desc_count, MPI3MR_NUM_IOCTL_SGE);
fb231d7deffb41 Chandrakanth patil 2023-12-06  1086  		return -1;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1087  	}
fb231d7deffb41 Chandrakanth patil 2023-12-06  1088  	drv_buf->dma_desc = kzalloc(sizeof(*drv_buf->dma_desc) * needed_desc,
fb231d7deffb41 Chandrakanth patil 2023-12-06  1089  				    GFP_KERNEL);
fb231d7deffb41 Chandrakanth patil 2023-12-06  1090  	if (!drv_buf->dma_desc)
fb231d7deffb41 Chandrakanth patil 2023-12-06  1091  		return -1;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1092  	for (i = 0; i < needed_desc; i++, desc_count++) {
fb231d7deffb41 Chandrakanth patil 2023-12-06  1093  		drv_buf->dma_desc[i].addr = mrioc->ioctl_sge[desc_count].addr;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1094  		drv_buf->dma_desc[i].dma_addr =
fb231d7deffb41 Chandrakanth patil 2023-12-06  1095  		    mrioc->ioctl_sge[desc_count].dma_addr;
fb231d7deffb41 Chandrakanth patil 2023-12-06 @1096  		if (buf_len < mrioc->ioctl_sge[desc_count].size)
fb231d7deffb41 Chandrakanth patil 2023-12-06  1097  			drv_buf->dma_desc[i].size = buf_len;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1098  		else
fb231d7deffb41 Chandrakanth patil 2023-12-06  1099  			drv_buf->dma_desc[i].size =
fb231d7deffb41 Chandrakanth patil 2023-12-06  1100  			    mrioc->ioctl_sge[desc_count].size;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1101  		buf_len -= drv_buf->dma_desc[i].size;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1102  		memset(drv_buf->dma_desc[i].addr, 0,
fb231d7deffb41 Chandrakanth patil 2023-12-06  1103  		       mrioc->ioctl_sge[desc_count].size);
fb231d7deffb41 Chandrakanth patil 2023-12-06  1104  		if (drv_buf->data_dir == DMA_TO_DEVICE) {
fb231d7deffb41 Chandrakanth patil 2023-12-06  1105  			memcpy(drv_buf->dma_desc[i].addr,
fb231d7deffb41 Chandrakanth patil 2023-12-06  1106  			       drv_buf->bsg_buf + copied_len,
fb231d7deffb41 Chandrakanth patil 2023-12-06  1107  			       drv_buf->dma_desc[i].size);
fb231d7deffb41 Chandrakanth patil 2023-12-06  1108  			copied_len += drv_buf->dma_desc[i].size;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1109  		}
fb231d7deffb41 Chandrakanth patil 2023-12-06  1110  	}
fb231d7deffb41 Chandrakanth patil 2023-12-06  1111  	drv_buf->num_dma_desc = needed_desc;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1112  	return 0;
fb231d7deffb41 Chandrakanth patil 2023-12-06  1113  }
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1114  /**
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1115   * mpi3mr_bsg_process_mpt_cmds - MPI Pass through BSG handler
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1116   * @job: BSG job reference
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1117   *
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1118   * This function is the top level handler for MPI Pass through
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1119   * command, this does basic validation of the input data buffers,
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1120   * identifies the given buffer types and MPI command, allocates
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1121   * DMAable memory for user given buffers, construstcs SGL
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1122   * properly and passes the command to the firmware.
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1123   *
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1124   * Once the MPI command is completed the driver copies the data
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1125   * if any and reply, sense information to user provided buffers.
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1126   * If the command is timed out then issues controller reset
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1127   * prior to returning.
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1128   *
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1129   * Return: 0 on success and proper error codes on failure
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1130   */
506bc1a0d6ba62 Sumit Saxena       2022-04-29  1131

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux