Skip to content

Commit 40b7d5c

Browse files
committed
mtd: spi-nor: Check all the bits written, not just the BP ones
Check that all the bits written in the write_sr_and_check() method match the status_new received value. Failing to write the other bits is dangerous too, extend the check. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Vignesh Raghavendra <vigneshr@ti.com>
1 parent b0db77f commit 40b7d5c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,7 @@ static int spi_nor_write_sr(struct spi_nor *nor, const u8 *sr, size_t len)
960960
}
961961

962962
/* Write status register and ensure bits in mask match written values */
963-
static int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 status_new,
964-
u8 mask)
963+
static int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 status_new)
965964
{
966965
int ret;
967966

@@ -975,7 +974,7 @@ static int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 status_new,
975974
if (ret)
976975
return ret;
977976

978-
return ((nor->bouncebuf[0] & mask) != (status_new & mask)) ? -EIO : 0;
977+
return (nor->bouncebuf[0] != status_new) ? -EIO : 0;
979978
}
980979

981980
/**
@@ -1774,7 +1773,7 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
17741773
if ((status_new & mask) < (status_old & mask))
17751774
return -EINVAL;
17761775

1777-
return spi_nor_write_sr_and_check(nor, status_new, mask);
1776+
return spi_nor_write_sr_and_check(nor, status_new);
17781777
}
17791778

17801779
/*
@@ -1859,7 +1858,7 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
18591858
if ((status_new & mask) > (status_old & mask))
18601859
return -EINVAL;
18611860

1862-
return spi_nor_write_sr_and_check(nor, status_new, mask);
1861+
return spi_nor_write_sr_and_check(nor, status_new);
18631862
}
18641863

18651864
/*

0 commit comments

Comments
 (0)