aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorEzequiel Garcia <elezegarcia@gmail.com>2012-11-23 06:58:05 -0500
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-12-03 06:54:14 -0500
commitd856c13c11d81dfa545f927db8d31663d45bbc94 (patch)
tree7253bc3605cbfb66a502ea54f62927a14e041d2c /drivers/mtd/ubi
parent38f92cca8aae5b2e4ff2700c47eee0b807e22980 (diff)
UBI: replace memcpy with struct assignment
This kind of memcpy() is error-prone. Its replacement with a struct assignment is prefered because it's type-safe and much easier to read. Found by coccinelle. Hand patched and reviewed. Tested by compilation only. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ identifier struct_name; struct struct_name to; struct struct_name from; expression E; @@ -memcpy(&(to), &(from), E); +to = from; // </smpl> Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com> Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/build.c3
-rw-r--r--drivers/mtd/ubi/upd.c6
-rw-r--r--drivers/mtd/ubi/vmt.c2
3 files changed, 4 insertions, 7 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 344b4cb49d4e..fb59604854c9 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -825,8 +825,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
825 * No available PEBs to re-size the volume, clear the flag on 825 * No available PEBs to re-size the volume, clear the flag on
826 * flash and exit. 826 * flash and exit.
827 */ 827 */
828 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], 828 vtbl_rec = ubi->vtbl[vol_id];
829 sizeof(struct ubi_vtbl_record));
830 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 829 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
831 if (err) 830 if (err)
832 ubi_err("cannot clean auto-resize flag for volume %d", 831 ubi_err("cannot clean auto-resize flag for volume %d",
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index 9f2ebd8750e7..ec2c2dc1c1ca 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -64,8 +64,7 @@ static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol)
64 return 0; 64 return 0;
65 } 65 }
66 66
67 memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], 67 vtbl_rec = ubi->vtbl[vol->vol_id];
68 sizeof(struct ubi_vtbl_record));
69 vtbl_rec.upd_marker = 1; 68 vtbl_rec.upd_marker = 1;
70 69
71 mutex_lock(&ubi->device_mutex); 70 mutex_lock(&ubi->device_mutex);
@@ -93,8 +92,7 @@ static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol,
93 92
94 dbg_gen("clear update marker for volume %d", vol->vol_id); 93 dbg_gen("clear update marker for volume %d", vol->vol_id);
95 94
96 memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], 95 vtbl_rec = ubi->vtbl[vol->vol_id];
97 sizeof(struct ubi_vtbl_record));
98 ubi_assert(vol->upd_marker && vtbl_rec.upd_marker); 96 ubi_assert(vol->upd_marker && vtbl_rec.upd_marker);
99 vtbl_rec.upd_marker = 0; 97 vtbl_rec.upd_marker = 0;
100 98
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 9169e58c262e..99ef8a14e668 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -535,7 +535,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
535 } 535 }
536 536
537 /* Change volume table record */ 537 /* Change volume table record */
538 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); 538 vtbl_rec = ubi->vtbl[vol_id];
539 vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs); 539 vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
540 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 540 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
541 if (err) 541 if (err)