From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by mx.groups.io with SMTP id smtpd.web09.309.1658339313594410456 for ; Wed, 20 Jul 2022 10:48:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@posteo.de header.s=2017 header.b=HN6X4EY4; spf=pass (domain: posteo.de, ip: 185.67.36.65, mailfrom: mhaeuser@posteo.de) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id B2322240026 for ; Wed, 20 Jul 2022 19:48:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1658339311; bh=ynCfNhReVfrxqcnK8BEeEMsB4AYLVDbuIM0eg2ZuZ30=; h=Subject:From:Date:Cc:To:From; b=HN6X4EY4yaRMgJXo31n8MrZFPVKV7nZZbIKDDI6xYwKHuYqLOrXy2W/rF6LUJ3zTZ lunUuNrL/zha+1NiKKVgVu7JT+dveUP0JMcnLmaP28t085VncYb8MV+Bm5Leru969n JSdzUGfPkq5ODPZlLo64VSijLRH9Cm+xiEHWKF9zADKz/MUeJg4Zzfl72vBkgzpC8/ 4iAzcxtPN/UFC1Gxz1aLB63pXTIMK9m2n3V9UZ0na6kirGQ/Rze/hx2zD0Ly0uwS9t fks5xQTSQ6/zBUWxgp1AEr9BmefjysDmCAo7W6+v4oarzTNhShPfDEwpwvizxDV4Xo XyZm5HXWI/BEw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Lp38Z2jgtz9rxY; Wed, 20 Jul 2022 19:48:30 +0200 (CEST) Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: Re: [edk2-platforms][PATCH v2 2/2] Ext4Pkg: Add base containing record macro for EXT4_FILE From: =?utf-8?Q?Marvin_H=C3=A4user?= In-Reply-To: <20220720064737.41258-3-savvamtr@gmail.com> Date: Wed, 20 Jul 2022 17:48:30 +0000 Cc: edk2-devel-groups-io , Pedro Falcato , Vitaly Cheptsov Message-Id: <716B95E2-8D97-4FCE-AD73-3B28C1D328E7@posteo.de> References: <20220720064737.41258-1-savvamtr@gmail.com> <20220720064737.41258-3-savvamtr@gmail.com> To: Savva Mitrofanov Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Reviewed-by: Marvin H=C3=A4user > On 20. Jul 2022, at 08:47, Savva Mitrofanov = wrote: >=20 > We shouldn't use direct casts, because in the future it could break > the code, so using BASE_CR would be safe against possible structure > changes and rearrangements >=20 > Cc: Marvin H=C3=A4user > Cc: Pedro Falcato > Cc: Vitaly Cheptsov > Signed-off-by: Savva Mitrofanov > --- > Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 2 ++ > Features/Ext4Pkg/Ext4Dxe/File.c | 16 ++++++++-------- > 2 files changed, 10 insertions(+), 8 deletions(-) >=20 > diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h = b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h > index a1eb32aa2cff..3ff7b29e7133 100644 > --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h > +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h > @@ -383,6 +383,8 @@ struct _Ext4File { > EXT4_DENTRY *Dentry; > }; >=20 > +#define EXT4_FILE_FROM_THIS(This) BASE_CR ((This), EXT4_FILE, = Protocol) > + > #define EXT4_FILE_FROM_OPEN_FILES_NODE(Node) = \ > BASE_CR(Node, EXT4_FILE, OpenFilesListNode) >=20 > diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c = b/Features/Ext4Pkg/Ext4Dxe/File.c > index 0fb9e05e6647..750397010443 100644 > --- a/Features/Ext4Pkg/Ext4Dxe/File.c > +++ b/Features/Ext4Pkg/Ext4Dxe/File.c > @@ -568,7 +568,7 @@ Ext4Open ( > EXT4_FILE *FoundFile; > EXT4_FILE *Source; >=20 > - Source =3D (EXT4_FILE *)This; > + Source =3D EXT4_FILE_FROM_THIS (This); >=20 > // > // Reset Symloops counter > @@ -605,7 +605,7 @@ Ext4Close ( > IN EFI_FILE_PROTOCOL *This > ) > { > - return Ext4CloseInternal ((EXT4_FILE *)This); > + return Ext4CloseInternal (EXT4_FILE_FROM_THIS (This)); > } >=20 > /** > @@ -686,7 +686,7 @@ Ext4ReadFile ( > EXT4_PARTITION *Partition; > EFI_STATUS Status; >=20 > - File =3D (EXT4_FILE *)This; > + File =3D EXT4_FILE_FROM_THIS (This); > Partition =3D File->Partition; >=20 > ASSERT (Ext4FileIsOpenable (File)); > @@ -737,7 +737,7 @@ Ext4WriteFile ( > { > EXT4_FILE *File; >=20 > - File =3D (EXT4_FILE *)This; > + File =3D EXT4_FILE_FROM_THIS (This); >=20 > if (!(File->OpenMode & EFI_FILE_MODE_WRITE)) { > return EFI_ACCESS_DENIED; > @@ -767,7 +767,7 @@ Ext4GetPosition ( > { > EXT4_FILE *File; >=20 > - File =3D (EXT4_FILE *)This; > + File =3D EXT4_FILE_FROM_THIS (This); >=20 > if (Ext4FileIsDir (File)) { > return EFI_UNSUPPORTED; > @@ -800,7 +800,7 @@ Ext4SetPosition ( > { > EXT4_FILE *File; >=20 > - File =3D (EXT4_FILE *)This; > + File =3D EXT4_FILE_FROM_THIS (This); >=20 > // Only seeks to 0 (so it resets the ReadDir operation) are allowed > if (Ext4FileIsDir (File) && (Position !=3D 0)) { > @@ -1068,7 +1068,7 @@ Ext4GetInfo ( > EXT4_FILE *File; > EXT4_PARTITION *Partition; >=20 > - File =3D (EXT4_FILE *)This; > + File =3D EXT4_FILE_FROM_THIS (This); > Partition =3D File->Partition; >=20 > if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { > @@ -1185,7 +1185,7 @@ Ext4SetInfo ( > EXT4_FILE *File; > EXT4_PARTITION *Partition; >=20 > - File =3D (EXT4_FILE *)This; > + File =3D EXT4_FILE_FROM_THIS (This); > Partition =3D File->Partition; >=20 > if (Partition->ReadOnly) { > --=20 > 2.37.0 >=20