From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by mx.groups.io with SMTP id smtpd.web08.6003.1626541572715289541 for ; Sat, 17 Jul 2021 10:06:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qPgEripy; spf=pass (domain: gmail.com, ip: 209.85.218.51, mailfrom: harlydavidsen@gmail.com) Received: by mail-ej1-f51.google.com with SMTP id bu12so20400762ejb.0 for ; Sat, 17 Jul 2021 10:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=f5TUuiJNlnf8ZQdvvw4aKn9KTAr1lyQS7U6SANa6SPY=; b=qPgEripyLmqh2y5U8SghhYBcZgAc22DeEQPzstQDyYWva/2Ef54N58cJZOg+DQzAGR vs4dHu5z5JtoUT8k7kUn4GkJoKu2SqVXc0ynYAxA7GZD3MnoEUG4vvN1cNeoTlmkMM18 w+dk2YyQzuqigKwFzRYot0psDxbhbTi1IM/qQkUv2+jgIf5s1r0KLHL51+VBTj3eN5Mp +GIsEuJWQpP1994OkeOA0vSlWErxeMlReCpMCeY0MYrRaeTfJX1MHM7P04q9q6oyBFpw wRtc/dcDZMY/prQS+noErHfgLWRWkXq7FkayAXjBKegSCZCC8xK/XIDYzhHrk8Jeak1a pCUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=f5TUuiJNlnf8ZQdvvw4aKn9KTAr1lyQS7U6SANa6SPY=; b=DktT+M3eOPTP3K94IhSfq2H50ixO0DZ5eCs6kw3KIrwCB0c8G/A1M2xO6Pc6vOZhcm N+1DQRFpuuq0XZv8cLIGTCwBjE1IVWsMF1IkDGhx+u8K/bWRyyeatvjtfRjPT4mcoahI NKyI3PIzsUc/iye/9K6kzcWgLqVT0goZQmzySXKTlUJbz+bb7opu4rP79raXffe2EFRx PQvP6rYVGvRdN6eSwTUgFuQHbEZxgZ0Qxt/QwzqZb+Iu58gk7cp00lvWxFnGX6PjIE4k CBQbOqLsxoyDct7d4/r7z2aO3W2mP8a1CNm5yEJMCAfuFf/ZWMPvQotTAGspOvPA8Csr z0lw== X-Gm-Message-State: AOAM532zKMgKYYphqkho4AWZYo98kNZ8h7nkR9MLriEiPhmZlDRWFJvb 7ESCocDz/otFz7Fk98kHTTcc44OwfDS+4wRi6J4= X-Google-Smtp-Source: ABdhPJzl52YJI1mqKfUG/ZdzTCbpWro6G3L1zdxLWaeu1XXilW2s0aK77MyLbynprvUhMxEIcgC4tC+39Qq2tdX96a8= X-Received: by 2002:a17:907:f8e:: with SMTP id kb14mr18233507ejc.40.1626541571337; Sat, 17 Jul 2021 10:06:11 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:3f89:0:0:0:0:0 with HTTP; Sat, 17 Jul 2021 10:06:10 -0700 (PDT) In-Reply-To: References: <88AE4AB4-12BA-433C-9EA4-EDC01B30DAD1@apple.com> From: "Ethin Probst" Date: Sat, 17 Jul 2021 12:06:10 -0500 Message-ID: Subject: Re: OpenProtocol() giving me EFI_INVALID_PARAMETER To: Andrew Fish Cc: devel@edk2.groups.io, "Leif Lindholm (Nuvia address)" , Ray Ni Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Okay, so I just tried dh -v 7EDE4C18 (that was the handle that I'm getting from `HandleBuffer()`) and it says "dh: Handle - '7EDE4C18' not found". So I'm definitely confused because that's what `HandleBuffer()` is getting me. Should I pre-allocate the buffer? On 7/17/21, Ethin Probst wrote: > I mean, possible... The code I'm using to initialize the handle buffer is > this: > > ```C > EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imageHandle, IN EFI_SYSTEM_TABLE= * > st) { > Print(L"Attempting to find USB IO protocol\n"); > UINTN numHandles =3D 0; > UINTN i =3D 0; > UINT32 UsbStatus =3D 0; > EFI_HANDLE* handles =3D NULL; > EFI_USB_IO_PROTOCOL* UsbIo =3D NULL; > EFI_STATUS status =3D st->BootServices->LocateHandleBuffer(ByProtocol, > &gEfiUsbIoProtocolGuid, NULL, &numHandles, &handles); > if (EFI_ERROR(status)) { > Print(L"Cannot find any handles for USB devices, reason: %r\n", > status); > return EFI_ABORTED; > } > Print(L"Found %d USB devices; enumerating\n", numHandles); > for (; i < numHandles; ++i) { > Print(L"Trying to open handle %d (%x)... ", i, handles[i]); > status =3D st->BootServices->OpenProtocol(handles[i], > &gEfiUsbIoProtocolGuid, (void**)&UsbIo, imageHandle, NULL, > EFI_OPEN_PROTOCOL_EXCLUSIVE); > if (EFI_ERROR(status)) { > Print(L"%r, skipping\n", status); > continue; > } > // ... > ``` > I've done my best to follow SEI secure C coding standards, like > initializing all variables, regardless of type -- e.g. initializing > pointers to 0/NULL. But I will definitely try that idea. > > On 7/17/21, Andrew Fish wrote: >> >> >>> On Jul 17, 2021, at 9:41 AM, Ethin Probst >>> wrote: >>> >>> Hey all, >>> >>> So my UsbAudio.efi app has hit a bit of a roadblock. This code: >>> >>> ```C >>> status =3D st->BootServices->OpenProtocol(handles[i], >>> &gEfiUsbIoProtocolGuid, (void**)&UsbIo, imageHandle, NULL, >>> EFI_OPEN_PROTOCOL_EXCLUSIVE); >>> if (EFI_ERROR(status)) { >>> Print(L"%r, skipping\n", status); >>> continue; >>> } >>> ``` >> >> How are you constructing handle[]? Could it have gotten stale? You could >> print out the value of handle[I] on the failure. >> >> The contents of a handle are not defined, but the current implementation >> is >> a pointer to an IHANDLE internal data structure in the DXE Core. If you >> are >> at the UEFI Shell and you `dh -v it will show the >> and the value. >> >> Shell> dh -v 98 >> 98: 6d5CF18 >> =E2=80=A6. >> >> I think you can `dh -p UsbIo=E2=80=99 to get the list of the UsbIo handl= es. >> >> So you can poke around and see what is happening on that handle. >> >> I guess the handle[] array could be getting corrupted? So you could chec= k >> for that? >> >> Thanks, >> >> Andrew Fish >> >>> Is giving me EFI_INVALID_PARAMETER and I don=E2=80=99t know why. I don'= t think >>> I'm violating any of its constraints, according to the specification, >>> and I haven't touched this code since it was written. It also happens >>> irregularly: sometimes it happens on the USB audio streaming device, >>> or if I have a device plugged in it might happen on that device, you >>> get the idea. But it doesn't consistently fail. Does anybody have any >>> idea what's going on? >>> >>> -- >>> Signed, >>> Ethin D. Probst >> >> > > > -- > Signed, > Ethin D. Probst > --=20 Signed, Ethin D. Probst