Skip to content

Commit e3e54e5

Browse files
Merge pull request #4607 from geky/fix-mbr-init
bd: Fix missing init in MBRBlockDevice
2 parents c9647e0 + f2c93c7 commit e3e54e5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

features/filesystem/bd/HeapBlockDevice.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,39 @@ int HeapBlockDevice::init()
5757

5858
int HeapBlockDevice::deinit()
5959
{
60-
// Heapory is lazily cleaned up in destructor to allow
60+
MBED_ASSERT(_blocks != NULL);
61+
// Memory is lazily cleaned up in destructor to allow
6162
// data to live across de/reinitialization
6263
return BD_ERROR_OK;
6364
}
6465

6566
bd_size_t HeapBlockDevice::get_read_size() const
6667
{
68+
MBED_ASSERT(_blocks != NULL);
6769
return _read_size;
6870
}
6971

7072
bd_size_t HeapBlockDevice::get_program_size() const
7173
{
74+
MBED_ASSERT(_blocks != NULL);
7275
return _program_size;
7376
}
7477

7578
bd_size_t HeapBlockDevice::get_erase_size() const
7679
{
80+
MBED_ASSERT(_blocks != NULL);
7781
return _erase_size;
7882
}
7983

8084
bd_size_t HeapBlockDevice::size() const
8185
{
86+
MBED_ASSERT(_blocks != NULL);
8287
return _count * _erase_size;
8388
}
8489

8590
int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
8691
{
92+
MBED_ASSERT(_blocks != NULL);
8793
MBED_ASSERT(is_valid_read(addr, size));
8894
uint8_t *buffer = static_cast<uint8_t*>(b);
8995

@@ -107,6 +113,7 @@ int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
107113

108114
int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
109115
{
116+
MBED_ASSERT(_blocks != NULL);
110117
MBED_ASSERT(is_valid_program(addr, size));
111118
const uint8_t *buffer = static_cast<const uint8_t*>(b);
112119

@@ -133,6 +140,7 @@ int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
133140

134141
int HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
135142
{
143+
MBED_ASSERT(_blocks != NULL);
136144
MBED_ASSERT(is_valid_erase(addr, size));
137145
// TODO assert on programming unerased blocks
138146

features/filesystem/bd/MBRBlockDevice.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,16 @@ MBRBlockDevice::MBRBlockDevice(BlockDevice *bd, int part)
187187

188188
int MBRBlockDevice::init()
189189
{
190+
int err = _bd->init();
191+
if (err) {
192+
return err;
193+
}
194+
190195
// Allocate smallest buffer necessary to write MBR
191196
uint32_t buffer_size = std::max<uint32_t>(_bd->get_read_size(), sizeof(struct mbr_table));
192197
uint8_t *buffer = new uint8_t[buffer_size];
193198

194-
int err = _bd->read(buffer, 512-buffer_size, buffer_size);
199+
err = _bd->read(buffer, 512-buffer_size, buffer_size);
195200
if (err) {
196201
delete[] buffer;
197202
return err;

0 commit comments

Comments
 (0)