@@ -6358,37 +6358,33 @@ static int hpsa_getdrivver_ioctl(struct ctlr_info *h, void __user *argp)
6358
6358
return 0 ;
6359
6359
}
6360
6360
6361
- static int hpsa_passthru_ioctl (struct ctlr_info * h , void __user * argp )
6361
+ static int hpsa_passthru_ioctl (struct ctlr_info * h ,
6362
+ IOCTL_Command_struct * iocommand )
6362
6363
{
6363
- IOCTL_Command_struct iocommand ;
6364
6364
struct CommandList * c ;
6365
6365
char * buff = NULL ;
6366
6366
u64 temp64 ;
6367
6367
int rc = 0 ;
6368
6368
6369
- if (!argp )
6370
- return - EINVAL ;
6371
6369
if (!capable (CAP_SYS_RAWIO ))
6372
6370
return - EPERM ;
6373
- if (copy_from_user (& iocommand , argp , sizeof (iocommand )))
6374
- return - EFAULT ;
6375
- if ((iocommand .buf_size < 1 ) &&
6376
- (iocommand .Request .Type .Direction != XFER_NONE )) {
6371
+ if ((iocommand -> buf_size < 1 ) &&
6372
+ (iocommand -> Request .Type .Direction != XFER_NONE )) {
6377
6373
return - EINVAL ;
6378
6374
}
6379
- if (iocommand . buf_size > 0 ) {
6380
- buff = kmalloc (iocommand . buf_size , GFP_KERNEL );
6375
+ if (iocommand -> buf_size > 0 ) {
6376
+ buff = kmalloc (iocommand -> buf_size , GFP_KERNEL );
6381
6377
if (buff == NULL )
6382
6378
return - ENOMEM ;
6383
- if (iocommand . Request .Type .Direction & XFER_WRITE ) {
6379
+ if (iocommand -> Request .Type .Direction & XFER_WRITE ) {
6384
6380
/* Copy the data into the buffer we created */
6385
- if (copy_from_user (buff , iocommand . buf ,
6386
- iocommand . buf_size )) {
6381
+ if (copy_from_user (buff , iocommand -> buf ,
6382
+ iocommand -> buf_size )) {
6387
6383
rc = - EFAULT ;
6388
6384
goto out_kfree ;
6389
6385
}
6390
6386
} else {
6391
- memset (buff , 0 , iocommand . buf_size );
6387
+ memset (buff , 0 , iocommand -> buf_size );
6392
6388
}
6393
6389
}
6394
6390
c = cmd_alloc (h );
@@ -6398,36 +6394,36 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6398
6394
c -> scsi_cmd = SCSI_CMD_BUSY ;
6399
6395
/* Fill in Command Header */
6400
6396
c -> Header .ReplyQueue = 0 ; /* unused in simple mode */
6401
- if (iocommand . buf_size > 0 ) { /* buffer to fill */
6397
+ if (iocommand -> buf_size > 0 ) { /* buffer to fill */
6402
6398
c -> Header .SGList = 1 ;
6403
6399
c -> Header .SGTotal = cpu_to_le16 (1 );
6404
6400
} else { /* no buffers to fill */
6405
6401
c -> Header .SGList = 0 ;
6406
6402
c -> Header .SGTotal = cpu_to_le16 (0 );
6407
6403
}
6408
- memcpy (& c -> Header .LUN , & iocommand . LUN_info , sizeof (c -> Header .LUN ));
6404
+ memcpy (& c -> Header .LUN , & iocommand -> LUN_info , sizeof (c -> Header .LUN ));
6409
6405
6410
6406
/* Fill in Request block */
6411
- memcpy (& c -> Request , & iocommand . Request ,
6407
+ memcpy (& c -> Request , & iocommand -> Request ,
6412
6408
sizeof (c -> Request ));
6413
6409
6414
6410
/* Fill in the scatter gather information */
6415
- if (iocommand . buf_size > 0 ) {
6411
+ if (iocommand -> buf_size > 0 ) {
6416
6412
temp64 = dma_map_single (& h -> pdev -> dev , buff ,
6417
- iocommand . buf_size , DMA_BIDIRECTIONAL );
6413
+ iocommand -> buf_size , DMA_BIDIRECTIONAL );
6418
6414
if (dma_mapping_error (& h -> pdev -> dev , (dma_addr_t ) temp64 )) {
6419
6415
c -> SG [0 ].Addr = cpu_to_le64 (0 );
6420
6416
c -> SG [0 ].Len = cpu_to_le32 (0 );
6421
6417
rc = - ENOMEM ;
6422
6418
goto out ;
6423
6419
}
6424
6420
c -> SG [0 ].Addr = cpu_to_le64 (temp64 );
6425
- c -> SG [0 ].Len = cpu_to_le32 (iocommand . buf_size );
6421
+ c -> SG [0 ].Len = cpu_to_le32 (iocommand -> buf_size );
6426
6422
c -> SG [0 ].Ext = cpu_to_le32 (HPSA_SG_LAST ); /* not chaining */
6427
6423
}
6428
6424
rc = hpsa_scsi_do_simple_cmd (h , c , DEFAULT_REPLY_QUEUE ,
6429
6425
NO_TIMEOUT );
6430
- if (iocommand . buf_size > 0 )
6426
+ if (iocommand -> buf_size > 0 )
6431
6427
hpsa_pci_unmap (h -> pdev , c , 1 , DMA_BIDIRECTIONAL );
6432
6428
check_ioctl_unit_attention (h , c );
6433
6429
if (rc ) {
@@ -6436,16 +6432,12 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6436
6432
}
6437
6433
6438
6434
/* Copy the error information out */
6439
- memcpy (& iocommand .error_info , c -> err_info ,
6440
- sizeof (iocommand .error_info ));
6441
- if (copy_to_user (argp , & iocommand , sizeof (iocommand ))) {
6442
- rc = - EFAULT ;
6443
- goto out ;
6444
- }
6445
- if ((iocommand .Request .Type .Direction & XFER_READ ) &&
6446
- iocommand .buf_size > 0 ) {
6435
+ memcpy (& iocommand -> error_info , c -> err_info ,
6436
+ sizeof (iocommand -> error_info ));
6437
+ if ((iocommand -> Request .Type .Direction & XFER_READ ) &&
6438
+ iocommand -> buf_size > 0 ) {
6447
6439
/* Copy the data out of the buffer we created */
6448
- if (copy_to_user (iocommand . buf , buff , iocommand . buf_size )) {
6440
+ if (copy_to_user (iocommand -> buf , buff , iocommand -> buf_size )) {
6449
6441
rc = - EFAULT ;
6450
6442
goto out ;
6451
6443
}
@@ -6457,9 +6449,9 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6457
6449
return rc ;
6458
6450
}
6459
6451
6460
- static int hpsa_big_passthru_ioctl (struct ctlr_info * h , void __user * argp )
6452
+ static int hpsa_big_passthru_ioctl (struct ctlr_info * h ,
6453
+ BIG_IOCTL_Command_struct * ioc )
6461
6454
{
6462
- BIG_IOCTL_Command_struct * ioc ;
6463
6455
struct CommandList * c ;
6464
6456
unsigned char * * buff = NULL ;
6465
6457
int * buff_size = NULL ;
@@ -6470,29 +6462,17 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6470
6462
u32 sz ;
6471
6463
BYTE __user * data_ptr ;
6472
6464
6473
- if (!argp )
6474
- return - EINVAL ;
6475
6465
if (!capable (CAP_SYS_RAWIO ))
6476
6466
return - EPERM ;
6477
- ioc = vmemdup_user (argp , sizeof (* ioc ));
6478
- if (IS_ERR (ioc )) {
6479
- status = PTR_ERR (ioc );
6480
- goto cleanup1 ;
6481
- }
6467
+
6482
6468
if ((ioc -> buf_size < 1 ) &&
6483
- (ioc -> Request .Type .Direction != XFER_NONE )) {
6484
- status = - EINVAL ;
6485
- goto cleanup1 ;
6486
- }
6469
+ (ioc -> Request .Type .Direction != XFER_NONE ))
6470
+ return - EINVAL ;
6487
6471
/* Check kmalloc limits using all SGs */
6488
- if (ioc -> malloc_size > MAX_KMALLOC_SIZE ) {
6489
- status = - EINVAL ;
6490
- goto cleanup1 ;
6491
- }
6492
- if (ioc -> buf_size > ioc -> malloc_size * SG_ENTRIES_IN_CMD ) {
6493
- status = - EINVAL ;
6494
- goto cleanup1 ;
6495
- }
6472
+ if (ioc -> malloc_size > MAX_KMALLOC_SIZE )
6473
+ return - EINVAL ;
6474
+ if (ioc -> buf_size > ioc -> malloc_size * SG_ENTRIES_IN_CMD )
6475
+ return - EINVAL ;
6496
6476
buff = kcalloc (SG_ENTRIES_IN_CMD , sizeof (char * ), GFP_KERNEL );
6497
6477
if (!buff ) {
6498
6478
status = - ENOMEM ;
@@ -6565,10 +6545,6 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6565
6545
6566
6546
/* Copy the error information out */
6567
6547
memcpy (& ioc -> error_info , c -> err_info , sizeof (ioc -> error_info ));
6568
- if (copy_to_user (argp , ioc , sizeof (* ioc ))) {
6569
- status = - EFAULT ;
6570
- goto cleanup0 ;
6571
- }
6572
6548
if ((ioc -> Request .Type .Direction & XFER_READ ) && ioc -> buf_size > 0 ) {
6573
6549
int i ;
6574
6550
@@ -6594,7 +6570,6 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
6594
6570
kfree (buff );
6595
6571
}
6596
6572
kfree (buff_size );
6597
- kvfree (ioc );
6598
6573
return status ;
6599
6574
}
6600
6575
@@ -6628,18 +6603,39 @@ static int hpsa_ioctl(struct scsi_device *dev, unsigned int cmd,
6628
6603
return hpsa_getpciinfo_ioctl (h , argp );
6629
6604
case CCISS_GETDRIVVER :
6630
6605
return hpsa_getdrivver_ioctl (h , argp );
6631
- case CCISS_PASSTHRU :
6606
+ case CCISS_PASSTHRU : {
6607
+ IOCTL_Command_struct iocommand ;
6608
+
6609
+ if (!argp )
6610
+ return - EINVAL ;
6611
+ if (copy_from_user (& iocommand , argp , sizeof (iocommand )))
6612
+ return - EFAULT ;
6632
6613
if (atomic_dec_if_positive (& h -> passthru_cmds_avail ) < 0 )
6633
6614
return - EAGAIN ;
6634
- rc = hpsa_passthru_ioctl (h , argp );
6615
+ rc = hpsa_passthru_ioctl (h , & iocommand );
6635
6616
atomic_inc (& h -> passthru_cmds_avail );
6617
+ if (!rc && copy_to_user (argp , & iocommand , sizeof (iocommand )))
6618
+ rc = - EFAULT ;
6636
6619
return rc ;
6637
- case CCISS_BIG_PASSTHRU :
6620
+ }
6621
+ case CCISS_BIG_PASSTHRU : {
6622
+ BIG_IOCTL_Command_struct * ioc ;
6623
+ if (!argp )
6624
+ return - EINVAL ;
6638
6625
if (atomic_dec_if_positive (& h -> passthru_cmds_avail ) < 0 )
6639
6626
return - EAGAIN ;
6640
- rc = hpsa_big_passthru_ioctl (h , argp );
6627
+ ioc = vmemdup_user (argp , sizeof (* ioc ));
6628
+ if (IS_ERR (ioc )) {
6629
+ atomic_inc (& h -> passthru_cmds_avail );
6630
+ return PTR_ERR (ioc );
6631
+ }
6632
+ rc = hpsa_big_passthru_ioctl (h , ioc );
6641
6633
atomic_inc (& h -> passthru_cmds_avail );
6634
+ if (!rc && copy_to_user (argp , ioc , sizeof (* ioc )))
6635
+ rc = - EFAULT ;
6636
+ kvfree (ioc );
6642
6637
return rc ;
6638
+ }
6643
6639
default :
6644
6640
return - ENOTTY ;
6645
6641
}
0 commit comments