Skip to content

Commit e850984

Browse files
committed
Correctly check return codes from bytewise write function of I2C.
1 parent 52aed22 commit e850984

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,18 @@ int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
6969
{
7070
_i2c->start();
7171

72-
auto const pagedDeviceAddress = get_paged_device_address(page);
73-
74-
if (!_i2c->write(pagedDeviceAddress)) {
72+
if (1 != _i2c->write(pagedDeviceAddress))
73+
{
7574
return BD_ERROR_DEVICE_ERROR;
7675
}
7776

78-
if (!_address_is_eight_bit && !_i2c->write((char)(pagedStart >> 8u))) {
77+
if (!_address_is_eight_bit && 1 != _i2c->write((char) (pagedStart >> 8u)))
78+
{
7979
return BD_ERROR_DEVICE_ERROR;
8080
}
8181

82-
if (!_i2c->write((char)(pagedStart & 0xffu))) {
82+
if (1 != _i2c->write((char) (pagedStart & 0xffu)))
83+
{
8384
return BD_ERROR_DEVICE_ERROR;
8485
}
8586

@@ -113,28 +114,34 @@ int I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
113114
const uint8_t &pagedDeviceAddress) -> int
114115
{
115116
// While we have some more data to write.
116-
while (size > 0) {
117+
while (size > 0)
118+
{
117119
uint32_t off = addr % _block;
118120
uint32_t chunk = (off + size < _block) ? size : (_block - off);
119121

120122
_i2c->start();
121123

122-
auto const pagedDeviceAddress = get_paged_device_address(page);
123-
124-
if (!_i2c->write(pagedDeviceAddress)) {
124+
if (1 != _i2c->write(pagedDeviceAddress))
125+
{
125126
return BD_ERROR_DEVICE_ERROR;
126127
}
127128

128-
if (!_address_is_eight_bit && !_i2c->write((char)(pagedStart >> 8u))) {
129+
if (!_address_is_eight_bit && 1 != _i2c->write((char) (pagedStart >> 8u)))
130+
{
129131
return BD_ERROR_DEVICE_ERROR;
130132
}
131133

132-
if (!_i2c->write((char)(addr & 0xffu))) {
134+
if (1 != _i2c->write((char) (addr & 0xffu)))
135+
{
133136
return BD_ERROR_DEVICE_ERROR;
134137
}
135138

136-
for (unsigned i = 0; i < chunk; i++) {
137-
_i2c->write(charBuffer[i]);
139+
for (unsigned i = 0; i < chunk; i++)
140+
{
141+
if (1 != _i2c->write(charBuffer[i]))
142+
{
143+
return BD_ERROR_DEVICE_ERROR;
144+
}
138145
}
139146

140147
_i2c->stop();

0 commit comments

Comments
 (0)