aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-10-26 09:11:26 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-10-26 09:29:46 -0400
commitd125a753425b9de3c251df519e521024c79c663d (patch)
tree546946ccc49f6ca8ddb6af51a35d1bf205d09267
parent6a059abdbae7b6b35ddc69f6336f7afc1ce79bac (diff)
UBI: do not allocate the memory unnecessarily
UBI reserves an LEB sized buffer for various needs. We can use this buffer while scanning, instead of allocating another one. This patch was originally created by Jan Luebbe <jlu@pengutronix.de>, but then he dropped it and I picked up and tweaked a little bit. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
-rw-r--r--drivers/mtd/ubi/attach.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index fec406b4553d..72fed3027304 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -322,7 +322,6 @@ static struct ubi_ainf_volume *add_volume(struct ubi_attach_info *ai,
322int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb, 322int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
323 int pnum, const struct ubi_vid_hdr *vid_hdr) 323 int pnum, const struct ubi_vid_hdr *vid_hdr)
324{ 324{
325 void *buf;
326 int len, err, second_is_newer, bitflips = 0, corrupted = 0; 325 int len, err, second_is_newer, bitflips = 0, corrupted = 0;
327 uint32_t data_crc, crc; 326 uint32_t data_crc, crc;
328 struct ubi_vid_hdr *vh = NULL; 327 struct ubi_vid_hdr *vh = NULL;
@@ -393,18 +392,14 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
393 /* Read the data of the copy and check the CRC */ 392 /* Read the data of the copy and check the CRC */
394 393
395 len = be32_to_cpu(vid_hdr->data_size); 394 len = be32_to_cpu(vid_hdr->data_size);
396 buf = vmalloc(len);
397 if (!buf) {
398 err = -ENOMEM;
399 goto out_free_vidh;
400 }
401 395
402 err = ubi_io_read_data(ubi, buf, pnum, 0, len); 396 mutex_lock(&ubi->buf_mutex);
397 err = ubi_io_read_data(ubi, ubi->peb_buf, pnum, 0, len);
403 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err)) 398 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
404 goto out_free_buf; 399 goto out_unlock;
405 400
406 data_crc = be32_to_cpu(vid_hdr->data_crc); 401 data_crc = be32_to_cpu(vid_hdr->data_crc);
407 crc = crc32(UBI_CRC32_INIT, buf, len); 402 crc = crc32(UBI_CRC32_INIT, ubi->peb_buf, len);
408 if (crc != data_crc) { 403 if (crc != data_crc) {
409 dbg_bld("PEB %d CRC error: calculated %#08x, must be %#08x", 404 dbg_bld("PEB %d CRC error: calculated %#08x, must be %#08x",
410 pnum, crc, data_crc); 405 pnum, crc, data_crc);
@@ -415,8 +410,8 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
415 dbg_bld("PEB %d CRC is OK", pnum); 410 dbg_bld("PEB %d CRC is OK", pnum);
416 bitflips = !!err; 411 bitflips = !!err;
417 } 412 }
413 mutex_unlock(&ubi->buf_mutex);
418 414
419 vfree(buf);
420 ubi_free_vid_hdr(ubi, vh); 415 ubi_free_vid_hdr(ubi, vh);
421 416
422 if (second_is_newer) 417 if (second_is_newer)
@@ -426,8 +421,8 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
426 421
427 return second_is_newer | (bitflips << 1) | (corrupted << 2); 422 return second_is_newer | (bitflips << 1) | (corrupted << 2);
428 423
429out_free_buf: 424out_unlock:
430 vfree(buf); 425 mutex_unlock(&ubi->buf_mutex);
431out_free_vidh: 426out_free_vidh:
432 ubi_free_vid_hdr(ubi, vh); 427 ubi_free_vid_hdr(ubi, vh);
433 return err; 428 return err;