diff mbox series

mtd: cfi_cmdset_0002.c: fix crash when erasing/writing AMD cards

Message ID DB6P189MB0583AB48641688D2C5086D1CC11D9@DB6P189MB0583.EURP189.PROD.OUTLOOK.COM
State Superseded
Delegated to: Vignesh R
Headers show
Series mtd: cfi_cmdset_0002.c: fix crash when erasing/writing AMD cards | expand

Commit Message

Andreas Persson July 4, 2021, 7:31 p.m. UTC
Erasing an AMD linear flash card (AM29F016D) crashes after the first
sector has been erased. Likewise, writing to it crashes after two bytes
have been written. The reason is a missing check for a null pointer, the
cmdset_priv field is not set for this type of card.
diff mbox series

Patch

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c 
b/drivers/mtd/chips/cfi_cmdset_0002.c
index 3097e93787f7..a761134fd3be 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -119,7 +119,7 @@  static int cfi_use_status_reg(struct cfi_private *cfi)
         struct cfi_pri_amdstd *extp = cfi->cmdset_priv;
         u8 poll_mask = CFI_POLL_STATUS_REG | CFI_POLL_DQ;

-       return extp->MinorVersion >= '5' &&
+       return extp && extp->MinorVersion >= '5' &&
                 (extp->SoftwareFeatures & poll_mask) == 
CFI_POLL_STATUS_REG;
  }