From: Christian Taedcke <christian.taedcke@weidmueller.com>
Date: Wed, 15 Nov 2023 12:44:16 +0000 (+0100)
Subject: fs: fat: use get_unaligned_le16 to convert u8[2] to u16
X-Git-Tag: v2025.01-rc5-pxa1908~581^2~38^2~8
X-Git-Url: http://git.dujemihanovic.xyz/img/html/static/%7B%7B%20.Permalink%20%7D%7D?a=commitdiff_plain;h=24caa6964a7c0364296a8654041ac875d4ef0ad8;p=u-boot.git

fs: fat: use get_unaligned_le16 to convert u8[2] to u16

This reduces code duplications.

Signed-off-by: Christian Taedcke <christian.taedcke@weidmueller.com>
---

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 8ff1fd0ec8..a3522340ef 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -18,6 +18,7 @@
 #include <fs.h>
 #include <log.h>
 #include <asm/byteorder.h>
+#include <asm/unaligned.h>
 #include <part.h>
 #include <malloc.h>
 #include <memalign.h>
@@ -571,7 +572,7 @@ static int get_fs_info(fsdata *mydata)
 		mydata->total_sect = bs.total_sect;
 	} else {
 		mydata->fatlength = bs.fat_length;
-		mydata->total_sect = (bs.sectors[1] << 8) + bs.sectors[0];
+		mydata->total_sect = get_unaligned_le16(bs.sectors);
 		if (!mydata->total_sect)
 			mydata->total_sect = bs.total_sect;
 	}
@@ -583,7 +584,7 @@ static int get_fs_info(fsdata *mydata)
 
 	mydata->rootdir_sect = mydata->fat_sect + mydata->fatlength * bs.fats;
 
-	mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0];
+	mydata->sect_size = get_unaligned_le16(bs.sector_size);
 	mydata->clust_size = bs.cluster_size;
 	if (mydata->sect_size != cur_part_info.blksz) {
 		log_err("FAT sector size mismatch (fs=%u, dev=%lu)\n",
@@ -607,8 +608,7 @@ static int get_fs_info(fsdata *mydata)
 					(mydata->clust_size * 2);
 		mydata->root_cluster = bs.root_cluster;
 	} else {
-		mydata->rootdir_size = ((bs.dir_entries[1]  * (int)256 +
-					 bs.dir_entries[0]) *
+		mydata->rootdir_size = (get_unaligned_le16(bs.dir_entries) *
 					 sizeof(dir_entry)) /
 					 mydata->sect_size;
 		mydata->data_begin = mydata->rootdir_sect +