From: "Ni, Ruiyu" <ruiyu.ni@Intel.com>
To: Laszlo Ersek <lersek@redhat.com>,
edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Chao Zhang <chao.b.zhang@intel.com>,
Eric Dong <eric.dong@intel.com>,
Jaben Carsey <jaben.carsey@intel.com>,
Jiaxin Wu <jiaxin.wu@intel.com>,
Jiewen Yao <jiewen.yao@intel.com>,
Liming Gao <liming.gao@intel.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Roman Bacik <roman.bacik@broadcom.com>,
Siyuan Fu <siyuan.fu@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: Re: [PATCH 1/6] MdePkg/UefiLib: introduce EfiOpenFileByDevicePath()
Date: Mon, 30 Jul 2018 09:54:34 +0800 [thread overview]
Message-ID: <57ac2b07-41fc-d01d-e20b-9be4a68a0f1b@Intel.com> (raw)
In-Reply-To: <9bb5eed1-f8b0-8d22-e801-53ba7a06cdc5@redhat.com>
On 7/27/2018 8:06 PM, Laszlo Ersek wrote:
> On 07/27/18 11:28, Ni, Ruiyu wrote:
>> On 7/19/2018 4:50 AM, Laszlo Ersek wrote:
>>
>>> + //
>>> + // Traverse the device path nodes relative to the filesystem.
>>> + //
>>> + while (!IsDevicePathEnd (*FilePath)) {
>>> + //
>>> + // Keep local variables that relate to the current device path
>>> node tightly
>>> + // scoped.
>>> + //
>>> + FILEPATH_DEVICE_PATH *FilePathNode;
>>> + CHAR16 *AlignedPathName;
>>> + CHAR16 *PathName;
>>> + EFI_FILE_PROTOCOL *NextFile;
>> 1. Not sure if it follows the coding style. I would prefer to move the
>> definition to the beginning of the function.
>
> OK, will do.
Thanks!
>
>>
>>> +
>>> + if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||
>>> + DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP) {
>>> + Status = EFI_INVALID_PARAMETER;
>>> + goto CloseLastFile;
>>> + }
>>> + FilePathNode = (FILEPATH_DEVICE_PATH *)*FilePath;
>>> +
>>> + //
>>> + // FilePathNode->PathName may be unaligned, and the UEFI
>>> specification
>>> + // requires pointers that are passed to protocol member functions
>>> to be
>>> + // aligned. Create an aligned copy of the pathname if necessary.
>>> + //
>>> + if ((UINTN)FilePathNode->PathName % sizeof
>>> *FilePathNode->PathName == 0) {
>>> + AlignedPathName = NULL;
>>> + PathName = FilePathNode->PathName;
>>> + } else {
>>> + AlignedPathName = AllocateCopyPool (
>>> + (DevicePathNodeLength (FilePathNode) -
>>> + SIZE_OF_FILEPATH_DEVICE_PATH),
>>> + FilePathNode->PathName
>>> + );
>>> + if (AlignedPathName == NULL) {
>>> + Status = EFI_OUT_OF_RESOURCES;
>>> + goto CloseLastFile;
>>> + }
>>> + PathName = AlignedPathName;
>>> + }
>>> +
>>> + //
>>> + // Open the next pathname fragment with EFI_FILE_MODE_CREATE
>>> masked out and
>>> + // with Attributes set to 0.
>>> + //
>>> + Status = LastFile->Open (
>>> + LastFile,
>>> + &NextFile,
>>> + PathName,
>>> + OpenMode & ~(UINT64)EFI_FILE_MODE_CREATE,
>>> + 0
>>> + );
>> 2. As I said in previous mail, is it really needed?
>> Per spec it's not required. Per FAT driver implementation, it's also not
>> required.
>
> I can do that, but it's out of scope for this series. The behavior that
> you point out is not a functionality bug (it is not observably erroneous
> behavior), just sub-optimal implementation. This series is about
> unifying the implementation and fixing those issues that are actual
> bugs. I suggest that we report a separate BZ about this question,
> discuss it separately, and then I can send a separate patch (which will
> benefit all client code at once).
>
> Does that sound acceptable?
I agree.
>
>>
>>> +
>>> + //
>>> + // Retry with EFI_FILE_MODE_CREATE and the original Attributes if
>>> the first
>>> + // attempt failed, and the caller specified EFI_FILE_MODE_CREATE.
>>> + //
>>> + if (EFI_ERROR (Status) && (OpenMode & EFI_FILE_MODE_CREATE) != 0) {
>>> + Status = LastFile->Open (
>>> + LastFile,
>>> + &NextFile,
>>> + PathName,
>>> + OpenMode,
>>> + Attributes
>>> + );
>>> + }
>>> +
>>> + //
>>> + // Release any AlignedPathName on both error and success paths;
>>> PathName is
>>> + // no longer needed.
>>> + //
>>> + if (AlignedPathName != NULL) {
>>> + FreePool (AlignedPathName);
>>> + }
>>> + if (EFI_ERROR (Status)) {
>>> + goto CloseLastFile;
>>> + }
>>> +
>>> + //
>>> + // Advance to the next device path node.
>>> + //
>>> + LastFile->Close (LastFile);
>>> + LastFile = NextFile;
>>> + *FilePath = NextDevicePathNode (FilePathNode);
>>> + }
>>> +
>>> + *File = LastFile;
>>> + return EFI_SUCCESS;
>>> +
>>> +CloseLastFile:
>>> + LastFile->Close (LastFile);
>>> +
>>> + ASSERT (EFI_ERROR (Status));
>> 3. ASSERT_EFI_ERROR (Status);
>
> No, that's not correct; I *really* meant
>
> ASSERT (EFI_ERROR (Status))
>
> Please find the explanation here:
>
> https://lists.01.org/pipermail/edk2-devel/2018-July/027288.html
>
> However, given that both Jaben and you were confused by this, I agree
> that I should add a comment before the assert:
>
> //
> // We are on the error path; we must have set an error Status for
> // returning to the caller.
> //
I just found there is no "!" before "EFI_ERROR".
It's really confusing. I agree a comment before that is better.
Thanks!
With the comment added, Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
>
> Thanks!
> Laszlo
>
>>
>>> + return Status;
>>> +}
>>>
>>
>>
>
--
Thanks,
Ray
next prev parent reply other threads:[~2018-07-30 1:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-18 20:50 [PATCH 0/6] UefiLib: centralize OpenFileByDevicePath() and fix its bugs Laszlo Ersek
2018-07-18 20:50 ` [PATCH 1/6] MdePkg/UefiLib: introduce EfiOpenFileByDevicePath() Laszlo Ersek
2018-07-18 23:10 ` Yao, Jiewen
2018-07-19 10:47 ` Laszlo Ersek
2018-07-19 13:03 ` Yao, Jiewen
2018-07-24 17:20 ` Laszlo Ersek
2018-07-27 9:15 ` Ni, Ruiyu
2018-07-27 9:28 ` Ni, Ruiyu
2018-07-27 12:06 ` Laszlo Ersek
2018-07-30 1:54 ` Ni, Ruiyu [this message]
2018-07-30 14:13 ` Laszlo Ersek
2018-08-02 4:06 ` Gao, Liming
2018-08-02 14:45 ` Laszlo Ersek
2018-07-18 20:50 ` [PATCH 2/6] MdeModulePkg/RamDiskDxe: replace OpenFileByDevicePath() with UefiLib API Laszlo Ersek
2018-07-19 10:36 ` Zeng, Star
2018-07-19 13:20 ` Laszlo Ersek
2018-07-20 10:22 ` Zeng, Star
2018-07-18 20:50 ` [PATCH 3/6] NetworkPkg/TlsAuthConfigDxe: " Laszlo Ersek
2018-07-24 17:20 ` Laszlo Ersek
2018-07-25 0:30 ` Wu, Jiaxin
2018-07-18 20:50 ` [PATCH 4/6] SecurityPkg/SecureBootConfigDxe: " Laszlo Ersek
2018-07-24 5:09 ` Zhang, Chao B
2018-07-18 20:50 ` [PATCH 5/6] ShellPkg/UefiShellLib: drop DeviceHandle param of ShellOpenFileByDevicePath() Laszlo Ersek
2018-07-18 20:50 ` [PATCH 6/6] ShellPkg/UefiShellLib: rebase ShellOpenFileByDevicePath() to UefiLib API Laszlo Ersek
2018-07-18 21:15 ` [PATCH 0/6] UefiLib: centralize OpenFileByDevicePath() and fix its bugs Carsey, Jaben
2018-07-19 0:07 ` Ard Biesheuvel
2018-07-19 10:38 ` Laszlo Ersek
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-list 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=57ac2b07-41fc-d01d-e20b-9be4a68a0f1b@Intel.com \
--to=devel@edk2.groups.io \
/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