diff mbox series

[v3,1/5] scsi: mpi3mr: remove unnecessary memcpy

Message ID 20230110015538.201332-2-shinichiro.kawasaki@wdc.com (mailing list archive)
State Superseded
Headers show
Series scsi: mpi3mr: fix issues found by KASAN | expand

Commit Message

Shin'ichiro Kawasaki Jan. 10, 2023, 1:55 a.m. UTC
In the function mpi3mr_get_all_tgt_info, devmap_info points to
alltgt_info->dmi then there is no need to memcpy data from devmap_info
to alltgt_info->dmi. Remove the unnecessary memcpy. This also allows to
remove the local variable 'rval' and the goto label 'out'.

Fixes: f5e6d5a34376 ("scsi: mpi3mr: Add support for driver commands")
Cc: stable@vger.kernel.org
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 drivers/scsi/mpi3mr/mpi3mr_app.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

kernel test robot Jan. 10, 2023, 4:27 a.m. UTC | #1
Hi Shin'ichiro,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on jejb-scsi/for-next]
[also build test WARNING on mkp-scsi/for-next linus/master v6.2-rc3 next-20230109]
[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/Shin-ichiro-Kawasaki/scsi-mpi3mr-remove-unnecessary-memcpy/20230110-095717
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
patch link:    https://lore.kernel.org/r/20230110015538.201332-2-shinichiro.kawasaki%40wdc.com
patch subject: [PATCH v3 1/5] scsi: mpi3mr: remove unnecessary memcpy
config: ia64-allyesconfig
compiler: ia64-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/fad43146fb864da8124537dd3a548f9c638cddd6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Shin-ichiro-Kawasaki/scsi-mpi3mr-remove-unnecessary-memcpy/20230110-095717
        git checkout fad43146fb864da8124537dd3a548f9c638cddd6
        # 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=ia64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/scsi/mpi3mr/

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/scsi/mpi3mr/mpi3mr_app.c: In function 'mpi3mr_get_all_tgt_info':
>> drivers/scsi/mpi3mr/mpi3mr_app.c:301:18: warning: variable 'min_entrylen' set but not used [-Wunused-but-set-variable]
     301 |         uint32_t min_entrylen = 0, kern_entrylen = 0, usr_entrylen = 0;
         |                  ^~~~~~~~~~~~


vim +/min_entrylen +301 drivers/scsi/mpi3mr/mpi3mr_app.c

f5e6d5a3437610 Sumit Saxena         2022-04-29  198  
43ca110050988c Sumit Saxena         2022-04-29  199  /**
43ca110050988c Sumit Saxena         2022-04-29  200   * mpi3mr_bsg_pel_enable - Handler for PEL enable driver
43ca110050988c Sumit Saxena         2022-04-29  201   * @mrioc: Adapter instance reference
43ca110050988c Sumit Saxena         2022-04-29  202   * @job: BSG job pointer
43ca110050988c Sumit Saxena         2022-04-29  203   *
43ca110050988c Sumit Saxena         2022-04-29  204   * This function is the handler for PEL enable driver.
43ca110050988c Sumit Saxena         2022-04-29  205   * Validates the application given class and locale and if
43ca110050988c Sumit Saxena         2022-04-29  206   * requires aborts the existing PEL wait request and/or issues
43ca110050988c Sumit Saxena         2022-04-29  207   * new PEL wait request to the firmware and returns.
43ca110050988c Sumit Saxena         2022-04-29  208   *
43ca110050988c Sumit Saxena         2022-04-29  209   * Return: 0 on success and proper error codes on failure.
43ca110050988c Sumit Saxena         2022-04-29  210   */
43ca110050988c Sumit Saxena         2022-04-29  211  static long mpi3mr_bsg_pel_enable(struct mpi3mr_ioc *mrioc,
43ca110050988c Sumit Saxena         2022-04-29  212  				  struct bsg_job *job)
43ca110050988c Sumit Saxena         2022-04-29  213  {
43ca110050988c Sumit Saxena         2022-04-29  214  	long rval = -EINVAL;
43ca110050988c Sumit Saxena         2022-04-29  215  	struct mpi3mr_bsg_out_pel_enable pel_enable;
43ca110050988c Sumit Saxena         2022-04-29  216  	u8 issue_pel_wait;
43ca110050988c Sumit Saxena         2022-04-29  217  	u8 tmp_class;
43ca110050988c Sumit Saxena         2022-04-29  218  	u16 tmp_locale;
43ca110050988c Sumit Saxena         2022-04-29  219  
43ca110050988c Sumit Saxena         2022-04-29  220  	if (job->request_payload.payload_len != sizeof(pel_enable)) {
43ca110050988c Sumit Saxena         2022-04-29  221  		dprint_bsg_err(mrioc, "%s: invalid size argument\n",
43ca110050988c Sumit Saxena         2022-04-29  222  		    __func__);
43ca110050988c Sumit Saxena         2022-04-29  223  		return rval;
43ca110050988c Sumit Saxena         2022-04-29  224  	}
43ca110050988c Sumit Saxena         2022-04-29  225  
43ca110050988c Sumit Saxena         2022-04-29  226  	sg_copy_to_buffer(job->request_payload.sg_list,
43ca110050988c Sumit Saxena         2022-04-29  227  			  job->request_payload.sg_cnt,
43ca110050988c Sumit Saxena         2022-04-29  228  			  &pel_enable, sizeof(pel_enable));
43ca110050988c Sumit Saxena         2022-04-29  229  
43ca110050988c Sumit Saxena         2022-04-29  230  	if (pel_enable.pel_class > MPI3_PEL_CLASS_FAULT) {
43ca110050988c Sumit Saxena         2022-04-29  231  		dprint_bsg_err(mrioc, "%s: out of range class %d sent\n",
43ca110050988c Sumit Saxena         2022-04-29  232  			__func__, pel_enable.pel_class);
43ca110050988c Sumit Saxena         2022-04-29  233  		rval = 0;
43ca110050988c Sumit Saxena         2022-04-29  234  		goto out;
43ca110050988c Sumit Saxena         2022-04-29  235  	}
43ca110050988c Sumit Saxena         2022-04-29  236  	if (!mrioc->pel_enabled)
43ca110050988c Sumit Saxena         2022-04-29  237  		issue_pel_wait = 1;
43ca110050988c Sumit Saxena         2022-04-29  238  	else {
43ca110050988c Sumit Saxena         2022-04-29  239  		if ((mrioc->pel_class <= pel_enable.pel_class) &&
43ca110050988c Sumit Saxena         2022-04-29  240  		    !((mrioc->pel_locale & pel_enable.pel_locale) ^
43ca110050988c Sumit Saxena         2022-04-29  241  		      pel_enable.pel_locale)) {
43ca110050988c Sumit Saxena         2022-04-29  242  			issue_pel_wait = 0;
43ca110050988c Sumit Saxena         2022-04-29  243  			rval = 0;
43ca110050988c Sumit Saxena         2022-04-29  244  		} else {
43ca110050988c Sumit Saxena         2022-04-29  245  			pel_enable.pel_locale |= mrioc->pel_locale;
43ca110050988c Sumit Saxena         2022-04-29  246  
43ca110050988c Sumit Saxena         2022-04-29  247  			if (mrioc->pel_class < pel_enable.pel_class)
43ca110050988c Sumit Saxena         2022-04-29  248  				pel_enable.pel_class = mrioc->pel_class;
43ca110050988c Sumit Saxena         2022-04-29  249  
43ca110050988c Sumit Saxena         2022-04-29  250  			rval = mpi3mr_bsg_pel_abort(mrioc);
43ca110050988c Sumit Saxena         2022-04-29  251  			if (rval) {
43ca110050988c Sumit Saxena         2022-04-29  252  				dprint_bsg_err(mrioc,
43ca110050988c Sumit Saxena         2022-04-29  253  				    "%s: pel_abort failed, status(%ld)\n",
43ca110050988c Sumit Saxena         2022-04-29  254  				    __func__, rval);
43ca110050988c Sumit Saxena         2022-04-29  255  				goto out;
43ca110050988c Sumit Saxena         2022-04-29  256  			}
43ca110050988c Sumit Saxena         2022-04-29  257  			issue_pel_wait = 1;
43ca110050988c Sumit Saxena         2022-04-29  258  		}
43ca110050988c Sumit Saxena         2022-04-29  259  	}
43ca110050988c Sumit Saxena         2022-04-29  260  	if (issue_pel_wait) {
43ca110050988c Sumit Saxena         2022-04-29  261  		tmp_class = mrioc->pel_class;
43ca110050988c Sumit Saxena         2022-04-29  262  		tmp_locale = mrioc->pel_locale;
43ca110050988c Sumit Saxena         2022-04-29  263  		mrioc->pel_class = pel_enable.pel_class;
43ca110050988c Sumit Saxena         2022-04-29  264  		mrioc->pel_locale = pel_enable.pel_locale;
43ca110050988c Sumit Saxena         2022-04-29  265  		mrioc->pel_enabled = 1;
43ca110050988c Sumit Saxena         2022-04-29  266  		rval = mpi3mr_pel_get_seqnum_post(mrioc, NULL);
43ca110050988c Sumit Saxena         2022-04-29  267  		if (rval) {
43ca110050988c Sumit Saxena         2022-04-29  268  			mrioc->pel_class = tmp_class;
43ca110050988c Sumit Saxena         2022-04-29  269  			mrioc->pel_locale = tmp_locale;
43ca110050988c Sumit Saxena         2022-04-29  270  			mrioc->pel_enabled = 0;
43ca110050988c Sumit Saxena         2022-04-29  271  			dprint_bsg_err(mrioc,
43ca110050988c Sumit Saxena         2022-04-29  272  			    "%s: pel get sequence number failed, status(%ld)\n",
43ca110050988c Sumit Saxena         2022-04-29  273  			    __func__, rval);
43ca110050988c Sumit Saxena         2022-04-29  274  		}
43ca110050988c Sumit Saxena         2022-04-29  275  	}
43ca110050988c Sumit Saxena         2022-04-29  276  
43ca110050988c Sumit Saxena         2022-04-29  277  out:
43ca110050988c Sumit Saxena         2022-04-29  278  	return rval;
43ca110050988c Sumit Saxena         2022-04-29  279  }
f5e6d5a3437610 Sumit Saxena         2022-04-29  280  /**
f5e6d5a3437610 Sumit Saxena         2022-04-29  281   * mpi3mr_get_all_tgt_info - Get all target information
f5e6d5a3437610 Sumit Saxena         2022-04-29  282   * @mrioc: Adapter instance reference
f5e6d5a3437610 Sumit Saxena         2022-04-29  283   * @job: BSG job reference
f5e6d5a3437610 Sumit Saxena         2022-04-29  284   *
f5e6d5a3437610 Sumit Saxena         2022-04-29  285   * This function copies the driver managed target devices device
f5e6d5a3437610 Sumit Saxena         2022-04-29  286   * handle, persistent ID, bus ID and taret ID to the user
f5e6d5a3437610 Sumit Saxena         2022-04-29  287   * provided buffer for the specific controller. This function
f5e6d5a3437610 Sumit Saxena         2022-04-29  288   * also provides the number of devices managed by the driver for
f5e6d5a3437610 Sumit Saxena         2022-04-29  289   * the specific controller.
f5e6d5a3437610 Sumit Saxena         2022-04-29  290   *
f5e6d5a3437610 Sumit Saxena         2022-04-29  291   * Return: 0 on success and proper error codes on failure
f5e6d5a3437610 Sumit Saxena         2022-04-29  292   */
f5e6d5a3437610 Sumit Saxena         2022-04-29  293  static long mpi3mr_get_all_tgt_info(struct mpi3mr_ioc *mrioc,
f5e6d5a3437610 Sumit Saxena         2022-04-29  294  	struct bsg_job *job)
f5e6d5a3437610 Sumit Saxena         2022-04-29  295  {
f5e6d5a3437610 Sumit Saxena         2022-04-29  296  	u16 num_devices = 0, i = 0, size;
f5e6d5a3437610 Sumit Saxena         2022-04-29  297  	unsigned long flags;
f5e6d5a3437610 Sumit Saxena         2022-04-29  298  	struct mpi3mr_tgt_dev *tgtdev;
f5e6d5a3437610 Sumit Saxena         2022-04-29  299  	struct mpi3mr_device_map_info *devmap_info = NULL;
f5e6d5a3437610 Sumit Saxena         2022-04-29  300  	struct mpi3mr_all_tgt_info *alltgt_info = NULL;
f5e6d5a3437610 Sumit Saxena         2022-04-29 @301  	uint32_t min_entrylen = 0, kern_entrylen = 0, usr_entrylen = 0;
f5e6d5a3437610 Sumit Saxena         2022-04-29  302  
f5e6d5a3437610 Sumit Saxena         2022-04-29  303  	if (job->request_payload.payload_len < sizeof(u32)) {
f5e6d5a3437610 Sumit Saxena         2022-04-29  304  		dprint_bsg_err(mrioc, "%s: invalid size argument\n",
f5e6d5a3437610 Sumit Saxena         2022-04-29  305  		    __func__);
fad43146fb864d Shin'ichiro Kawasaki 2023-01-10  306  		return -EINVAL;
f5e6d5a3437610 Sumit Saxena         2022-04-29  307  	}
f5e6d5a3437610 Sumit Saxena         2022-04-29  308  
f5e6d5a3437610 Sumit Saxena         2022-04-29  309  	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
f5e6d5a3437610 Sumit Saxena         2022-04-29  310  	list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list)
f5e6d5a3437610 Sumit Saxena         2022-04-29  311  		num_devices++;
f5e6d5a3437610 Sumit Saxena         2022-04-29  312  	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
f5e6d5a3437610 Sumit Saxena         2022-04-29  313  
f5e6d5a3437610 Sumit Saxena         2022-04-29  314  	if ((job->request_payload.payload_len == sizeof(u32)) ||
f5e6d5a3437610 Sumit Saxena         2022-04-29  315  		list_empty(&mrioc->tgtdev_list)) {
f5e6d5a3437610 Sumit Saxena         2022-04-29  316  		sg_copy_from_buffer(job->request_payload.sg_list,
f5e6d5a3437610 Sumit Saxena         2022-04-29  317  				    job->request_payload.sg_cnt,
f5e6d5a3437610 Sumit Saxena         2022-04-29  318  				    &num_devices, sizeof(num_devices));
f5e6d5a3437610 Sumit Saxena         2022-04-29  319  		return 0;
f5e6d5a3437610 Sumit Saxena         2022-04-29  320  	}
f5e6d5a3437610 Sumit Saxena         2022-04-29  321  
f5e6d5a3437610 Sumit Saxena         2022-04-29  322  	kern_entrylen = (num_devices - 1) * sizeof(*devmap_info);
f5e6d5a3437610 Sumit Saxena         2022-04-29  323  	size = sizeof(*alltgt_info) + kern_entrylen;
f5e6d5a3437610 Sumit Saxena         2022-04-29  324  	alltgt_info = kzalloc(size, GFP_KERNEL);
f5e6d5a3437610 Sumit Saxena         2022-04-29  325  	if (!alltgt_info)
f5e6d5a3437610 Sumit Saxena         2022-04-29  326  		return -ENOMEM;
f5e6d5a3437610 Sumit Saxena         2022-04-29  327  
f5e6d5a3437610 Sumit Saxena         2022-04-29  328  	devmap_info = alltgt_info->dmi;
f5e6d5a3437610 Sumit Saxena         2022-04-29  329  	memset((u8 *)devmap_info, 0xFF, (kern_entrylen + sizeof(*devmap_info)));
f5e6d5a3437610 Sumit Saxena         2022-04-29  330  	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
f5e6d5a3437610 Sumit Saxena         2022-04-29  331  	list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) {
f5e6d5a3437610 Sumit Saxena         2022-04-29  332  		if (i < num_devices) {
f5e6d5a3437610 Sumit Saxena         2022-04-29  333  			devmap_info[i].handle = tgtdev->dev_handle;
f5e6d5a3437610 Sumit Saxena         2022-04-29  334  			devmap_info[i].perst_id = tgtdev->perst_id;
f5e6d5a3437610 Sumit Saxena         2022-04-29  335  			if (tgtdev->host_exposed && tgtdev->starget) {
f5e6d5a3437610 Sumit Saxena         2022-04-29  336  				devmap_info[i].target_id = tgtdev->starget->id;
f5e6d5a3437610 Sumit Saxena         2022-04-29  337  				devmap_info[i].bus_id =
f5e6d5a3437610 Sumit Saxena         2022-04-29  338  				    tgtdev->starget->channel;
f5e6d5a3437610 Sumit Saxena         2022-04-29  339  			}
f5e6d5a3437610 Sumit Saxena         2022-04-29  340  			i++;
f5e6d5a3437610 Sumit Saxena         2022-04-29  341  		}
f5e6d5a3437610 Sumit Saxena         2022-04-29  342  	}
f5e6d5a3437610 Sumit Saxena         2022-04-29  343  	num_devices = i;
f5e6d5a3437610 Sumit Saxena         2022-04-29  344  	spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
f5e6d5a3437610 Sumit Saxena         2022-04-29  345  
f5e6d5a3437610 Sumit Saxena         2022-04-29  346  	memcpy(&alltgt_info->num_devices, &num_devices, sizeof(num_devices));
f5e6d5a3437610 Sumit Saxena         2022-04-29  347  
f5e6d5a3437610 Sumit Saxena         2022-04-29  348  	usr_entrylen = (job->request_payload.payload_len - sizeof(u32)) / sizeof(*devmap_info);
f5e6d5a3437610 Sumit Saxena         2022-04-29  349  	usr_entrylen *= sizeof(*devmap_info);
f5e6d5a3437610 Sumit Saxena         2022-04-29  350  	min_entrylen = min(usr_entrylen, kern_entrylen);
f5e6d5a3437610 Sumit Saxena         2022-04-29  351  
f5e6d5a3437610 Sumit Saxena         2022-04-29  352  	sg_copy_from_buffer(job->request_payload.sg_list,
f5e6d5a3437610 Sumit Saxena         2022-04-29  353  			    job->request_payload.sg_cnt,
f5e6d5a3437610 Sumit Saxena         2022-04-29  354  			    alltgt_info, job->request_payload.payload_len);
f5e6d5a3437610 Sumit Saxena         2022-04-29  355  	kfree(alltgt_info);
fad43146fb864d Shin'ichiro Kawasaki 2023-01-10  356  	return 0;
f5e6d5a3437610 Sumit Saxena         2022-04-29  357  }
f5e6d5a3437610 Sumit Saxena         2022-04-29  358  /**
f5e6d5a3437610 Sumit Saxena         2022-04-29  359   * mpi3mr_get_change_count - Get topology change count
f5e6d5a3437610 Sumit Saxena         2022-04-29  360   * @mrioc: Adapter instance reference
f5e6d5a3437610 Sumit Saxena         2022-04-29  361   * @job: BSG job reference
f5e6d5a3437610 Sumit Saxena         2022-04-29  362   *
f5e6d5a3437610 Sumit Saxena         2022-04-29  363   * This function copies the toplogy change count provided by the
f5e6d5a3437610 Sumit Saxena         2022-04-29  364   * driver in events and cached in the driver to the user
f5e6d5a3437610 Sumit Saxena         2022-04-29  365   * provided buffer for the specific controller.
f5e6d5a3437610 Sumit Saxena         2022-04-29  366   *
f5e6d5a3437610 Sumit Saxena         2022-04-29  367   * Return: 0 on success and proper error codes on failure
f5e6d5a3437610 Sumit Saxena         2022-04-29  368   */
f5e6d5a3437610 Sumit Saxena         2022-04-29  369  static long mpi3mr_get_change_count(struct mpi3mr_ioc *mrioc,
f5e6d5a3437610 Sumit Saxena         2022-04-29  370  	struct bsg_job *job)
f5e6d5a3437610 Sumit Saxena         2022-04-29  371  {
f5e6d5a3437610 Sumit Saxena         2022-04-29  372  	struct mpi3mr_change_count chgcnt;
f5e6d5a3437610 Sumit Saxena         2022-04-29  373  
f5e6d5a3437610 Sumit Saxena         2022-04-29  374  	memset(&chgcnt, 0, sizeof(chgcnt));
f5e6d5a3437610 Sumit Saxena         2022-04-29  375  	chgcnt.change_count = mrioc->change_count;
f5e6d5a3437610 Sumit Saxena         2022-04-29  376  	if (job->request_payload.payload_len >= sizeof(chgcnt)) {
f5e6d5a3437610 Sumit Saxena         2022-04-29  377  		sg_copy_from_buffer(job->request_payload.sg_list,
f5e6d5a3437610 Sumit Saxena         2022-04-29  378  				    job->request_payload.sg_cnt,
f5e6d5a3437610 Sumit Saxena         2022-04-29  379  				    &chgcnt, sizeof(chgcnt));
f5e6d5a3437610 Sumit Saxena         2022-04-29  380  		return 0;
f5e6d5a3437610 Sumit Saxena         2022-04-29  381  	}
f5e6d5a3437610 Sumit Saxena         2022-04-29  382  	return -EINVAL;
f5e6d5a3437610 Sumit Saxena         2022-04-29  383  }
f5e6d5a3437610 Sumit Saxena         2022-04-29  384
Shin'ichiro Kawasaki Jan. 27, 2023, 6:17 a.m. UTC | #2
On Jan 10, 2023 / 12:27, kernel test robot wrote:
> Hi Shin'ichiro,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on jejb-scsi/for-next]
> [also build test WARNING on mkp-scsi/for-next linus/master v6.2-rc3 next-20230109]
> [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/Shin-ichiro-Kawasaki/scsi-mpi3mr-remove-unnecessary-memcpy/20230110-095717
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
> patch link:    https://lore.kernel.org/r/20230110015538.201332-2-shinichiro.kawasaki%40wdc.com
> patch subject: [PATCH v3 1/5] scsi: mpi3mr: remove unnecessary memcpy
> config: ia64-allyesconfig
> compiler: ia64-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/fad43146fb864da8124537dd3a548f9c638cddd6
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Shin-ichiro-Kawasaki/scsi-mpi3mr-remove-unnecessary-memcpy/20230110-095717
>         git checkout fad43146fb864da8124537dd3a548f9c638cddd6
>         # 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=ia64 olddefconfig
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/scsi/mpi3mr/
> 
> 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/scsi/mpi3mr/mpi3mr_app.c: In function 'mpi3mr_get_all_tgt_info':
> >> drivers/scsi/mpi3mr/mpi3mr_app.c:301:18: warning: variable 'min_entrylen' set but not used [-Wunused-but-set-variable]
>      301 |         uint32_t min_entrylen = 0, kern_entrylen = 0, usr_entrylen = 0;
>          |                  ^~~~~~~~~~~~

This patch removes the reference to min_entrylen, and the 3rd patch adds back
the reference. So, this warning can be fixed by moving the 1st patch in the
series after the 3rd patch. Will do so in v4.
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index 9baac224b213..5bbfdff70570 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -293,7 +293,6 @@  static long mpi3mr_bsg_pel_enable(struct mpi3mr_ioc *mrioc,
 static long mpi3mr_get_all_tgt_info(struct mpi3mr_ioc *mrioc,
 	struct bsg_job *job)
 {
-	long rval = -EINVAL;
 	u16 num_devices = 0, i = 0, size;
 	unsigned long flags;
 	struct mpi3mr_tgt_dev *tgtdev;
@@ -304,7 +303,7 @@  static long mpi3mr_get_all_tgt_info(struct mpi3mr_ioc *mrioc,
 	if (job->request_payload.payload_len < sizeof(u32)) {
 		dprint_bsg_err(mrioc, "%s: invalid size argument\n",
 		    __func__);
-		return rval;
+		return -EINVAL;
 	}
 
 	spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
@@ -349,20 +348,12 @@  static long mpi3mr_get_all_tgt_info(struct mpi3mr_ioc *mrioc,
 	usr_entrylen = (job->request_payload.payload_len - sizeof(u32)) / sizeof(*devmap_info);
 	usr_entrylen *= sizeof(*devmap_info);
 	min_entrylen = min(usr_entrylen, kern_entrylen);
-	if (min_entrylen && (!memcpy(&alltgt_info->dmi, devmap_info, min_entrylen))) {
-		dprint_bsg_err(mrioc, "%s:%d: device map info copy failed\n",
-		    __func__, __LINE__);
-		rval = -EFAULT;
-		goto out;
-	}
 
 	sg_copy_from_buffer(job->request_payload.sg_list,
 			    job->request_payload.sg_cnt,
 			    alltgt_info, job->request_payload.payload_len);
-	rval = 0;
-out:
 	kfree(alltgt_info);
-	return rval;
+	return 0;
 }
 /**
  * mpi3mr_get_change_count - Get topology change count