From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by mx.groups.io with SMTP id smtpd.web11.5814.1626541286388850138 for ; Sat, 17 Jul 2021 10:01:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UNVkrwqI; spf=pass (domain: gmail.com, ip: 209.85.218.46, mailfrom: harlydavidsen@gmail.com) Received: by mail-ej1-f46.google.com with SMTP id dp20so18359839ejc.7 for ; Sat, 17 Jul 2021 10:01:26 -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=Ec3KbkfBpTWTNwE4g1/uYldYJ5O7Y8xttPV08F4DC2c=; b=UNVkrwqI4ZqUGqjDUW3Utzs+SBve4+fjSszlq0VuTXVOfTCve5VZOp6eQ9URkxHJQc saXTzCn2Oc/Xmja219aVSPbRS5W4tn/0ok9NThsk3+vT4jkB2w8FlrGKozfP4OtEC1az vrDgBMvjCk3zQgHTZtHrR2ALc+07y0jN0o7EY9O/EwzFYFG4ugyFYUqaMCLzJyOtup67 t5m6Dv6zOLHNY9P5foAVd+aPt4NoJ4kGfCwMvYS80OVg0xTISD+P4u3UxW1ZmQyeR3RU mgeTTK7jECyeNGgyeVW8/WE9KvmovaRrDUuuXKwLYmhOd504XCPss3g4q2iNPcuZxpiS atGw== 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=Ec3KbkfBpTWTNwE4g1/uYldYJ5O7Y8xttPV08F4DC2c=; b=rB6UBAuZLprs6Ao4fyV0KLv2t2VL13s22dn81tFjMgdJHqaPwT+An7gWtRISBElwRD 7pQ8s2wjTbtotq8g3DeNVUVLxTN0WgCTT2+hu/tTFVx89IEuA9gIxAfTfBuRX7Cyj7XN HdCpGUMHOsXsVv4TIpn/Bs+fNRxU0SFzlte2hQjViDdUd4Y7sFMXF3AWOauuNI/+zrCD aScEYdl/fbd2HCB3NFo6y34PWdeBAoJ6XoGxJAUaUi6tBOA8J7RCQ8tIXLBSASjfKGDb P4Xa/u7dt6U8GYqRLlEgrfTtLVhfvkXlQt+yGW7kXSjP/qNUC1k0kLbmXCJ7/pkYt8KB tRIg== X-Gm-Message-State: AOAM532xHQ9lRAaPFC4Woz+Y/PN9TQ0Q6KvlvrfG9dtCQS9EjdQuEyd1 NfGcxlxnRU7PHrwNGH1ZADI2rTJ+xn+uC+pyOWc= X-Google-Smtp-Source: ABdhPJwGZ7J69/6d9YyO1M5j+wX/fnRUHNgviVYXLxy2vzGmWSWhjxp1hgwS3EC3gb3X/N9UEGl2JoXrA2Sy1OhZfm4= X-Received: by 2002:a17:906:6c91:: with SMTP id s17mr17922508ejr.403.1626541284949; Sat, 17 Jul 2021 10:01:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:3f89:0:0:0:0:0 with HTTP; Sat, 17 Jul 2021 10:01:24 -0700 (PDT) In-Reply-To: <88AE4AB4-12BA-433C-9EA4-EDC01B30DAD1@apple.com> References: <88AE4AB4-12BA-433C-9EA4-EDC01B30DAD1@apple.com> From: "Ethin Probst" Date: Sat, 17 Jul 2021 12:01:24 -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 I mean, possible... The code I'm using to initialize the handle buffer is t= his: ```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 a= re > 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 handle= s. > > 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 check > 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 > > --=20 Signed, Ethin D. Probst