Blame SOURCES/hdparm-9.62-dco_max_sector_calculation.patch

e69b29
diff -ruN hdparm-9.54/hdparm.c hdparm-9.54/hdparm.c
e69b29
--- hdparm-9.54/hdparm.c	2021-04-26 15:05:54.000000000 +0100
e69b29
+++ hdparm-9.54/hdparm.c	2021-05-10 15:58:14.000000000 +0100
e69b29
@@ -1352,8 +1352,8 @@
e69b29
 			if (verbose)
e69b29
 				printf("GET_NATIVE_MAX_ADDRESS_EXT response: hob={%02x %02x %02x} lob={%02x %02x %02x}\n",
e69b29
 					   r.hob.lbah, r.hob.lbam, r.hob.lbal, r.lob.lbah, r.lob.lbam, r.lob.lbal);
e69b29
-			max = (((__u64)((r.hob.lbah << 16) | (r.hob.lbam << 8) | r.hob.lbal) << 24)
e69b29
-				   | ((r.lob.lbah << 16) | (r.lob.lbam << 8) | r.lob.lbal)) + 1;
e69b29
+			max = (((__u64)((r.hob.lbah << 16) | ((__u64)(r.hob.lbam << 8) | r.hob.lbal)) << 24)
e69b29
+				   | (__u64)((r.lob.lbah << 16) | (r.lob.lbam << 8) | r.lob.lbal)) + 1;
e69b29
 		}
e69b29
 	} else { // ACS2 or below, or optional AMAX not present
e69b29
 		if (SUPPORTS_48BIT_ADDR(id)) {
e69b29
@@ -1371,7 +1371,7 @@
e69b29
 					printf("READ_NATIVE_MAX_ADDRESS_EXT response: hob={%02x %02x %02x} lob={%02x %02x %02x}\n",
e69b29
 						r.hob.lbah, r.hob.lbam, r.hob.lbal, r.lob.lbah, r.lob.lbam, r.lob.lbal);
e69b29
 				max = (((__u64)((r.hob.lbah << 16) | (r.hob.lbam << 8) | r.hob.lbal) << 24)
e69b29
-				     	| ((r.lob.lbah << 16) | (r.lob.lbam << 8) | r.lob.lbal)) + 1;
e69b29
+				     	| ((__u64)(r.lob.lbah << 16) | (r.lob.lbam << 8) | r.lob.lbal)) + 1;
e69b29
 			}
e69b29
 		} else {
e69b29
 			/* DEVICE (3:0) / LBA (27:24) "remap" does NOT apply in ATA Status Return */
e69b29
@@ -1556,7 +1556,7 @@
e69b29
 	for (i = 0; i < nranges; ++i) {
e69b29
 		nsectors += sr->nsectors;
e69b29
 		range = sr->nsectors;
e69b29
-		range = (range << 48) | sr->lba;
e69b29
+		range = (__u64)(range << 48) | sr->lba;
e69b29
 		data[i] = __cpu_to_le64(range);
e69b29
 		++sr;
e69b29
 	}
e69b29
@@ -1742,7 +1742,7 @@
e69b29
 			err = errno;
e69b29
 			fprintf(stderr, "stdin: error at lba:count pair #%d: %s\n", (total_ranges + 1), strerror(err));
e69b29
 		} else {
e69b29
-			range = (nsect << 48) | lba;
e69b29
+			range = (__u64)(nsect << 48) | lba;
e69b29
 			nsectors += nsect;
e69b29
 			data[nranges++] = __cpu_to_le64(range);
e69b29
 			if (nranges == max_ranges) {
e69b29
@@ -2807,7 +2807,7 @@
e69b29
 					__u16 *dco = get_dco_identify_data(fd, 1);
e69b29
 					if (dco) {
e69b29
 						__u64 dco_max = dco[5];
e69b29
-						dco_max = ((((__u64)dco[5]) << 32) | (dco[4] << 16) | dco[3]) + 1;
e69b29
+						dco_max = ((((__u64)dco[5]) << 32) | ((__u64)dco[4] << 16) | (__u64)dco[3]) + 1;
e69b29
 						printf("(%llu?)", dco_max);
e69b29
 					}
e69b29
 					printf(", HPA setting seems invalid");
e69b29
diff -ruN hdparm-9.61/identify.c hdparm-9.62/identify.c
e69b29
--- hdparm-9.43/identify.c	2021-04-26 14:47:24.000000000 +0100
e69b29
+++ hdparm-9.43/identify.c	2021-05-10 15:51:23.000000000 +0100
e69b29
@@ -1531,7 +1531,7 @@
e69b29
 	else if (dco[2] & (1<<0)) printf(" udma0");
e69b29
 	putchar('\n');
e69b29
e69b29
-	lba = ((((__u64)dco[5]) << 32) | (dco[4] << 16) | dco[3]) + 1;
e69b29
+	lba = ((((__u64)dco[5]) << 32) | ((__u64)dco[4] << 16) | (__u64)dco[3]) + 1;
e69b29
 	printf("\tReal max sectors: %llu\n", lba);
e69b29
e69b29
 	printf("\tATA command/feature sets:");