We can only have one page of data in each sg element, so we can not cross a page boundary. Fail this case. The 'while (len > 0 && data_len > 0) {}' loop is not necessary. The loop can only be executed once.
Unified · Split
| @@ -883,7 +883,14 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, · 882 unmodified lines | ||
| 883 | 883 | pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i, |
| 884 | 884 | page, len, off); |
| 885 | 885 | |
| 886 | − while (len > 0 && data_len > 0) { | |
| 886 | + /* | |
| 887 | + * We only have one page of data in each sg element, | |
| 888 | + * we can not cross a page boundary. | |
| 889 | + */ | |
| 890 | + if (off + len > PAGE_SIZE) | |
| 891 | + goto fail; | |
| 892 | + | |
| 893 | + if (len > 0 && data_len > 0) { | |
| 887 | 894 | bytes = min_t(unsigned int, len, PAGE_SIZE - off); |
| 888 | 895 | bytes = min(bytes, data_len); |
| 889 | 896 | |
| @@ -940,9 +947,7 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, · 50 unmodified lines | ||
| 940 | 947 | bio = NULL; |
| 941 | 948 | } |
| 942 | 949 | |
| 943 | − len -= bytes; | |
| 944 | 950 | data_len -= bytes; |
| 945 | − off = 0; | |
| 946 | 951 | } |
| 947 | 952 | } |
| 948 | 953 | |