Skip to content

Commit db601f3

Browse files
borneoaBoris Brezillon
authored andcommitted
mtd: mchp23k256: propagate return value of spi_sync()
The call to spi_sync() can fail. Check the return value and propagate it. Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
1 parent bf65710 commit db601f3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/mtd/devices/mchp23k256.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static int mchp23k256_write(struct mtd_info *mtd, loff_t to, size_t len,
6868
struct spi_transfer transfer[2] = {};
6969
struct spi_message message;
7070
unsigned char command[MAX_CMD_SIZE];
71+
int ret;
7172

7273
spi_message_init(&message);
7374

@@ -84,12 +85,16 @@ static int mchp23k256_write(struct mtd_info *mtd, loff_t to, size_t len,
8485

8586
mutex_lock(&flash->lock);
8687

87-
spi_sync(flash->spi, &message);
88+
ret = spi_sync(flash->spi, &message);
89+
90+
mutex_unlock(&flash->lock);
91+
92+
if (ret)
93+
return ret;
8894

8995
if (retlen && message.actual_length > sizeof(command))
9096
*retlen += message.actual_length - sizeof(command);
9197

92-
mutex_unlock(&flash->lock);
9398
return 0;
9499
}
95100

@@ -100,6 +105,7 @@ static int mchp23k256_read(struct mtd_info *mtd, loff_t from, size_t len,
100105
struct spi_transfer transfer[2] = {};
101106
struct spi_message message;
102107
unsigned char command[MAX_CMD_SIZE];
108+
int ret;
103109

104110
spi_message_init(&message);
105111

@@ -117,12 +123,16 @@ static int mchp23k256_read(struct mtd_info *mtd, loff_t from, size_t len,
117123

118124
mutex_lock(&flash->lock);
119125

120-
spi_sync(flash->spi, &message);
126+
ret = spi_sync(flash->spi, &message);
127+
128+
mutex_unlock(&flash->lock);
129+
130+
if (ret)
131+
return ret;
121132

122133
if (retlen && message.actual_length > sizeof(command))
123134
*retlen += message.actual_length - sizeof(command);
124135

125-
mutex_unlock(&flash->lock);
126136
return 0;
127137
}
128138

0 commit comments

Comments
 (0)