Skip to content

Commit f387ab1

Browse files
committed
mtd: spi-nor: don't overwrite errno in spi_nor_get_map_in_use()
Don't overwrite the errno from spi_nor_read_raw(). Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> (cherry picked from commit b9f07cc) Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent ea3ad78 commit f387ab1

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,11 +2804,13 @@ static u8 spi_nor_smpt_read_dummy(const struct spi_nor *nor, const u32 settings)
28042804
* @nor: pointer to a 'struct spi_nor'
28052805
* @smpt: pointer to the sector map parameter table
28062806
* @smpt_len: sector map parameter table length
2807+
*
2808+
* Return: pointer to the map in use, ERR_PTR(-errno) otherwise.
28072809
*/
28082810
static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28092811
u8 smpt_len)
28102812
{
2811-
const u32 *ret = NULL;
2813+
const u32 *ret;
28122814
u32 addr;
28132815
int err;
28142816
u8 i;
@@ -2832,8 +2834,10 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28322834
addr = smpt[i + 1];
28332835

28342836
err = spi_nor_read_raw(nor, addr, 1, &data_byte);
2835-
if (err)
2837+
if (err) {
2838+
ret = ERR_PTR(err);
28362839
goto out;
2840+
}
28372841

28382842
/*
28392843
* Build an index value that is used to select the Sector Map
@@ -2849,6 +2853,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
28492853
*
28502854
* Find the matching configuration map.
28512855
*/
2856+
ret = ERR_PTR(-EINVAL);
28522857
while (i < smpt_len) {
28532858
if (SMPT_MAP_ID(smpt[i]) == map_id) {
28542859
ret = smpt + i;
@@ -2989,8 +2994,8 @@ static int spi_nor_parse_smpt(struct spi_nor *nor,
29892994
smpt[i] = le32_to_cpu(smpt[i]);
29902995

29912996
sector_map = spi_nor_get_map_in_use(nor, smpt, smpt_header->length);
2992-
if (!sector_map) {
2993-
ret = -EINVAL;
2997+
if (IS_ERR(sector_map)) {
2998+
ret = PTR_ERR(sector_map);
29942999
goto out;
29953000
}
29963001

0 commit comments

Comments
 (0)