aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire/fw-sbp2.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2007-05-09 19:23:08 -0400
committerStefan Richter <stefanr@s5r6.in-berlin.de>2007-05-10 12:24:14 -0400
commit95ffc5e314e2bba87ec012c6e3adc487c5a7b4bb (patch)
tree5612352b4d3b8309cde8bff2c77ee2038304bffb /drivers/firewire/fw-sbp2.c
parentad85274fb7f1b3c8c03f6f516dc6196a19ea4296 (diff)
firewire: Handle the last few DMA mapping error cases.
This should be the last missing checks. Signed-off-by: Kristian Hoegsberg <krh@redhat.com> Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/firewire/fw-sbp2.c')
-rw-r--r--drivers/firewire/fw-sbp2.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index c6fd7d353685..c32254e94187 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -892,7 +892,7 @@ complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
892 kfree(orb); 892 kfree(orb);
893} 893}
894 894
895static void sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb) 895static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
896{ 896{
897 struct sbp2_device *sd = 897 struct sbp2_device *sd =
898 (struct sbp2_device *)orb->cmd->device->host->hostdata; 898 (struct sbp2_device *)orb->cmd->device->host->hostdata;
@@ -906,6 +906,8 @@ static void sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
906 sg = (struct scatterlist *)orb->cmd->request_buffer; 906 sg = (struct scatterlist *)orb->cmd->request_buffer;
907 count = dma_map_sg(device->card->device, sg, orb->cmd->use_sg, 907 count = dma_map_sg(device->card->device, sg, orb->cmd->use_sg,
908 orb->cmd->sc_data_direction); 908 orb->cmd->sc_data_direction);
909 if (count == 0)
910 goto fail;
909 911
910 /* 912 /*
911 * Handle the special case where there is only one element in 913 * Handle the special case where there is only one element in
@@ -919,7 +921,7 @@ static void sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
919 orb->request.data_descriptor.low = sg_dma_address(sg); 921 orb->request.data_descriptor.low = sg_dma_address(sg);
920 orb->request.misc |= 922 orb->request.misc |=
921 COMMAND_ORB_DATA_SIZE(sg_dma_len(sg)); 923 COMMAND_ORB_DATA_SIZE(sg_dma_len(sg));
922 return; 924 return 0;
923 } 925 }
924 926
925 /* 927 /*
@@ -952,6 +954,8 @@ static void sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
952 orb->page_table_bus = 954 orb->page_table_bus =
953 dma_map_single(device->card->device, orb->page_table, 955 dma_map_single(device->card->device, orb->page_table,
954 size, DMA_TO_DEVICE); 956 size, DMA_TO_DEVICE);
957 if (dma_mapping_error(orb->page_table_bus))
958 goto fail_page_table;
955 orb->request.data_descriptor.high = sd->address_high; 959 orb->request.data_descriptor.high = sd->address_high;
956 orb->request.data_descriptor.low = orb->page_table_bus; 960 orb->request.data_descriptor.low = orb->page_table_bus;
957 orb->request.misc |= 961 orb->request.misc |=
@@ -959,9 +963,17 @@ static void sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
959 COMMAND_ORB_DATA_SIZE(j); 963 COMMAND_ORB_DATA_SIZE(j);
960 964
961 fw_memcpy_to_be32(orb->page_table, orb->page_table, size); 965 fw_memcpy_to_be32(orb->page_table, orb->page_table, size);
966
967 return 0;
968
969 fail_page_table:
970 dma_unmap_sg(device->card->device, sg, orb->cmd->use_sg,
971 orb->cmd->sc_data_direction);
972 fail:
973 return -ENOMEM;
962} 974}
963 975
964static void sbp2_command_orb_map_buffer(struct sbp2_command_orb *orb) 976static int sbp2_command_orb_map_buffer(struct sbp2_command_orb *orb)
965{ 977{
966 struct sbp2_device *sd = 978 struct sbp2_device *sd =
967 (struct sbp2_device *)orb->cmd->device->host->hostdata; 979 (struct sbp2_device *)orb->cmd->device->host->hostdata;
@@ -978,10 +990,15 @@ static void sbp2_command_orb_map_buffer(struct sbp2_command_orb *orb)
978 orb->cmd->request_buffer, 990 orb->cmd->request_buffer,
979 orb->cmd->request_bufflen, 991 orb->cmd->request_bufflen,
980 orb->cmd->sc_data_direction); 992 orb->cmd->sc_data_direction);
993 if (dma_mapping_error(orb->request_buffer_bus))
994 return -ENOMEM;
995
981 orb->request.data_descriptor.high = sd->address_high; 996 orb->request.data_descriptor.high = sd->address_high;
982 orb->request.data_descriptor.low = orb->request_buffer_bus; 997 orb->request.data_descriptor.low = orb->request_buffer_bus;
983 orb->request.misc |= 998 orb->request.misc |=
984 COMMAND_ORB_DATA_SIZE(orb->cmd->request_bufflen); 999 COMMAND_ORB_DATA_SIZE(orb->cmd->request_bufflen);
1000
1001 return 0;
985} 1002}
986 1003
987/* SCSI stack integration */ 1004/* SCSI stack integration */
@@ -1042,7 +1059,8 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1042 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA); 1059 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA);
1043 1060
1044 if (cmd->use_sg) { 1061 if (cmd->use_sg) {
1045 sbp2_command_orb_map_scatterlist(orb); 1062 if (sbp2_command_orb_map_scatterlist(orb) < 0)
1063 goto fail_map_payload;
1046 } else if (cmd->request_bufflen > SBP2_MAX_SG_ELEMENT_LENGTH) { 1064 } else if (cmd->request_bufflen > SBP2_MAX_SG_ELEMENT_LENGTH) {
1047 /* 1065 /*
1048 * FIXME: Need to split this into a sg list... but 1066 * FIXME: Need to split this into a sg list... but
@@ -1050,9 +1068,10 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1050 * reporting our max supported block size? 1068 * reporting our max supported block size?
1051 */ 1069 */
1052 fw_error("command > 64k\n"); 1070 fw_error("command > 64k\n");
1053 goto fail_bufflen; 1071 goto fail_map_payload;
1054 } else if (cmd->request_bufflen > 0) { 1072 } else if (cmd->request_bufflen > 0) {
1055 sbp2_command_orb_map_buffer(orb); 1073 if (sbp2_command_orb_map_buffer(orb) < 0)
1074 goto fail_map_payload;
1056 } 1075 }
1057 1076
1058 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof orb->request); 1077 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof orb->request);
@@ -1068,7 +1087,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1068 1087
1069 return 0; 1088 return 0;
1070 1089
1071 fail_bufflen: 1090 fail_map_payload:
1072 dma_unmap_single(device->card->device, orb->base.request_bus, 1091 dma_unmap_single(device->card->device, orb->base.request_bus,
1073 sizeof orb->request, DMA_TO_DEVICE); 1092 sizeof orb->request, DMA_TO_DEVICE);
1074 fail_mapping: 1093 fail_mapping: