@@ -2329,6 +2329,15 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2329
2329
if (!mrioc )
2330
2330
return - ENODEV ;
2331
2331
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
+
2332
2341
if (!mrioc -> ioctl_sges_allocated ) {
2333
2342
dprint_bsg_err (mrioc , "%s: DMA memory was not allocated\n" ,
2334
2343
__func__ );
@@ -2339,27 +2348,32 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2339
2348
karg -> timeout = MPI3MR_APP_DEFAULT_TIMEOUT ;
2340
2349
2341
2350
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 );
2343
2353
return - ENOMEM ;
2354
+ }
2344
2355
mpi_header = (struct mpi3_request_header * )mpi_req ;
2345
2356
2346
2357
bufcnt = karg -> buf_entry_list .num_of_entries ;
2347
2358
drv_bufs = kzalloc ((sizeof (* drv_bufs ) * bufcnt ), GFP_KERNEL );
2348
2359
if (!drv_bufs ) {
2360
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2349
2361
rval = - ENOMEM ;
2350
2362
goto out ;
2351
2363
}
2352
2364
2353
2365
dout_buf = kzalloc (job -> request_payload .payload_len ,
2354
2366
GFP_KERNEL );
2355
2367
if (!dout_buf ) {
2368
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2356
2369
rval = - ENOMEM ;
2357
2370
goto out ;
2358
2371
}
2359
2372
2360
2373
din_buf = kzalloc (job -> reply_payload .payload_len ,
2361
2374
GFP_KERNEL );
2362
2375
if (!din_buf ) {
2376
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2363
2377
rval = - ENOMEM ;
2364
2378
goto out ;
2365
2379
}
@@ -2435,6 +2449,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2435
2449
(mpi_msg_size > MPI3MR_ADMIN_REQ_FRAME_SZ )) {
2436
2450
dprint_bsg_err (mrioc , "%s: invalid MPI message size\n" ,
2437
2451
__func__ );
2452
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2438
2453
rval = - EINVAL ;
2439
2454
goto out ;
2440
2455
}
@@ -2447,19 +2462,22 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2447
2462
if (invalid_be ) {
2448
2463
dprint_bsg_err (mrioc , "%s: invalid buffer entries passed\n" ,
2449
2464
__func__ );
2465
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2450
2466
rval = - EINVAL ;
2451
2467
goto out ;
2452
2468
}
2453
2469
2454
2470
if (sgl_dout_iter > (dout_buf + job -> request_payload .payload_len )) {
2455
2471
dprint_bsg_err (mrioc , "%s: data_out buffer length mismatch\n" ,
2456
2472
__func__ );
2473
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2457
2474
rval = - EINVAL ;
2458
2475
goto out ;
2459
2476
}
2460
2477
if (sgl_din_iter > (din_buf + job -> reply_payload .payload_len )) {
2461
2478
dprint_bsg_err (mrioc , "%s: data_in buffer length mismatch\n" ,
2462
2479
__func__ );
2480
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2463
2481
rval = - EINVAL ;
2464
2482
goto out ;
2465
2483
}
@@ -2472,6 +2490,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2472
2490
dprint_bsg_err (mrioc , "%s:%d: invalid data transfer size passed for function 0x%x din_size = %d, dout_size = %d\n" ,
2473
2491
__func__ , __LINE__ , mpi_header -> function , din_size ,
2474
2492
dout_size );
2493
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2475
2494
rval = - EINVAL ;
2476
2495
goto out ;
2477
2496
}
@@ -2480,13 +2499,15 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2480
2499
dprint_bsg_err (mrioc ,
2481
2500
"%s:%d: invalid data transfer size passed for function 0x%x din_size=%d\n" ,
2482
2501
__func__ , __LINE__ , mpi_header -> function , din_size );
2502
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2483
2503
rval = - EINVAL ;
2484
2504
goto out ;
2485
2505
}
2486
2506
if (dout_size > MPI3MR_MAX_APP_XFER_SIZE ) {
2487
2507
dprint_bsg_err (mrioc ,
2488
2508
"%s:%d: invalid data transfer size passed for function 0x%x dout_size = %d\n" ,
2489
2509
__func__ , __LINE__ , mpi_header -> function , dout_size );
2510
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2490
2511
rval = - EINVAL ;
2491
2512
goto out ;
2492
2513
}
@@ -2497,6 +2518,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2497
2518
dprint_bsg_err (mrioc , "%s:%d: invalid message size passed:%d:%d:%d:%d\n" ,
2498
2519
__func__ , __LINE__ , din_cnt , dout_cnt , din_size ,
2499
2520
dout_size );
2521
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2500
2522
rval = - EINVAL ;
2501
2523
goto out ;
2502
2524
}
@@ -2544,6 +2566,7 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2544
2566
continue ;
2545
2567
if (mpi3mr_map_data_buffer_dma (mrioc , drv_buf_iter , desc_count )) {
2546
2568
rval = - ENOMEM ;
2569
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2547
2570
dprint_bsg_err (mrioc , "%s:%d: mapping data buffers failed\n" ,
2548
2571
__func__ , __LINE__ );
2549
2572
goto out ;
@@ -2556,20 +2579,11 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
2556
2579
sense_buff_k = kzalloc (erbsz , GFP_KERNEL );
2557
2580
if (!sense_buff_k ) {
2558
2581
rval = - ENOMEM ;
2582
+ mutex_unlock (& mrioc -> bsg_cmds .mutex );
2559
2583
goto out ;
2560
2584
}
2561
2585
}
2562
2586
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
- }
2573
2587
if (mrioc -> unrecoverable ) {
2574
2588
dprint_bsg_err (mrioc , "%s: unrecoverable controller\n" ,
2575
2589
__func__ );
0 commit comments