@@ -2329,6 +2329,15 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
23292329 if (!mrioc )
23302330 return - ENODEV ;
23312331
2332+ if (mutex_lock_interruptible (& mrioc -> bsg_cmds .mutex ))
2333+ return - ERESTARTSYS ;
2334+
2335+ if (mrioc -> bsg_cmds .state & MPI3MR_CMD_PENDING ) {
2336+ dprint_bsg_err (mrioc , "%s: command is in use\n" , __func__ );
2337+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2338+ return - EAGAIN ;
2339+ }
2340+
23322341 if (!mrioc -> ioctl_sges_allocated ) {
23332342 dprint_bsg_err (mrioc , "%s: DMA memory was not allocated\n" ,
23342343 __func__ );
@@ -2339,27 +2348,32 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
23392348 karg -> timeout = MPI3MR_APP_DEFAULT_TIMEOUT ;
23402349
23412350 mpi_req = kzalloc (MPI3MR_ADMIN_REQ_FRAME_SZ , GFP_KERNEL );
2342- if (!mpi_req )
2351+ if (!mpi_req ) {
2352+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
23432353 return - ENOMEM ;
2354+ }
23442355 mpi_header = (struct mpi3_request_header * )mpi_req ;
23452356
23462357 bufcnt = karg -> buf_entry_list .num_of_entries ;
23472358 drv_bufs = kzalloc ((sizeof (* drv_bufs ) * bufcnt ), GFP_KERNEL );
23482359 if (!drv_bufs ) {
2360+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
23492361 rval = - ENOMEM ;
23502362 goto out ;
23512363 }
23522364
23532365 dout_buf = kzalloc (job -> request_payload .payload_len ,
23542366 GFP_KERNEL );
23552367 if (!dout_buf ) {
2368+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
23562369 rval = - ENOMEM ;
23572370 goto out ;
23582371 }
23592372
23602373 din_buf = kzalloc (job -> reply_payload .payload_len ,
23612374 GFP_KERNEL );
23622375 if (!din_buf ) {
2376+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
23632377 rval = - ENOMEM ;
23642378 goto out ;
23652379 }
@@ -2435,6 +2449,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
24352449 (mpi_msg_size > MPI3MR_ADMIN_REQ_FRAME_SZ )) {
24362450 dprint_bsg_err (mrioc , "%s: invalid MPI message size\n" ,
24372451 __func__ );
2452+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24382453 rval = - EINVAL ;
24392454 goto out ;
24402455 }
@@ -2447,19 +2462,22 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
24472462 if (invalid_be ) {
24482463 dprint_bsg_err (mrioc , "%s: invalid buffer entries passed\n" ,
24492464 __func__ );
2465+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24502466 rval = - EINVAL ;
24512467 goto out ;
24522468 }
24532469
24542470 if (sgl_dout_iter > (dout_buf + job -> request_payload .payload_len )) {
24552471 dprint_bsg_err (mrioc , "%s: data_out buffer length mismatch\n" ,
24562472 __func__ );
2473+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24572474 rval = - EINVAL ;
24582475 goto out ;
24592476 }
24602477 if (sgl_din_iter > (din_buf + job -> reply_payload .payload_len )) {
24612478 dprint_bsg_err (mrioc , "%s: data_in buffer length mismatch\n" ,
24622479 __func__ );
2480+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24632481 rval = - EINVAL ;
24642482 goto out ;
24652483 }
@@ -2472,6 +2490,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
24722490 dprint_bsg_err (mrioc , "%s:%d: invalid data transfer size passed for function 0x%x din_size = %d, dout_size = %d\n" ,
24732491 __func__ , __LINE__ , mpi_header -> function , din_size ,
24742492 dout_size );
2493+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24752494 rval = - EINVAL ;
24762495 goto out ;
24772496 }
@@ -2480,13 +2499,15 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
24802499 dprint_bsg_err (mrioc ,
24812500 "%s:%d: invalid data transfer size passed for function 0x%x din_size=%d\n" ,
24822501 __func__ , __LINE__ , mpi_header -> function , din_size );
2502+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24832503 rval = - EINVAL ;
24842504 goto out ;
24852505 }
24862506 if (dout_size > MPI3MR_MAX_APP_XFER_SIZE ) {
24872507 dprint_bsg_err (mrioc ,
24882508 "%s:%d: invalid data transfer size passed for function 0x%x dout_size = %d\n" ,
24892509 __func__ , __LINE__ , mpi_header -> function , dout_size );
2510+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
24902511 rval = - EINVAL ;
24912512 goto out ;
24922513 }
@@ -2497,6 +2518,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
24972518 dprint_bsg_err (mrioc , "%s:%d: invalid message size passed:%d:%d:%d:%d\n" ,
24982519 __func__ , __LINE__ , din_cnt , dout_cnt , din_size ,
24992520 dout_size );
2521+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
25002522 rval = - EINVAL ;
25012523 goto out ;
25022524 }
@@ -2544,6 +2566,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
25442566 continue ;
25452567 if (mpi3mr_map_data_buffer_dma (mrioc , drv_buf_iter , desc_count )) {
25462568 rval = - ENOMEM ;
2569+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
25472570 dprint_bsg_err (mrioc , "%s:%d: mapping data buffers failed\n" ,
25482571 __func__ , __LINE__ );
25492572 goto out ;
@@ -2556,20 +2579,11 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
25562579 sense_buff_k = kzalloc (erbsz , GFP_KERNEL );
25572580 if (!sense_buff_k ) {
25582581 rval = - ENOMEM ;
2582+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
25592583 goto out ;
25602584 }
25612585 }
25622586
2563- if (mutex_lock_interruptible (& mrioc -> bsg_cmds .mutex )) {
2564- rval = - ERESTARTSYS ;
2565- goto out ;
2566- }
2567- if (mrioc -> bsg_cmds .state & MPI3MR_CMD_PENDING ) {
2568- rval = - EAGAIN ;
2569- dprint_bsg_err (mrioc , "%s: command is in use\n" , __func__ );
2570- mutex_unlock (& mrioc -> bsg_cmds .mutex );
2571- goto out ;
2572- }
25732587 if (mrioc -> unrecoverable ) {
25742588 dprint_bsg_err (mrioc , "%s: unrecoverable controller\n" ,
25752589 __func__ );
0 commit comments