tree: https://gitee.com/openeuler/kernel.git openEuler-1.0-LTS head: 992b5fc139d3aa14b25613b06adee4bb9c110b28 commit: d597314e1e561e653a9dbeafec69f20d6b372af1 [4369/21577] scsi: sd: Protect against READ(6) or WRITE(6) with zero block transfer length :::::: branch date: 7 hours ago :::::: commit date: 4 years, 1 month ago config: x86_64-randconfig-121-20240125 (attached as .config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (attached as reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot lkp@intel.com | Closes: https://lore.kernel.org/oe-kbuild-all/202401262223.5mM2ZI39-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
drivers/scsi/sd.c:1222:32: sparse: sparse: incorrect type in return expression (different base types) @@ expected int @@ got restricted blk_status_t [usertype] @@
drivers/scsi/sd.c:1222:32: sparse: expected int drivers/scsi/sd.c:1222:32: sparse: got restricted blk_status_t [usertype] In file included from drivers/scsi/sd.c:46: In file included from include/linux/blkdev.h:16: include/linux/pagemap.h:401:21: warning: cast from 'int (*)(struct file *, struct page *)' to 'filler_t *' (aka 'int (*)(void *, struct page *)') converts to incompatible function type [-Wcast-function-type-strict] 401 | filler_t *filler = (filler_t *)mapping->a_ops->readpage; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.
vim +1222 drivers/scsi/sd.c
90467c294aba7f FUJITA Tomonori 2010-07-03 1019 87949eee7e1547 Christoph Hellwig 2014-06-28 1020 static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) ^1da177e4c3f41 Linus Torvalds 2005-04-16 1021 { a1b73fc194e73e Christoph Hellwig 2014-05-01 1022 struct request *rq = SCpnt->request; a1b73fc194e73e Christoph Hellwig 2014-05-01 1023 struct scsi_device *sdp = SCpnt->device; 776b23a0363d99 Christoph Hellwig 2006-01-06 1024 struct gendisk *disk = rq->rq_disk; 89d9475610771b Hannes Reinecke 2016-10-18 1025 struct scsi_disk *sdkp = scsi_disk(disk); 83096ebf1263b2 Tejun Heo 2009-05-07 1026 sector_t block = blk_rq_pos(rq); 18351070b86d15 Linus Torvalds 2008-08-05 1027 sector_t threshold; 83096ebf1263b2 Tejun Heo 2009-05-07 1028 unsigned int this_count = blk_rq_sectors(rq); d597314e1e561e Bart Van Assche 2019-03-23 1029 unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); c611529e7cd346 Martin K. Petersen 2014-09-26 1030 unsigned int dif, dix; c611529e7cd346 Martin K. Petersen 2014-09-26 1031 int ret; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1032 unsigned char protect; 7f9a6bc4e9d59e James Bottomley 2007-08-04 1033 3c356bde19e9a7 Christoph Hellwig 2014-09-05 1034 ret = scsi_init_io(SCpnt); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1035 if (ret != BLKPREP_OK) 39051dd85f2870 Damien Le Moal 2017-12-21 1036 return ret; 0624cbb1e2e64a Bart Van Assche 2017-08-25 1037 WARN_ON_ONCE(SCpnt != rq->special); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1038 7f9a6bc4e9d59e James Bottomley 2007-08-04 1039 /* from here on until we're complete, any goto out 7f9a6bc4e9d59e James Bottomley 2007-08-04 1040 * is used for a killable error condition */ 7f9a6bc4e9d59e James Bottomley 2007-08-04 1041 ret = BLKPREP_KILL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1042 a1b73fc194e73e Christoph Hellwig 2014-05-01 1043 SCSI_LOG_HLQUEUE(1, a1b73fc194e73e Christoph Hellwig 2014-05-01 1044 scmd_printk(KERN_INFO, SCpnt, a1b73fc194e73e Christoph Hellwig 2014-05-01 1045 "%s: block=%llu, count=%d\n", a1b73fc194e73e Christoph Hellwig 2014-05-01 1046 __func__, (unsigned long long)block, this_count)); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1047 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1048 if (!sdp || !scsi_device_online(sdp) || 83096ebf1263b2 Tejun Heo 2009-05-07 1049 block + blk_rq_sectors(rq) > get_capacity(disk)) { fa0d34be06213e Martin K. Petersen 2007-02-27 1050 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, 83096ebf1263b2 Tejun Heo 2009-05-07 1051 "Finishing %u sectors\n", 83096ebf1263b2 Tejun Heo 2009-05-07 1052 blk_rq_sectors(rq))); fa0d34be06213e Martin K. Petersen 2007-02-27 1053 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, fa0d34be06213e Martin K. Petersen 2007-02-27 1054 "Retry with 0x%p\n", SCpnt)); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1055 goto out; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1056 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1057 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1058 if (sdp->changed) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1059 /* ^1da177e4c3f41 Linus Torvalds 2005-04-16 1060 * quietly refuse to do anything to a changed disc until ^1da177e4c3f41 Linus Torvalds 2005-04-16 1061 * the changed bit has been reset ^1da177e4c3f41 Linus Torvalds 2005-04-16 1062 */ 3ff5588d3f8afa Alan Stern 2010-09-07 1063 /* printk("SCSI disk has been changed or is not present. Prohibiting further I/O.\n"); */ 7f9a6bc4e9d59e James Bottomley 2007-08-04 1064 goto out; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1065 } 7f9a6bc4e9d59e James Bottomley 2007-08-04 1066 a0899d4df534d2 Hans de Goede 2008-01-20 1067 /* 18351070b86d15 Linus Torvalds 2008-08-05 1068 * Some SD card readers can't handle multi-sector accesses which touch 18351070b86d15 Linus Torvalds 2008-08-05 1069 * the last one or two hardware sectors. Split accesses as needed. a0899d4df534d2 Hans de Goede 2008-01-20 1070 */ 18351070b86d15 Linus Torvalds 2008-08-05 1071 threshold = get_capacity(disk) - SD_LAST_BUGGY_SECTORS * 18351070b86d15 Linus Torvalds 2008-08-05 1072 (sdp->sector_size / 512); 18351070b86d15 Linus Torvalds 2008-08-05 1073 18351070b86d15 Linus Torvalds 2008-08-05 1074 if (unlikely(sdp->last_sector_bug && block + this_count > threshold)) { 18351070b86d15 Linus Torvalds 2008-08-05 1075 if (block < threshold) { 18351070b86d15 Linus Torvalds 2008-08-05 1076 /* Access up to the threshold but not beyond */ 18351070b86d15 Linus Torvalds 2008-08-05 1077 this_count = threshold - block; 18351070b86d15 Linus Torvalds 2008-08-05 1078 } else { 18351070b86d15 Linus Torvalds 2008-08-05 1079 /* Access only a single hardware sector */ 18351070b86d15 Linus Torvalds 2008-08-05 1080 this_count = sdp->sector_size / 512; 18351070b86d15 Linus Torvalds 2008-08-05 1081 } 18351070b86d15 Linus Torvalds 2008-08-05 1082 } a0899d4df534d2 Hans de Goede 2008-01-20 1083 fa0d34be06213e Martin K. Petersen 2007-02-27 1084 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "block=%llu\n", fa0d34be06213e Martin K. Petersen 2007-02-27 1085 (unsigned long long)block)); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1086 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1087 /* ^1da177e4c3f41 Linus Torvalds 2005-04-16 1088 * If we have a 1K hardware sectorsize, prevent access to single ^1da177e4c3f41 Linus Torvalds 2005-04-16 1089 * 512 byte sectors. In theory we could handle this - in fact ^1da177e4c3f41 Linus Torvalds 2005-04-16 1090 * the scsi cdrom driver must be able to handle this because ^1da177e4c3f41 Linus Torvalds 2005-04-16 1091 * we typically use 1K blocksizes, and cdroms typically have ^1da177e4c3f41 Linus Torvalds 2005-04-16 1092 * 2K hardware sectorsizes. Of course, things are simpler ^1da177e4c3f41 Linus Torvalds 2005-04-16 1093 * with the cdrom, since it is read-only. For performance ^1da177e4c3f41 Linus Torvalds 2005-04-16 1094 * reasons, the filesystems should be able to handle this ^1da177e4c3f41 Linus Torvalds 2005-04-16 1095 * and not force the scsi disk driver to use bounce buffers ^1da177e4c3f41 Linus Torvalds 2005-04-16 1096 * for this. ^1da177e4c3f41 Linus Torvalds 2005-04-16 1097 */ ^1da177e4c3f41 Linus Torvalds 2005-04-16 1098 if (sdp->sector_size == 1024) { 83096ebf1263b2 Tejun Heo 2009-05-07 1099 if ((block & 1) || (blk_rq_sectors(rq) & 1)) { e73aec8247032e Martin K. Petersen 2007-02-27 1100 scmd_printk(KERN_ERR, SCpnt, e73aec8247032e Martin K. Petersen 2007-02-27 1101 "Bad block number requested\n"); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1102 goto out; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1103 } else { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1104 block = block >> 1; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1105 this_count = this_count >> 1; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1106 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1107 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1108 if (sdp->sector_size == 2048) { 83096ebf1263b2 Tejun Heo 2009-05-07 1109 if ((block & 3) || (blk_rq_sectors(rq) & 3)) { e73aec8247032e Martin K. Petersen 2007-02-27 1110 scmd_printk(KERN_ERR, SCpnt, e73aec8247032e Martin K. Petersen 2007-02-27 1111 "Bad block number requested\n"); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1112 goto out; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1113 } else { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1114 block = block >> 2; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1115 this_count = this_count >> 2; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1116 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1117 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1118 if (sdp->sector_size == 4096) { 83096ebf1263b2 Tejun Heo 2009-05-07 1119 if ((block & 7) || (blk_rq_sectors(rq) & 7)) { e73aec8247032e Martin K. Petersen 2007-02-27 1120 scmd_printk(KERN_ERR, SCpnt, e73aec8247032e Martin K. Petersen 2007-02-27 1121 "Bad block number requested\n"); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1122 goto out; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1123 } else { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1124 block = block >> 3; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1125 this_count = this_count >> 3; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1126 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1127 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1128 if (rq_data_dir(rq) == WRITE) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1129 SCpnt->cmnd[0] = WRITE_6; af55ff675a8461 Martin K. Petersen 2008-07-17 1130 8c579ab69d50a4 Martin K. Petersen 2012-08-28 1131 if (blk_integrity_rq(rq)) 10c41ddd61323b Max Gurtovoy 2018-07-30 1132 t10_pi_prepare(SCpnt->request, sdkp->protection_type); af55ff675a8461 Martin K. Petersen 2008-07-17 1133 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1134 } else if (rq_data_dir(rq) == READ) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1135 SCpnt->cmnd[0] = READ_6; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1136 } else { ef295ecf090d3e Christoph Hellwig 2016-10-28 1137 scmd_printk(KERN_ERR, SCpnt, "Unknown command %d\n", req_op(rq)); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1138 goto out; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1139 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1140 fa0d34be06213e Martin K. Petersen 2007-02-27 1141 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, 83096ebf1263b2 Tejun Heo 2009-05-07 1142 "%s %d/%u 512 byte blocks.\n", fa0d34be06213e Martin K. Petersen 2007-02-27 1143 (rq_data_dir(rq) == WRITE) ? fa0d34be06213e Martin K. Petersen 2007-02-27 1144 "writing" : "reading", this_count, 83096ebf1263b2 Tejun Heo 2009-05-07 1145 blk_rq_sectors(rq))); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1146 c611529e7cd346 Martin K. Petersen 2014-09-26 1147 dix = scsi_prot_sg_count(SCpnt); c611529e7cd346 Martin K. Petersen 2014-09-26 1148 dif = scsi_host_dif_capable(SCpnt->device->host, sdkp->protection_type); c611529e7cd346 Martin K. Petersen 2014-09-26 1149 c611529e7cd346 Martin K. Petersen 2014-09-26 1150 if (dif || dix) c611529e7cd346 Martin K. Petersen 2014-09-26 1151 protect = sd_setup_protect_cmnd(SCpnt, dix, dif); af55ff675a8461 Martin K. Petersen 2008-07-17 1152 else 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1153 protect = 0; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1154 8475c8118551f8 Christoph Hellwig 2016-09-11 1155 if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1156 SCpnt->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC); 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1157 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1158 if (unlikely(SCpnt->cmnd == NULL)) { 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1159 ret = BLKPREP_DEFER; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1160 goto out; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1161 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1162 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1163 SCpnt->cmd_len = SD_EXT_CDB_SIZE; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1164 memset(SCpnt->cmnd, 0, SCpnt->cmd_len); 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1165 SCpnt->cmnd[0] = VARIABLE_LENGTH_CMD; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1166 SCpnt->cmnd[7] = 0x18; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1167 SCpnt->cmnd[9] = (rq_data_dir(rq) == READ) ? READ_32 : WRITE_32; 33659ebbae2622 Christoph Hellwig 2010-08-07 1168 SCpnt->cmnd[10] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1169 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1170 /* LBA */ 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1171 SCpnt->cmnd[12] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1172 SCpnt->cmnd[13] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1173 SCpnt->cmnd[14] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1174 SCpnt->cmnd[15] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1175 SCpnt->cmnd[16] = (unsigned char) (block >> 24) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1176 SCpnt->cmnd[17] = (unsigned char) (block >> 16) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1177 SCpnt->cmnd[18] = (unsigned char) (block >> 8) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1178 SCpnt->cmnd[19] = (unsigned char) block & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1179 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1180 /* Expected Indirect LBA */ 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1181 SCpnt->cmnd[20] = (unsigned char) (block >> 24) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1182 SCpnt->cmnd[21] = (unsigned char) (block >> 16) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1183 SCpnt->cmnd[22] = (unsigned char) (block >> 8) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1184 SCpnt->cmnd[23] = (unsigned char) block & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1185 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1186 /* Transfer length */ 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1187 SCpnt->cmnd[28] = (unsigned char) (this_count >> 24) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1188 SCpnt->cmnd[29] = (unsigned char) (this_count >> 16) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1189 SCpnt->cmnd[30] = (unsigned char) (this_count >> 8) & 0xff; 4e7392ec582cf0 Martin K. Petersen 2009-09-20 1190 SCpnt->cmnd[31] = (unsigned char) this_count & 0xff; e430cbc8bbd779 Akinobu Mita 2014-06-02 1191 } else if (sdp->use_16_for_rw || (this_count > 0xffff)) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1192 SCpnt->cmnd[0] += READ_16 - READ_6; 33659ebbae2622 Christoph Hellwig 2010-08-07 1193 SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1194 SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1195 SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1196 SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1197 SCpnt->cmnd[5] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1198 SCpnt->cmnd[6] = (unsigned char) (block >> 24) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1199 SCpnt->cmnd[7] = (unsigned char) (block >> 16) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1200 SCpnt->cmnd[8] = (unsigned char) (block >> 8) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1201 SCpnt->cmnd[9] = (unsigned char) block & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1202 SCpnt->cmnd[10] = (unsigned char) (this_count >> 24) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1203 SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1204 SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1205 SCpnt->cmnd[13] = (unsigned char) this_count & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1206 SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1207 } else if ((this_count > 0xff) || (block > 0x1fffff) || af55ff675a8461 Martin K. Petersen 2008-07-17 1208 scsi_device_protection(SCpnt->device) || ^1da177e4c3f41 Linus Torvalds 2005-04-16 1209 SCpnt->device->use_10_for_rw) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 1210 SCpnt->cmnd[0] += READ_10 - READ_6; 33659ebbae2622 Christoph Hellwig 2010-08-07 1211 SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1212 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1213 SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1214 SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1215 SCpnt->cmnd[5] = (unsigned char) block & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1216 SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1217 SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1218 SCpnt->cmnd[8] = (unsigned char) this_count & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1219 } else { d597314e1e561e Bart Van Assche 2019-03-23 1220 /* Avoid that 0 blocks gets translated into 256 blocks. */ d597314e1e561e Bart Van Assche 2019-03-23 1221 if (WARN_ON_ONCE(nr_blocks == 0)) d597314e1e561e Bart Van Assche 2019-03-23 @1222 return BLK_STS_IOERR; d597314e1e561e Bart Van Assche 2019-03-23 1223 33659ebbae2622 Christoph Hellwig 2010-08-07 1224 if (unlikely(rq->cmd_flags & REQ_FUA)) { 007365ad60387d Tejun Heo 2006-01-06 1225 /* 007365ad60387d Tejun Heo 2006-01-06 1226 * This happens only if this drive failed 007365ad60387d Tejun Heo 2006-01-06 1227 * 10byte rw command with ILLEGAL_REQUEST 007365ad60387d Tejun Heo 2006-01-06 1228 * during operation and thus turned off 007365ad60387d Tejun Heo 2006-01-06 1229 * use_10_for_rw. 007365ad60387d Tejun Heo 2006-01-06 1230 */ e73aec8247032e Martin K. Petersen 2007-02-27 1231 scmd_printk(KERN_ERR, SCpnt, e73aec8247032e Martin K. Petersen 2007-02-27 1232 "FUA write on READ/WRITE(6) drive\n"); 7f9a6bc4e9d59e James Bottomley 2007-08-04 1233 goto out; 007365ad60387d Tejun Heo 2006-01-06 1234 } 007365ad60387d Tejun Heo 2006-01-06 1235 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1236 SCpnt->cmnd[1] |= (unsigned char) ((block >> 16) & 0x1f); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1237 SCpnt->cmnd[2] = (unsigned char) ((block >> 8) & 0xff); ^1da177e4c3f41 Linus Torvalds 2005-04-16 1238 SCpnt->cmnd[3] = (unsigned char) block & 0xff; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1239 SCpnt->cmnd[4] = (unsigned char) this_count; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1240 SCpnt->cmnd[5] = 0; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1241 } 30b0c37b27485a Boaz Harrosh 2007-12-13 1242 SCpnt->sdb.length = this_count * sdp->sector_size; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1243 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1244 /* ^1da177e4c3f41 Linus Torvalds 2005-04-16 1245 * We shouldn't disconnect in the middle of a sector, so with a dumb ^1da177e4c3f41 Linus Torvalds 2005-04-16 1246 * host adapter, it's safe to assume that we can at least transfer ^1da177e4c3f41 Linus Torvalds 2005-04-16 1247 * this many bytes between each connect / disconnect. ^1da177e4c3f41 Linus Torvalds 2005-04-16 1248 */ ^1da177e4c3f41 Linus Torvalds 2005-04-16 1249 SCpnt->transfersize = sdp->sector_size; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1250 SCpnt->underflow = this_count << 9; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1251 SCpnt->allowed = SD_MAX_RETRIES; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1252 ^1da177e4c3f41 Linus Torvalds 2005-04-16 1253 /* ^1da177e4c3f41 Linus Torvalds 2005-04-16 1254 * This indicates that the command is ready from our end to be ^1da177e4c3f41 Linus Torvalds 2005-04-16 1255 * queued. ^1da177e4c3f41 Linus Torvalds 2005-04-16 1256 */ 7f9a6bc4e9d59e James Bottomley 2007-08-04 1257 ret = BLKPREP_OK; 7f9a6bc4e9d59e James Bottomley 2007-08-04 1258 out: a1b73fc194e73e Christoph Hellwig 2014-05-01 1259 return ret; ^1da177e4c3f41 Linus Torvalds 2005-04-16 1260 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 1261