public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexander Dahl <ada@thorsis.com>
To: christian.taedcke-oss@weidmueller.com
Cc: u-boot@lists.denx.de,
	Christian Taedcke <christian.taedcke@weidmueller.com>,
	Bin Meng <bmeng.cn@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH v1 1/2] fs: fat: add macro to convert u8[2] to u16
Date: Wed, 8 Nov 2023 13:47:49 +0100	[thread overview]
Message-ID: <20231108-yield-virtual-b8409f93318f@ifak-system.com> (raw)
In-Reply-To: <20231108121239.26737-2-christian.taedcke-oss@weidmueller.com>

Hello Christian,

Am Wed, Nov 08, 2023 at 01:12:38PM +0100 schrieb christian.taedcke-oss@weidmueller.com:
> From: Christian Taedcke <christian.taedcke@weidmueller.com>
> 
> This reduces code duplications.
> 
> Signed-off-by: Christian Taedcke <christian.taedcke@weidmueller.com>
> ---
> 
>  fs/fat/fat.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index 8ff1fd0ec8..8a0f4e4e6c 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -25,6 +25,8 @@
>  #include <linux/compiler.h>
>  #include <linux/ctype.h>
>  
> +#define FATU8ARRAY2CPU16(x) (((x)[1] << 8) + (x)[0])

This does the same as the generic `get_unaligned_le16()` … why not use
that?

Greets
Alex

> +
>  /*
>   * Convert a string to lowercase.  Converts at most 'len' characters,
>   * 'len' may be larger than the length of 'str' if 'str' is NULL
> @@ -571,7 +573,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 = FATU8ARRAY2CPU16(bs.sectors);
>  		if (!mydata->total_sect)
>  			mydata->total_sect = bs.total_sect;
>  	}
> @@ -583,7 +585,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 = FATU8ARRAY2CPU16(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 +609,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 = (FATU8ARRAY2CPU16(bs.dir_entries) *
>  					 sizeof(dir_entry)) /
>  					 mydata->sect_size;
>  		mydata->data_begin = mydata->rootdir_sect +
> -- 
> 2.34.1
> 

  reply	other threads:[~2023-11-08 12:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 12:12 [PATCH v1 0/2] fs: fat: calculate FAT type based on cluster count christian.taedcke-oss
2023-11-08 12:12 ` [PATCH v1 1/2] fs: fat: add macro to convert u8[2] to u16 christian.taedcke-oss
2023-11-08 12:47   ` Alexander Dahl [this message]
2023-11-08 12:12 ` [PATCH v1 2/2] fs: fat: calculate FAT type based on cluster count christian.taedcke-oss
2023-11-08 13:39   ` Heinrich Schuchardt
2023-11-08 18:57   ` Sean Anderson
2023-11-08 18:59     ` Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231108-yield-virtual-b8409f93318f@ifak-system.com \
    --to=ada@thorsis.com \
    --cc=bmeng.cn@gmail.com \
    --cc=christian.taedcke-oss@weidmueller.com \
    --cc=christian.taedcke@weidmueller.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox