Commit 61fcc7d2757bc5d6bf52739e4fc7132b5fa84efe

Authored by Hector Palacios
Committed by Tom Rini
1 parent 1674df60d1

part_efi: fix protective mbr struct allocation

The calloc() call was allocating space for the sizeof the struct
pointer rather than for the struct contents.
Besides, since this buffer is passed to mmc for writing and some
platforms may use cache, the legacy_mbr struct should be cache-aligned.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>

Showing 1 changed file with 3 additions and 5 deletions Side-by-side Diff

... ... @@ -213,10 +213,10 @@
213 213 */
214 214 static int set_protective_mbr(block_dev_desc_t *dev_desc)
215 215 {
216   - legacy_mbr *p_mbr;
217   -
218 216 /* Setup the Protective MBR */
219   - p_mbr = calloc(1, sizeof(p_mbr));
  217 + ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, p_mbr, 1);
  218 + memset(p_mbr, 0, sizeof(*p_mbr));
  219 +
220 220 if (p_mbr == NULL) {
221 221 printf("%s: calloc failed!\n", __func__);
222 222 return -1;
223 223  
... ... @@ -231,11 +231,9 @@
231 231 if (dev_desc->block_write(dev_desc->dev, 0, 1, p_mbr) != 1) {
232 232 printf("** Can't write to device %d **\n",
233 233 dev_desc->dev);
234   - free(p_mbr);
235 234 return -1;
236 235 }
237 236  
238   - free(p_mbr);
239 237 return 0;
240 238 }
241 239