scsi: sd: Clear sdkp->protection_type if disk is reformatted without PI

If an attached disk with protection information enabled is reformatted
to Type 0 the revalidation code does not clear the original protection
type and subsequent accesses will keep setting RDPROTECT/WRPROTECT.

Set the protection type to 0 if the disk reports PROT_EN=0 in READ
CAPACITY(16).

[mkp: commit desc]

Fixes: fe542396da73 ("[SCSI] sd: Ensure we correctly disable devices with unknown protection type")
Link: https://lore.kernel.org/r/1578532344-101668-1-git-send-email-chenxiang66@hisilicon.com
Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by Xiang Chen and committed by Martin K. Petersen 465f4eda e4dc9a4c

Changed files
+3 -1
drivers
scsi
+3 -1
drivers/scsi/sd.c
··· 2211 2211 u8 type; 2212 2212 int ret = 0; 2213 2213 2214 - if (scsi_device_protection(sdp) == 0 || (buffer[12] & 1) == 0) 2214 + if (scsi_device_protection(sdp) == 0 || (buffer[12] & 1) == 0) { 2215 + sdkp->protection_type = 0; 2215 2216 return ret; 2217 + } 2216 2218 2217 2219 type = ((buffer[12] >> 1) & 7) + 1; /* P_TYPE 0 = Type 1 */ 2218 2220