@@ -683,7 +683,7 @@ static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev,
683
683
__le64 * old_prp_list = prp_list ;
684
684
prp_list = dma_pool_alloc (pool , GFP_ATOMIC , & prp_dma );
685
685
if (!prp_list )
686
- return BLK_STS_RESOURCE ;
686
+ goto free_prps ;
687
687
list [iod -> npages ++ ] = prp_list ;
688
688
prp_list [0 ] = old_prp_list [i - 1 ];
689
689
old_prp_list [i - 1 ] = cpu_to_le64 (prp_dma );
@@ -703,14 +703,14 @@ static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev,
703
703
dma_addr = sg_dma_address (sg );
704
704
dma_len = sg_dma_len (sg );
705
705
}
706
-
707
706
done :
708
707
cmnd -> dptr .prp1 = cpu_to_le64 (sg_dma_address (iod -> sg ));
709
708
cmnd -> dptr .prp2 = cpu_to_le64 (iod -> first_dma );
710
-
711
709
return BLK_STS_OK ;
712
-
713
- bad_sgl :
710
+ free_prps :
711
+ nvme_free_prps (dev , req );
712
+ return BLK_STS_RESOURCE ;
713
+ bad_sgl :
714
714
WARN (DO_ONCE (nvme_print_sgl , iod -> sg , iod -> nents ),
715
715
"Invalid SGL for payload:%d nents:%d\n" ,
716
716
blk_rq_payload_bytes (req ), iod -> nents );
@@ -782,7 +782,7 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
782
782
783
783
sg_list = dma_pool_alloc (pool , GFP_ATOMIC , & sgl_dma );
784
784
if (!sg_list )
785
- return BLK_STS_RESOURCE ;
785
+ goto free_sgls ;
786
786
787
787
i = 0 ;
788
788
nvme_pci_iod_list (req )[iod -> npages ++ ] = sg_list ;
@@ -795,6 +795,9 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
795
795
} while (-- entries > 0 );
796
796
797
797
return BLK_STS_OK ;
798
+ free_sgls :
799
+ nvme_free_sgls (dev , req );
800
+ return BLK_STS_RESOURCE ;
798
801
}
799
802
800
803
static blk_status_t nvme_setup_prp_simple (struct nvme_dev * dev ,
@@ -863,7 +866,7 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
863
866
sg_init_table (iod -> sg , blk_rq_nr_phys_segments (req ));
864
867
iod -> nents = blk_rq_map_sg (req -> q , req , iod -> sg );
865
868
if (!iod -> nents )
866
- goto out ;
869
+ goto out_free_sg ;
867
870
868
871
if (is_pci_p2pdma_page (sg_page (iod -> sg )))
869
872
nr_mapped = pci_p2pdma_map_sg_attrs (dev -> dev , iod -> sg ,
@@ -872,16 +875,21 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
872
875
nr_mapped = dma_map_sg_attrs (dev -> dev , iod -> sg , iod -> nents ,
873
876
rq_dma_dir (req ), DMA_ATTR_NO_WARN );
874
877
if (!nr_mapped )
875
- goto out ;
878
+ goto out_free_sg ;
876
879
877
880
iod -> use_sgl = nvme_pci_use_sgls (dev , req );
878
881
if (iod -> use_sgl )
879
882
ret = nvme_pci_setup_sgls (dev , req , & cmnd -> rw , nr_mapped );
880
883
else
881
884
ret = nvme_pci_setup_prps (dev , req , & cmnd -> rw );
882
- out :
883
885
if (ret != BLK_STS_OK )
884
- nvme_unmap_data (dev , req );
886
+ goto out_unmap_sg ;
887
+ return BLK_STS_OK ;
888
+
889
+ out_unmap_sg :
890
+ nvme_unmap_sg (dev , req );
891
+ out_free_sg :
892
+ mempool_free (iod -> sg , dev -> iod_mempool );
885
893
return ret ;
886
894
}
887
895
0 commit comments