Skip to content

Commit d856c13

Browse files
ezequielgarciadedekind
authored andcommitted
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>
1 parent 38f92cc commit d856c13

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

drivers/mtd/ubi/build.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
825825
* No available PEBs to re-size the volume, clear the flag on
826826
* flash and exit.
827827
*/
828-
memcpy(&vtbl_rec, &ubi->vtbl[vol_id],
829-
sizeof(struct ubi_vtbl_record));
828+
vtbl_rec = ubi->vtbl[vol_id];
830829
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
831830
if (err)
832831
ubi_err("cannot clean auto-resize flag for volume %d",

drivers/mtd/ubi/upd.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol)
6464
return 0;
6565
}
6666

67-
memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id],
68-
sizeof(struct ubi_vtbl_record));
67+
vtbl_rec = ubi->vtbl[vol->vol_id];
6968
vtbl_rec.upd_marker = 1;
7069

7170
mutex_lock(&ubi->device_mutex);
@@ -93,8 +92,7 @@ static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol,
9392

9493
dbg_gen("clear update marker for volume %d", vol->vol_id);
9594

96-
memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id],
97-
sizeof(struct ubi_vtbl_record));
95+
vtbl_rec = ubi->vtbl[vol->vol_id];
9896
ubi_assert(vol->upd_marker && vtbl_rec.upd_marker);
9997
vtbl_rec.upd_marker = 0;
10098

drivers/mtd/ubi/vmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
535535
}
536536

537537
/* Change volume table record */
538-
memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record));
538+
vtbl_rec = ubi->vtbl[vol_id];
539539
vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
540540
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
541541
if (err)

0 commit comments

Comments
 (0)