Skip to content

Commit b359ed5

Browse files
jpbruckerr-vignesh
authored andcommitted
mtd: cfi_cmdset_0001: Support the absence of protection registers
The flash controller implemented by the Arm Base platform behaves like the Intel StrataFlash J3 device, but omits several features. In particular it doesn't implement a protection register, so "Number of Protection register fields" in the Primary Vendor-Specific Extended Query, is 0. The Intel StrataFlash J3 datasheet only lists 1 as a valid value for NumProtectionFields. It describes the field as: "Number of Protection register fields in JEDEC ID space. “00h,” indicates that 256 protection bytes are available" While a value of 0 may arguably not be architecturally valid, the driver's current behavior is certainly wrong: if NumProtectionFields is 0, read_pri_intelext() adds a negative value to the unsigned extra_size, and ends up in an infinite loop. Fix it by ignoring a NumProtectionFields of 0. Signed-off-by: Jean-Philippe Brucker <[email protected]> Tested-by: Sudeep Holla <[email protected]> Tested-by: Catalin Marinas <[email protected]> Signed-off-by: Vignesh Raghavendra <[email protected]>
1 parent ae83d0b commit b359ed5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/mtd/chips/cfi_cmdset_0001.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,9 @@ read_pri_intelext(struct map_info *map, __u16 adr)
420420
extra_size = 0;
421421

422422
/* Protection Register info */
423-
extra_size += (extp->NumProtectionFields - 1) *
424-
sizeof(struct cfi_intelext_otpinfo);
423+
if (extp->NumProtectionFields)
424+
extra_size += (extp->NumProtectionFields - 1) *
425+
sizeof(struct cfi_intelext_otpinfo);
425426
}
426427

427428
if (extp->MinorVersion >= '1') {
@@ -695,14 +696,16 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
695696
*/
696697
if (extp && extp->MajorVersion == '1' && extp->MinorVersion >= '3'
697698
&& extp->FeatureSupport & (1 << 9)) {
699+
int offs = 0;
698700
struct cfi_private *newcfi;
699701
struct flchip *chip;
700702
struct flchip_shared *shared;
701-
int offs, numregions, numparts, partshift, numvirtchips, i, j;
703+
int numregions, numparts, partshift, numvirtchips, i, j;
702704

703705
/* Protection Register info */
704-
offs = (extp->NumProtectionFields - 1) *
705-
sizeof(struct cfi_intelext_otpinfo);
706+
if (extp->NumProtectionFields)
707+
offs = (extp->NumProtectionFields - 1) *
708+
sizeof(struct cfi_intelext_otpinfo);
706709

707710
/* Burst Read info */
708711
offs += extp->extra[offs+1]+2;

0 commit comments

Comments
 (0)