diff mbox series

[v2,3/6] disk: dos: use generic macro for unaligned le32 access

Message ID 20201222140914.9933-4-m.szyprowski@samsung.com
State Superseded
Headers show
Series Add MBR partition table creation and verify command | expand

Commit Message

Marek Szyprowski Dec. 22, 2020, 2:09 p.m. UTC
Use a generic helper for reading LE32 integers.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

---
 disk/part_dos.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 20d35dc9cd..3b79b9b1b8 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -18,6 +18,7 @@ 
 #include <command.h>
 #include <ide.h>
 #include <memalign.h>
+#include <asm/unaligned.h>
 #include "part_dos.h"
 #include <part.h>
 
@@ -29,17 +30,6 @@ 
  * to use large numbers of partitions */
 #define MAX_EXT_PARTS 256
 
-/* Convert char[4] in little endian format to the host format integer
- */
-static inline unsigned int le32_to_int(unsigned char *le32)
-{
-    return ((le32[3] << 24) +
-	    (le32[2] << 16) +
-	    (le32[1] << 8) +
-	     le32[0]
-	   );
-}
-
 static inline int is_extended(int part_type)
 {
     return (part_type == DOS_PART_TYPE_EXTENDED ||
@@ -61,8 +51,8 @@  static int get_bootable(dos_partition_t *p)
 static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
 			   int part_num, unsigned int disksig)
 {
-	lbaint_t lba_start = ext_part_sector + le32_to_int (p->start4);
-	lbaint_t lba_size  = le32_to_int (p->size4);
+	lbaint_t lba_start = ext_part_sector + get_unaligned_le32(p->start4);
+	lbaint_t lba_size  = get_unaligned_le32(p->size4);
 
 	printf("%3d\t%-10" LBAFlength "u\t%-10" LBAFlength
 		"u\t%08x-%02x\t%02x%s%s\n",
@@ -171,7 +161,7 @@  static void print_partition_extended(struct blk_desc *dev_desc,
 	}
 
 	if (!ext_part_sector)
-		disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]);
+		disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 
 	/* Print all primary/logical partitions */
 	pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
@@ -198,7 +188,7 @@  static void print_partition_extended(struct blk_desc *dev_desc,
 	for (i = 0; i < 4; i++, pt++) {
 		if (is_extended (pt->sys_ind)) {
 			lbaint_t lba_start
-				= le32_to_int (pt->start4) + relative;
+				= get_unaligned_le32 (pt->start4) + relative;
 
 			print_partition_extended(dev_desc, lba_start,
 				ext_part_sector == 0  ? lba_start : relative,
@@ -244,7 +234,7 @@  static int part_get_info_extended(struct blk_desc *dev_desc,
 
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
 	if (!ext_part_sector)
-		disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]);
+		disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 #endif
 
 	/* Print all primary/logical partitions */
@@ -260,8 +250,8 @@  static int part_get_info_extended(struct blk_desc *dev_desc,
 		    (ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
 			info->blksz = DOS_PART_DEFAULT_SECTOR;
 			info->start = (lbaint_t)(ext_part_sector +
-					le32_to_int(pt->start4));
-			info->size  = (lbaint_t)le32_to_int(pt->size4);
+					get_unaligned_le32(pt->start4));
+			info->size  = (lbaint_t)get_unaligned_le32(pt->size4);
 			part_set_generic_name(dev_desc, part_num,
 					      (char *)info->name);
 			/* sprintf(info->type, "%d, pt->sys_ind); */
@@ -286,7 +276,7 @@  static int part_get_info_extended(struct blk_desc *dev_desc,
 	for (i = 0; i < 4; i++, pt++) {
 		if (is_extended (pt->sys_ind)) {
 			lbaint_t lba_start
-				= le32_to_int (pt->start4) + relative;
+				= get_unaligned_le32 (pt->start4) + relative;
 
 			return part_get_info_extended(dev_desc, lba_start,
 				 ext_part_sector == 0 ? lba_start : relative,