[PATCH 1/5] fs: ext4: simplify ext4fs_iterate_dir()
Michael Nazzareno Trimarchi
michael at amarulasolutions.com
Sat Oct 26 10:52:08 CEST 2024
Hi
On Sat, Oct 26, 2024 at 8:41 AM Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> Remove copying a pointer with a cast to the very same type.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> fs/ext4/ext4_common.c | 27 +++++++++++++--------------
> 1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index 76f7102456e..c1e38978bb9 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -2046,24 +2046,23 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
> unsigned int fpos = 0;
> int status;
> loff_t actread;
> - struct ext2fs_node *diro = (struct ext2fs_node *) dir;
>
> #ifdef DEBUG
> if (name != NULL)
> printf("Iterate dir %s\n", name);
> #endif /* of DEBUG */
> - if (!diro->inode_read) {
> - status = ext4fs_read_inode(diro->data, diro->ino, &diro->inode);
> + if (!dir->inode_read) {
> + status = ext4fs_read_inode(dir->data, dir->ino, &dir->inode);
> if (status == 0)
> return 0;
> }
> /* Search the file. */
> - while (fpos < le32_to_cpu(diro->inode.size)) {
> + while (fpos < le32_to_cpu(dir->inode.size)) {
> struct ext2_dirent dirent;
>
> - status = ext4fs_read_file(diro, fpos,
> - sizeof(struct ext2_dirent),
> - (char *)&dirent, &actread);
> + status = ext4fs_read_file(dir, fpos,
> + sizeof(struct ext2_dirent),
> + (char *)&dirent, &actread);
> if (status < 0)
> return 0;
>
> @@ -2077,7 +2076,7 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
> struct ext2fs_node *fdiro;
> int type = FILETYPE_UNKNOWN;
>
> - status = ext4fs_read_file(diro,
> + status = ext4fs_read_file(dir,
> fpos +
> sizeof(struct ext2_dirent),
> dirent.namelen, filename,
> @@ -2089,7 +2088,7 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
> if (!fdiro)
> return 0;
>
> - fdiro->data = diro->data;
> + fdiro->data = dir->data;
> fdiro->ino = le32_to_cpu(dirent.inode);
>
> filename[dirent.namelen] = '\0';
> @@ -2104,7 +2103,7 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
> else if (dirent.filetype == FILETYPE_REG)
> type = FILETYPE_REG;
> } else {
> - status = ext4fs_read_inode(diro->data,
> + status = ext4fs_read_inode(dir->data,
> le32_to_cpu
> (dirent.inode),
> &fdiro->inode);
> @@ -2140,10 +2139,10 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
> }
> } else {
> if (fdiro->inode_read == 0) {
> - status = ext4fs_read_inode(diro->data,
> - le32_to_cpu(
> - dirent.inode),
> - &fdiro->inode);
> + status = ext4fs_read_inode(dir->data,
> + le32_to_cpu(
> + dirent.inode),
> + &fdiro->inode);
> if (status == 0) {
> free(fdiro);
> return 0;
> --
> 2.45.2
>
Nit I don't know if this can a const pointer from the function call prospective
Reviewed-by: Michael Trimarchi <michael at amarulasolutions.com>
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael at amarulasolutions.com
__________________________________
Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info at amarulasolutions.com
www.amarulasolutions.com
More information about the U-Boot
mailing list