@@ -410,7 +410,8 @@ static void xcopy_pt_release_cmd(struct se_cmd *se_cmd)
410
410
struct xcopy_pt_cmd * xpt_cmd = container_of (se_cmd ,
411
411
struct xcopy_pt_cmd , se_cmd );
412
412
413
- kfree (xpt_cmd );
413
+ /* xpt_cmd is on the stack, nothing to free here */
414
+ pr_debug ("xpt_cmd done: %p\n" , xpt_cmd );
414
415
}
415
416
416
417
static int xcopy_pt_check_stop_free (struct se_cmd * se_cmd )
@@ -566,20 +567,15 @@ static int target_xcopy_read_source(
566
567
sector_t src_lba ,
567
568
u32 src_sectors )
568
569
{
569
- struct xcopy_pt_cmd * xpt_cmd ;
570
- struct se_cmd * se_cmd ;
570
+ struct xcopy_pt_cmd xpt_cmd ;
571
+ struct se_cmd * se_cmd = & xpt_cmd . se_cmd ;
571
572
u32 length = (src_sectors * src_dev -> dev_attrib .block_size );
572
573
int rc ;
573
574
unsigned char cdb [16 ];
574
575
bool remote_port = (xop -> op_origin == XCOL_DEST_RECV_OP );
575
576
576
- xpt_cmd = kzalloc (sizeof (struct xcopy_pt_cmd ), GFP_KERNEL );
577
- if (!xpt_cmd ) {
578
- pr_err ("Unable to allocate xcopy_pt_cmd\n" );
579
- return - ENOMEM ;
580
- }
581
- init_completion (& xpt_cmd -> xpt_passthrough_sem );
582
- se_cmd = & xpt_cmd -> se_cmd ;
577
+ memset (& xpt_cmd , 0 , sizeof (xpt_cmd ));
578
+ init_completion (& xpt_cmd .xpt_passthrough_sem );
583
579
584
580
memset (& cdb [0 ], 0 , 16 );
585
581
cdb [0 ] = READ_16 ;
@@ -589,28 +585,24 @@ static int target_xcopy_read_source(
589
585
(unsigned long long )src_lba , src_sectors , length );
590
586
591
587
transport_init_se_cmd (se_cmd , & xcopy_pt_tfo , & xcopy_pt_sess , length ,
592
- DMA_FROM_DEVICE , 0 , & xpt_cmd -> sense_buffer [0 ]);
593
- xop -> src_pt_cmd = xpt_cmd ;
588
+ DMA_FROM_DEVICE , 0 , & xpt_cmd .sense_buffer [0 ]);
594
589
595
- rc = target_xcopy_setup_pt_cmd (xpt_cmd , xop , src_dev , & cdb [0 ],
590
+ rc = target_xcopy_setup_pt_cmd (& xpt_cmd , xop , src_dev , & cdb [0 ],
596
591
remote_port );
597
592
if (rc < 0 ) {
598
- ec_cmd -> scsi_status = xpt_cmd -> se_cmd .scsi_status ;
599
- transport_generic_free_cmd (se_cmd , 0 );
600
- return rc ;
593
+ ec_cmd -> scsi_status = se_cmd -> scsi_status ;
594
+ goto out ;
601
595
}
602
596
603
597
pr_debug ("XCOPY-READ: Saved xop->xop_data_sg: %p, num: %u for READ"
604
598
" memory\n" , xop -> xop_data_sg , xop -> xop_data_nents );
605
599
606
- rc = target_xcopy_issue_pt_cmd (xpt_cmd );
607
- if (rc < 0 ) {
608
- ec_cmd -> scsi_status = xpt_cmd -> se_cmd .scsi_status ;
609
- transport_generic_free_cmd (se_cmd , 0 );
610
- return rc ;
611
- }
612
-
613
- return 0 ;
600
+ rc = target_xcopy_issue_pt_cmd (& xpt_cmd );
601
+ if (rc < 0 )
602
+ ec_cmd -> scsi_status = se_cmd -> scsi_status ;
603
+ out :
604
+ transport_generic_free_cmd (se_cmd , 0 );
605
+ return rc ;
614
606
}
615
607
616
608
static int target_xcopy_write_destination (
@@ -620,20 +612,15 @@ static int target_xcopy_write_destination(
620
612
sector_t dst_lba ,
621
613
u32 dst_sectors )
622
614
{
623
- struct xcopy_pt_cmd * xpt_cmd ;
624
- struct se_cmd * se_cmd ;
615
+ struct xcopy_pt_cmd xpt_cmd ;
616
+ struct se_cmd * se_cmd = & xpt_cmd . se_cmd ;
625
617
u32 length = (dst_sectors * dst_dev -> dev_attrib .block_size );
626
618
int rc ;
627
619
unsigned char cdb [16 ];
628
620
bool remote_port = (xop -> op_origin == XCOL_SOURCE_RECV_OP );
629
621
630
- xpt_cmd = kzalloc (sizeof (struct xcopy_pt_cmd ), GFP_KERNEL );
631
- if (!xpt_cmd ) {
632
- pr_err ("Unable to allocate xcopy_pt_cmd\n" );
633
- return - ENOMEM ;
634
- }
635
- init_completion (& xpt_cmd -> xpt_passthrough_sem );
636
- se_cmd = & xpt_cmd -> se_cmd ;
622
+ memset (& xpt_cmd , 0 , sizeof (xpt_cmd ));
623
+ init_completion (& xpt_cmd .xpt_passthrough_sem );
637
624
638
625
memset (& cdb [0 ], 0 , 16 );
639
626
cdb [0 ] = WRITE_16 ;
@@ -643,25 +630,21 @@ static int target_xcopy_write_destination(
643
630
(unsigned long long )dst_lba , dst_sectors , length );
644
631
645
632
transport_init_se_cmd (se_cmd , & xcopy_pt_tfo , & xcopy_pt_sess , length ,
646
- DMA_TO_DEVICE , 0 , & xpt_cmd -> sense_buffer [0 ]);
647
- xop -> dst_pt_cmd = xpt_cmd ;
633
+ DMA_TO_DEVICE , 0 , & xpt_cmd .sense_buffer [0 ]);
648
634
649
- rc = target_xcopy_setup_pt_cmd (xpt_cmd , xop , dst_dev , & cdb [0 ],
635
+ rc = target_xcopy_setup_pt_cmd (& xpt_cmd , xop , dst_dev , & cdb [0 ],
650
636
remote_port );
651
637
if (rc < 0 ) {
652
- ec_cmd -> scsi_status = xpt_cmd -> se_cmd .scsi_status ;
653
- transport_generic_free_cmd (se_cmd , 0 );
654
- return rc ;
655
- }
656
-
657
- rc = target_xcopy_issue_pt_cmd (xpt_cmd );
658
- if (rc < 0 ) {
659
- ec_cmd -> scsi_status = xpt_cmd -> se_cmd .scsi_status ;
660
- transport_generic_free_cmd (se_cmd , 0 );
661
- return rc ;
638
+ ec_cmd -> scsi_status = se_cmd -> scsi_status ;
639
+ goto out ;
662
640
}
663
641
664
- return 0 ;
642
+ rc = target_xcopy_issue_pt_cmd (& xpt_cmd );
643
+ if (rc < 0 )
644
+ ec_cmd -> scsi_status = se_cmd -> scsi_status ;
645
+ out :
646
+ transport_generic_free_cmd (se_cmd , 0 );
647
+ return rc ;
665
648
}
666
649
667
650
static void target_xcopy_do_work (struct work_struct * work )
@@ -736,20 +719,15 @@ static void target_xcopy_do_work(struct work_struct *work)
736
719
737
720
rc = target_xcopy_write_destination (ec_cmd , xop , dst_dev ,
738
721
dst_lba , cur_nolb );
739
- if (rc < 0 ) {
740
- transport_generic_free_cmd (& xop -> src_pt_cmd -> se_cmd , 0 );
722
+ if (rc < 0 )
741
723
goto out ;
742
- }
743
724
744
725
dst_lba += cur_nolb ;
745
726
pr_debug ("target_xcopy_do_work: Incremented WRITE dst_lba to %llu\n" ,
746
727
(unsigned long long )dst_lba );
747
728
748
729
copied_nolb += cur_nolb ;
749
730
nolb -= cur_nolb ;
750
-
751
- transport_generic_free_cmd (& xop -> src_pt_cmd -> se_cmd , 0 );
752
- transport_generic_free_cmd (& xop -> dst_pt_cmd -> se_cmd , 0 );
753
731
}
754
732
755
733
xcopy_pt_undepend_remotedev (xop );
0 commit comments