Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] aacraid: SCSI dma mapping failure case handling

This patch handles SCSI dma mapping failure case. Reporting error code to the
upper layer instead of BUG_ON().

Signed-off-by: Mahesh Rajashekhara <Mahesh_Rajashekhara@pmc-sierra.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>

authored by

Mahesh Rajashekhara and committed by
James Bottomley
0b433447 b56d1003

+65 -24
+64 -23
drivers/scsi/aacraid/aachba.c
··· 132 132 * M O D U L E G L O B A L S 133 133 */ 134 134 135 - static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap); 136 - static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg); 137 - static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg); 138 - static unsigned long aac_build_sgraw2(struct scsi_cmnd *scsicmd, struct aac_raw_io2 *rio2, int sg_max); 139 - static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new); 135 + static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap); 136 + static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg); 137 + static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg); 138 + static long aac_build_sgraw2(struct scsi_cmnd *scsicmd, 139 + struct aac_raw_io2 *rio2, int sg_max); 140 + static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, 141 + int pages, int nseg, int nseg_new); 140 142 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd); 141 143 #ifdef AAC_DETAILED_STATUS_INFO 142 144 static char *aac_get_status_string(u32 status); ··· 973 971 { 974 972 struct aac_dev *dev = fib->dev; 975 973 u16 fibsize, command; 974 + long ret; 976 975 977 976 aac_fib_init(fib); 978 977 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) { ··· 985 982 readcmd2->byteCount = cpu_to_le32(count<<9); 986 983 readcmd2->cid = cpu_to_le16(scmd_id(cmd)); 987 984 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ); 988 - aac_build_sgraw2(cmd, readcmd2, dev->scsi_host_ptr->sg_tablesize); 985 + ret = aac_build_sgraw2(cmd, readcmd2, 986 + dev->scsi_host_ptr->sg_tablesize); 987 + if (ret < 0) 988 + return ret; 989 989 command = ContainerRawIo2; 990 990 fibsize = sizeof(struct aac_raw_io2) + 991 991 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212)); ··· 1002 996 readcmd->flags = cpu_to_le16(RIO_TYPE_READ); 1003 997 readcmd->bpTotal = 0; 1004 998 readcmd->bpComplete = 0; 1005 - aac_build_sgraw(cmd, &readcmd->sg); 999 + ret = aac_build_sgraw(cmd, &readcmd->sg); 1000 + if (ret < 0) 1001 + return ret; 1006 1002 command = ContainerRawIo; 1007 1003 fibsize = sizeof(struct aac_raw_io) + 1008 1004 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw)); ··· 1027 1019 { 1028 1020 u16 fibsize; 1029 1021 struct aac_read64 *readcmd; 1022 + long ret; 1023 + 1030 1024 aac_fib_init(fib); 1031 1025 readcmd = (struct aac_read64 *) fib_data(fib); 1032 1026 readcmd->command = cpu_to_le32(VM_CtHostRead64); ··· 1038 1028 readcmd->pad = 0; 1039 1029 readcmd->flags = 0; 1040 1030 1041 - aac_build_sg64(cmd, &readcmd->sg); 1031 + ret = aac_build_sg64(cmd, &readcmd->sg); 1032 + if (ret < 0) 1033 + return ret; 1042 1034 fibsize = sizeof(struct aac_read64) + 1043 1035 ((le32_to_cpu(readcmd->sg.count) - 1) * 1044 1036 sizeof (struct sgentry64)); ··· 1062 1050 { 1063 1051 u16 fibsize; 1064 1052 struct aac_read *readcmd; 1053 + long ret; 1054 + 1065 1055 aac_fib_init(fib); 1066 1056 readcmd = (struct aac_read *) fib_data(fib); 1067 1057 readcmd->command = cpu_to_le32(VM_CtBlockRead); ··· 1071 1057 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 1072 1058 readcmd->count = cpu_to_le32(count * 512); 1073 1059 1074 - aac_build_sg(cmd, &readcmd->sg); 1060 + ret = aac_build_sg(cmd, &readcmd->sg); 1061 + if (ret < 0) 1062 + return ret; 1075 1063 fibsize = sizeof(struct aac_read) + 1076 1064 ((le32_to_cpu(readcmd->sg.count) - 1) * 1077 1065 sizeof (struct sgentry)); ··· 1095 1079 { 1096 1080 struct aac_dev *dev = fib->dev; 1097 1081 u16 fibsize, command; 1082 + long ret; 1098 1083 1099 1084 aac_fib_init(fib); 1100 1085 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) { ··· 1110 1093 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ? 1111 1094 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) : 1112 1095 cpu_to_le16(RIO2_IO_TYPE_WRITE); 1113 - aac_build_sgraw2(cmd, writecmd2, dev->scsi_host_ptr->sg_tablesize); 1096 + ret = aac_build_sgraw2(cmd, writecmd2, 1097 + dev->scsi_host_ptr->sg_tablesize); 1098 + if (ret < 0) 1099 + return ret; 1114 1100 command = ContainerRawIo2; 1115 1101 fibsize = sizeof(struct aac_raw_io2) + 1116 1102 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212)); ··· 1130 1110 cpu_to_le16(RIO_TYPE_WRITE); 1131 1111 writecmd->bpTotal = 0; 1132 1112 writecmd->bpComplete = 0; 1133 - aac_build_sgraw(cmd, &writecmd->sg); 1113 + ret = aac_build_sgraw(cmd, &writecmd->sg); 1114 + if (ret < 0) 1115 + return ret; 1134 1116 command = ContainerRawIo; 1135 1117 fibsize = sizeof(struct aac_raw_io) + 1136 1118 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw)); ··· 1155 1133 { 1156 1134 u16 fibsize; 1157 1135 struct aac_write64 *writecmd; 1136 + long ret; 1137 + 1158 1138 aac_fib_init(fib); 1159 1139 writecmd = (struct aac_write64 *) fib_data(fib); 1160 1140 writecmd->command = cpu_to_le32(VM_CtHostWrite64); ··· 1166 1142 writecmd->pad = 0; 1167 1143 writecmd->flags = 0; 1168 1144 1169 - aac_build_sg64(cmd, &writecmd->sg); 1145 + ret = aac_build_sg64(cmd, &writecmd->sg); 1146 + if (ret < 0) 1147 + return ret; 1170 1148 fibsize = sizeof(struct aac_write64) + 1171 1149 ((le32_to_cpu(writecmd->sg.count) - 1) * 1172 1150 sizeof (struct sgentry64)); ··· 1190 1164 { 1191 1165 u16 fibsize; 1192 1166 struct aac_write *writecmd; 1167 + long ret; 1168 + 1193 1169 aac_fib_init(fib); 1194 1170 writecmd = (struct aac_write *) fib_data(fib); 1195 1171 writecmd->command = cpu_to_le32(VM_CtBlockWrite); ··· 1201 1173 writecmd->sg.count = cpu_to_le32(1); 1202 1174 /* ->stable is not used - it did mean which type of write */ 1203 1175 1204 - aac_build_sg(cmd, &writecmd->sg); 1176 + ret = aac_build_sg(cmd, &writecmd->sg); 1177 + if (ret < 0) 1178 + return ret; 1205 1179 fibsize = sizeof(struct aac_write) + 1206 1180 ((le32_to_cpu(writecmd->sg.count) - 1) * 1207 1181 sizeof (struct sgentry)); ··· 1265 1235 { 1266 1236 u16 fibsize; 1267 1237 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); 1238 + long ret; 1268 1239 1269 - aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg); 1240 + ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg); 1241 + if (ret < 0) 1242 + return ret; 1270 1243 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd)); 1271 1244 1272 1245 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); ··· 1296 1263 { 1297 1264 u16 fibsize; 1298 1265 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); 1266 + long ret; 1299 1267 1300 - aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg); 1268 + ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg); 1269 + if (ret < 0) 1270 + return ret; 1301 1271 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd)); 1302 1272 1303 1273 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); ··· 2906 2870 return -1; 2907 2871 } 2908 2872 2909 - static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg) 2873 + static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg) 2910 2874 { 2911 2875 struct aac_dev *dev; 2912 2876 unsigned long byte_count = 0; ··· 2919 2883 psg->sg[0].count = 0; 2920 2884 2921 2885 nseg = scsi_dma_map(scsicmd); 2922 - BUG_ON(nseg < 0); 2886 + if (nseg < 0) 2887 + return nseg; 2923 2888 if (nseg) { 2924 2889 struct scatterlist *sg; 2925 2890 int i; ··· 2949 2912 } 2950 2913 2951 2914 2952 - static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg) 2915 + static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg) 2953 2916 { 2954 2917 struct aac_dev *dev; 2955 2918 unsigned long byte_count = 0; ··· 2964 2927 psg->sg[0].count = 0; 2965 2928 2966 2929 nseg = scsi_dma_map(scsicmd); 2967 - BUG_ON(nseg < 0); 2930 + if (nseg < 0) 2931 + return nseg; 2968 2932 if (nseg) { 2969 2933 struct scatterlist *sg; 2970 2934 int i; ··· 2995 2957 return byte_count; 2996 2958 } 2997 2959 2998 - static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg) 2960 + static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg) 2999 2961 { 3000 2962 unsigned long byte_count = 0; 3001 2963 int nseg; ··· 3010 2972 psg->sg[0].flags = 0; 3011 2973 3012 2974 nseg = scsi_dma_map(scsicmd); 3013 - BUG_ON(nseg < 0); 2975 + if (nseg < 0) 2976 + return nseg; 3014 2977 if (nseg) { 3015 2978 struct scatterlist *sg; 3016 2979 int i; ··· 3044 3005 return byte_count; 3045 3006 } 3046 3007 3047 - static unsigned long aac_build_sgraw2(struct scsi_cmnd *scsicmd, struct aac_raw_io2 *rio2, int sg_max) 3008 + static long aac_build_sgraw2(struct scsi_cmnd *scsicmd, 3009 + struct aac_raw_io2 *rio2, int sg_max) 3048 3010 { 3049 3011 unsigned long byte_count = 0; 3050 3012 int nseg; 3051 3013 3052 3014 nseg = scsi_dma_map(scsicmd); 3053 - BUG_ON(nseg < 0); 3015 + if (nseg < 0) 3016 + return nseg; 3054 3017 if (nseg) { 3055 3018 struct scatterlist *sg; 3056 3019 int i, conformable = 0;
+1 -1
drivers/scsi/aacraid/aacraid.h
··· 12 12 *----------------------------------------------------------------------------*/ 13 13 14 14 #ifndef AAC_DRIVER_BUILD 15 - # define AAC_DRIVER_BUILD 29800 15 + # define AAC_DRIVER_BUILD 29801 16 16 # define AAC_DRIVER_BRANCH "-ms" 17 17 #endif 18 18 #define MAXIMUM_NUM_CONTAINERS 32