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

s390/zcrypt: replace snprintf/sprintf with scnprintf

snprintf() may not always return the correct size of used bytes but
instead the length the resulting string would be if it would fit into
the buffer. So scnprintf() is the function to use when the real length
of the resulting string is needed.

Replace all occurrences of snprintf() with scnprintf() where the return
code is further processed. Also find and fix some occurrences where
sprintf() was used.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

authored by

Harald Freudenberger and committed by
Vasily Gorbik
40501c70 eb3e064b

+76 -75
+36 -36
drivers/s390/crypto/ap_bus.c
··· 1021 1021 1022 1022 static ssize_t ap_domain_show(struct bus_type *bus, char *buf) 1023 1023 { 1024 - return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index); 1024 + return scnprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index); 1025 1025 } 1026 1026 1027 1027 static ssize_t ap_domain_store(struct bus_type *bus, ··· 1047 1047 static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf) 1048 1048 { 1049 1049 if (!ap_configuration) /* QCI not supported */ 1050 - return snprintf(buf, PAGE_SIZE, "not supported\n"); 1050 + return scnprintf(buf, PAGE_SIZE, "not supported\n"); 1051 1051 1052 - return snprintf(buf, PAGE_SIZE, 1053 - "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1054 - ap_configuration->adm[0], ap_configuration->adm[1], 1055 - ap_configuration->adm[2], ap_configuration->adm[3], 1056 - ap_configuration->adm[4], ap_configuration->adm[5], 1057 - ap_configuration->adm[6], ap_configuration->adm[7]); 1052 + return scnprintf(buf, PAGE_SIZE, 1053 + "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1054 + ap_configuration->adm[0], ap_configuration->adm[1], 1055 + ap_configuration->adm[2], ap_configuration->adm[3], 1056 + ap_configuration->adm[4], ap_configuration->adm[5], 1057 + ap_configuration->adm[6], ap_configuration->adm[7]); 1058 1058 } 1059 1059 1060 1060 static BUS_ATTR_RO(ap_control_domain_mask); ··· 1062 1062 static ssize_t ap_usage_domain_mask_show(struct bus_type *bus, char *buf) 1063 1063 { 1064 1064 if (!ap_configuration) /* QCI not supported */ 1065 - return snprintf(buf, PAGE_SIZE, "not supported\n"); 1065 + return scnprintf(buf, PAGE_SIZE, "not supported\n"); 1066 1066 1067 - return snprintf(buf, PAGE_SIZE, 1068 - "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1069 - ap_configuration->aqm[0], ap_configuration->aqm[1], 1070 - ap_configuration->aqm[2], ap_configuration->aqm[3], 1071 - ap_configuration->aqm[4], ap_configuration->aqm[5], 1072 - ap_configuration->aqm[6], ap_configuration->aqm[7]); 1067 + return scnprintf(buf, PAGE_SIZE, 1068 + "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1069 + ap_configuration->aqm[0], ap_configuration->aqm[1], 1070 + ap_configuration->aqm[2], ap_configuration->aqm[3], 1071 + ap_configuration->aqm[4], ap_configuration->aqm[5], 1072 + ap_configuration->aqm[6], ap_configuration->aqm[7]); 1073 1073 } 1074 1074 1075 1075 static BUS_ATTR_RO(ap_usage_domain_mask); ··· 1077 1077 static ssize_t ap_adapter_mask_show(struct bus_type *bus, char *buf) 1078 1078 { 1079 1079 if (!ap_configuration) /* QCI not supported */ 1080 - return snprintf(buf, PAGE_SIZE, "not supported\n"); 1080 + return scnprintf(buf, PAGE_SIZE, "not supported\n"); 1081 1081 1082 - return snprintf(buf, PAGE_SIZE, 1083 - "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1084 - ap_configuration->apm[0], ap_configuration->apm[1], 1085 - ap_configuration->apm[2], ap_configuration->apm[3], 1086 - ap_configuration->apm[4], ap_configuration->apm[5], 1087 - ap_configuration->apm[6], ap_configuration->apm[7]); 1082 + return scnprintf(buf, PAGE_SIZE, 1083 + "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", 1084 + ap_configuration->apm[0], ap_configuration->apm[1], 1085 + ap_configuration->apm[2], ap_configuration->apm[3], 1086 + ap_configuration->apm[4], ap_configuration->apm[5], 1087 + ap_configuration->apm[6], ap_configuration->apm[7]); 1088 1088 } 1089 1089 1090 1090 static BUS_ATTR_RO(ap_adapter_mask); 1091 1091 1092 1092 static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf) 1093 1093 { 1094 - return snprintf(buf, PAGE_SIZE, "%d\n", 1095 - ap_using_interrupts() ? 1 : 0); 1094 + return scnprintf(buf, PAGE_SIZE, "%d\n", 1095 + ap_using_interrupts() ? 1 : 0); 1096 1096 } 1097 1097 1098 1098 static BUS_ATTR_RO(ap_interrupts); 1099 1099 1100 1100 static ssize_t config_time_show(struct bus_type *bus, char *buf) 1101 1101 { 1102 - return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time); 1102 + return scnprintf(buf, PAGE_SIZE, "%d\n", ap_config_time); 1103 1103 } 1104 1104 1105 1105 static ssize_t config_time_store(struct bus_type *bus, ··· 1118 1118 1119 1119 static ssize_t poll_thread_show(struct bus_type *bus, char *buf) 1120 1120 { 1121 - return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0); 1121 + return scnprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0); 1122 1122 } 1123 1123 1124 1124 static ssize_t poll_thread_store(struct bus_type *bus, ··· 1141 1141 1142 1142 static ssize_t poll_timeout_show(struct bus_type *bus, char *buf) 1143 1143 { 1144 - return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout); 1144 + return scnprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout); 1145 1145 } 1146 1146 1147 1147 static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf, ··· 1176 1176 max_domain_id = ap_max_domain_id ? : -1; 1177 1177 else 1178 1178 max_domain_id = 15; 1179 - return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id); 1179 + return scnprintf(buf, PAGE_SIZE, "%d\n", max_domain_id); 1180 1180 } 1181 1181 1182 1182 static BUS_ATTR_RO(ap_max_domain_id); ··· 1187 1187 1188 1188 if (mutex_lock_interruptible(&ap_perms_mutex)) 1189 1189 return -ERESTARTSYS; 1190 - rc = snprintf(buf, PAGE_SIZE, 1191 - "0x%016lx%016lx%016lx%016lx\n", 1192 - ap_perms.apm[0], ap_perms.apm[1], 1193 - ap_perms.apm[2], ap_perms.apm[3]); 1190 + rc = scnprintf(buf, PAGE_SIZE, 1191 + "0x%016lx%016lx%016lx%016lx\n", 1192 + ap_perms.apm[0], ap_perms.apm[1], 1193 + ap_perms.apm[2], ap_perms.apm[3]); 1194 1194 mutex_unlock(&ap_perms_mutex); 1195 1195 1196 1196 return rc; ··· 1218 1218 1219 1219 if (mutex_lock_interruptible(&ap_perms_mutex)) 1220 1220 return -ERESTARTSYS; 1221 - rc = snprintf(buf, PAGE_SIZE, 1222 - "0x%016lx%016lx%016lx%016lx\n", 1223 - ap_perms.aqm[0], ap_perms.aqm[1], 1224 - ap_perms.aqm[2], ap_perms.aqm[3]); 1221 + rc = scnprintf(buf, PAGE_SIZE, 1222 + "0x%016lx%016lx%016lx%016lx\n", 1223 + ap_perms.aqm[0], ap_perms.aqm[1], 1224 + ap_perms.aqm[2], ap_perms.aqm[3]); 1225 1225 mutex_unlock(&ap_perms_mutex); 1226 1226 1227 1227 return rc;
+9 -8
drivers/s390/crypto/ap_card.c
··· 23 23 { 24 24 struct ap_card *ac = to_ap_card(dev); 25 25 26 - return snprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type); 26 + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type); 27 27 } 28 28 29 29 static DEVICE_ATTR_RO(hwtype); ··· 33 33 { 34 34 struct ap_card *ac = to_ap_card(dev); 35 35 36 - return snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype); 36 + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype); 37 37 } 38 38 39 39 static DEVICE_ATTR_RO(raw_hwtype); ··· 43 43 { 44 44 struct ap_card *ac = to_ap_card(dev); 45 45 46 - return snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth); 46 + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth); 47 47 } 48 48 49 49 static DEVICE_ATTR_RO(depth); ··· 53 53 { 54 54 struct ap_card *ac = to_ap_card(dev); 55 55 56 - return snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions); 56 + return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions); 57 57 } 58 58 59 59 static DEVICE_ATTR_RO(ap_functions); ··· 69 69 spin_lock_bh(&ap_list_lock); 70 70 req_cnt = atomic64_read(&ac->total_request_count); 71 71 spin_unlock_bh(&ap_list_lock); 72 - return snprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 72 + return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 73 73 } 74 74 75 75 static ssize_t request_count_store(struct device *dev, ··· 102 102 for_each_ap_queue(aq, ac) 103 103 reqq_cnt += aq->requestq_count; 104 104 spin_unlock_bh(&ap_list_lock); 105 - return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 105 + return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 106 106 } 107 107 108 108 static DEVICE_ATTR_RO(requestq_count); ··· 119 119 for_each_ap_queue(aq, ac) 120 120 penq_cnt += aq->pendingq_count; 121 121 spin_unlock_bh(&ap_list_lock); 122 - return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 122 + return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 123 123 } 124 124 125 125 static DEVICE_ATTR_RO(pendingq_count); ··· 127 127 static ssize_t modalias_show(struct device *dev, 128 128 struct device_attribute *attr, char *buf) 129 129 { 130 - return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type); 130 + return scnprintf(buf, PAGE_SIZE, "ap:t%02X\n", 131 + to_ap_dev(dev)->device_type); 131 132 } 132 133 133 134 static DEVICE_ATTR_RO(modalias);
+9 -9
drivers/s390/crypto/ap_queue.c
··· 484 484 spin_lock_bh(&aq->lock); 485 485 req_cnt = aq->total_request_count; 486 486 spin_unlock_bh(&aq->lock); 487 - return snprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 487 + return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); 488 488 } 489 489 490 490 static ssize_t request_count_store(struct device *dev, ··· 511 511 spin_lock_bh(&aq->lock); 512 512 reqq_cnt = aq->requestq_count; 513 513 spin_unlock_bh(&aq->lock); 514 - return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 514 + return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); 515 515 } 516 516 517 517 static DEVICE_ATTR_RO(requestq_count); ··· 525 525 spin_lock_bh(&aq->lock); 526 526 penq_cnt = aq->pendingq_count; 527 527 spin_unlock_bh(&aq->lock); 528 - return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 528 + return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); 529 529 } 530 530 531 531 static DEVICE_ATTR_RO(pendingq_count); ··· 540 540 switch (aq->state) { 541 541 case AP_STATE_RESET_START: 542 542 case AP_STATE_RESET_WAIT: 543 - rc = snprintf(buf, PAGE_SIZE, "Reset in progress.\n"); 543 + rc = scnprintf(buf, PAGE_SIZE, "Reset in progress.\n"); 544 544 break; 545 545 case AP_STATE_WORKING: 546 546 case AP_STATE_QUEUE_FULL: 547 - rc = snprintf(buf, PAGE_SIZE, "Reset Timer armed.\n"); 547 + rc = scnprintf(buf, PAGE_SIZE, "Reset Timer armed.\n"); 548 548 break; 549 549 default: 550 - rc = snprintf(buf, PAGE_SIZE, "No Reset Timer set.\n"); 550 + rc = scnprintf(buf, PAGE_SIZE, "No Reset Timer set.\n"); 551 551 } 552 552 spin_unlock_bh(&aq->lock); 553 553 return rc; ··· 581 581 582 582 spin_lock_bh(&aq->lock); 583 583 if (aq->state == AP_STATE_SETIRQ_WAIT) 584 - rc = snprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n"); 584 + rc = scnprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n"); 585 585 else if (aq->interrupt == AP_INTR_ENABLED) 586 - rc = snprintf(buf, PAGE_SIZE, "Interrupts enabled.\n"); 586 + rc = scnprintf(buf, PAGE_SIZE, "Interrupts enabled.\n"); 587 587 else 588 - rc = snprintf(buf, PAGE_SIZE, "Interrupts disabled.\n"); 588 + rc = scnprintf(buf, PAGE_SIZE, "Interrupts disabled.\n"); 589 589 spin_unlock_bh(&aq->lock); 590 590 return rc; 591 591 }
+3 -3
drivers/s390/crypto/zcrypt_card.c
··· 41 41 { 42 42 struct zcrypt_card *zc = to_ap_card(dev)->private; 43 43 44 - return snprintf(buf, PAGE_SIZE, "%s\n", zc->type_string); 44 + return scnprintf(buf, PAGE_SIZE, "%s\n", zc->type_string); 45 45 } 46 46 47 47 static DEVICE_ATTR_RO(type); ··· 52 52 { 53 53 struct zcrypt_card *zc = to_ap_card(dev)->private; 54 54 55 - return snprintf(buf, PAGE_SIZE, "%d\n", zc->online); 55 + return scnprintf(buf, PAGE_SIZE, "%d\n", zc->online); 56 56 } 57 57 58 58 static ssize_t online_store(struct device *dev, ··· 86 86 { 87 87 struct zcrypt_card *zc = to_ap_card(dev)->private; 88 88 89 - return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load)); 89 + return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load)); 90 90 } 91 91 92 92 static DEVICE_ATTR_RO(load);
+17 -17
drivers/s390/crypto/zcrypt_cex4.c
··· 87 87 if (ap_domain_index >= 0) 88 88 cca_get_info(ac->id, ap_domain_index, &ci, zc->online); 89 89 90 - return snprintf(buf, PAGE_SIZE, "%s\n", ci.serial); 90 + return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial); 91 91 } 92 92 93 93 static struct device_attribute dev_attr_cca_serialnr = ··· 122 122 &ci, zq->online); 123 123 124 124 if (ci.new_mk_state >= '1' && ci.new_mk_state <= '3') 125 - n = snprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n", 126 - new_state[ci.new_mk_state - '1'], ci.new_mkvp); 125 + n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n", 126 + new_state[ci.new_mk_state - '1'], ci.new_mkvp); 127 127 else 128 - n = snprintf(buf, PAGE_SIZE, "AES NEW: - -\n"); 128 + n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n"); 129 129 130 130 if (ci.cur_mk_state >= '1' && ci.cur_mk_state <= '2') 131 131 n += scnprintf(buf + n, PAGE_SIZE - n, ··· 172 172 ep11_get_card_info(ac->id, &ci, zc->online); 173 173 174 174 if (ci.API_ord_nr > 0) 175 - return snprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr); 175 + return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr); 176 176 else 177 - return snprintf(buf, PAGE_SIZE, "\n"); 177 + return scnprintf(buf, PAGE_SIZE, "\n"); 178 178 } 179 179 180 180 static struct device_attribute dev_attr_ep11_api_ordinalnr = ··· 193 193 ep11_get_card_info(ac->id, &ci, zc->online); 194 194 195 195 if (ci.FW_version > 0) 196 - return snprintf(buf, PAGE_SIZE, "%d.%d\n", 197 - (int)(ci.FW_version >> 8), 198 - (int)(ci.FW_version & 0xFF)); 196 + return scnprintf(buf, PAGE_SIZE, "%d.%d\n", 197 + (int)(ci.FW_version >> 8), 198 + (int)(ci.FW_version & 0xFF)); 199 199 else 200 - return snprintf(buf, PAGE_SIZE, "\n"); 200 + return scnprintf(buf, PAGE_SIZE, "\n"); 201 201 } 202 202 203 203 static struct device_attribute dev_attr_ep11_fw_version = ··· 216 216 ep11_get_card_info(ac->id, &ci, zc->online); 217 217 218 218 if (ci.serial[0]) 219 - return snprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial); 219 + return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial); 220 220 else 221 - return snprintf(buf, PAGE_SIZE, "\n"); 221 + return scnprintf(buf, PAGE_SIZE, "\n"); 222 222 } 223 223 224 224 static struct device_attribute dev_attr_ep11_serialnr = ··· 300 300 &di); 301 301 302 302 if (di.cur_wk_state == '0') { 303 - n = snprintf(buf, PAGE_SIZE, "WK CUR: %s -\n", 304 - cwk_state[di.cur_wk_state - '0']); 303 + n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s -\n", 304 + cwk_state[di.cur_wk_state - '0']); 305 305 } else if (di.cur_wk_state == '1') { 306 - n = snprintf(buf, PAGE_SIZE, "WK CUR: %s 0x", 307 - cwk_state[di.cur_wk_state - '0']); 306 + n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s 0x", 307 + cwk_state[di.cur_wk_state - '0']); 308 308 bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp)); 309 309 n += 2 * sizeof(di.cur_wkvp); 310 310 n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); 311 311 } else 312 - n = snprintf(buf, PAGE_SIZE, "WK CUR: - -\n"); 312 + n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n"); 313 313 314 314 if (di.new_wk_state == '0') { 315 315 n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s -\n",
+2 -2
drivers/s390/crypto/zcrypt_queue.c
··· 42 42 { 43 43 struct zcrypt_queue *zq = to_ap_queue(dev)->private; 44 44 45 - return snprintf(buf, PAGE_SIZE, "%d\n", zq->online); 45 + return scnprintf(buf, PAGE_SIZE, "%d\n", zq->online); 46 46 } 47 47 48 48 static ssize_t online_store(struct device *dev, ··· 78 78 { 79 79 struct zcrypt_queue *zq = to_ap_queue(dev)->private; 80 80 81 - return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load)); 81 + return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load)); 82 82 } 83 83 84 84 static DEVICE_ATTR_RO(load);