From patchwork Tue Jun 20 06:19:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 694428 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp143653wrm; Mon, 19 Jun 2023 23:19:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Sv09wAWldBgFE4rFMrmXQswbbTXL0K0KcOsWkAyCYdkd9bBzHBRRm3QkucKr7RHvZNU2V X-Received: by 2002:a5e:8f09:0:b0:77a:ec0c:5907 with SMTP id c9-20020a5e8f09000000b0077aec0c5907mr8531274iok.13.1687241998268; Mon, 19 Jun 2023 23:19:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687241998; cv=none; d=google.com; s=arc-20160816; b=vIRYM+64Q3Ai7p9zaK6siYSIJI/U69vT6QHql98EiHTSga6EZbd8YSKxWAF78ZAnST lMMZNGGRoYrN5iuVpSxA4RuRZ//zQQSGA/T/GID6SevmOGOJtt1VCs3SuAFS2NKBT3XJ Ns1tUxrnGlBbwaWj9SEkPb6tzIVvIX+6yK/OICsprc9L2CNZ1KtEbro2bNYXB4li6bN1 FbJ3Tg024/WHANsfqPjkaxxeWe7TkEdVsZN91UhqtZHhfXThQIxoEOozqJs09xP4lvj4 VfnpJ/fQAvKGzVUvfUDXG8VV8mNKA+Ziv2TGoCyMK/QqyTKdyU5pUVh5lYrS6fobPLm0 xUGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CoXKoGZoDowfsQalNyBZywdDmPy1Iws3Cwle/hL6gUw=; b=CFP5k73mpVNuvsD5cGSZ9ghrfg72M9FZZa9lAA/6P2/3SyqOQaT1jeRomptWpc6B2d c2MmKjNR+O/z67I3INlOFy1O5wV+mRL9w2EfTfmn3um6hiXlTaevm9NkfsUtoKZAvVm1 w9WJ/1yvEUc8P45Kaxfd/aytEIdAlUYUq36gG78704wAZ+VIZIHritZ1kVU7ekASLeu/ S71LfHS6CAA2dZAD+ExVCbpzkxIDvs0sn1jwx+7t0Qq/qgSwwouya8m9v2khEOGWTSDV M4Fwwtmbk1Mt1ONeG2UAS43o/eCwEb8gE/cOJdT0YdZA2538IjOaDD3l3RtGb5qwbUSI fydw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bd7XuQOb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id t25-20020a056602181900b0077e28bc0f87si527180ioh.97.2023.06.19.23.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:19:58 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bd7XuQOb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF1D686259; Tue, 20 Jun 2023 08:19:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bd7XuQOb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7E6AB86341; Tue, 20 Jun 2023 08:19:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 38D2085FE5 for ; Tue, 20 Jun 2023 08:19:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9883123260fso294814866b.0 for ; Mon, 19 Jun 2023 23:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687241977; x=1689833977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CoXKoGZoDowfsQalNyBZywdDmPy1Iws3Cwle/hL6gUw=; b=bd7XuQObu19LVgQzeUk7AhTzGi4cKvQwHEXgMzWbuxoSxj/yZyIhzROyXmxEJdzEYx BoNybhhzACviMfPNVL8gQC2+If0QQhQQ4Np3RGOFtty78OEhQqYp/EAnGEgpLmPphsi0 VAYrDsqxB9jPGl5M9nQVgVT77o9lxJ3WAabJyZ3B+NGxjjaPsU+FvYFPwJSRWsfKB5pe hcLxcHjI1MfTDB7QadSwacfQPOUscNleSfUVcRdt5H1W6VWYFS1xgjtLEeAgXYuV8Sb9 QqRXasuw3v8oMVzS+p3HQYwYogfeyIkLjgHDn3V0NFXKTToqF8H9PC5Cn9oCU67mLb+A 5TZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687241977; x=1689833977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CoXKoGZoDowfsQalNyBZywdDmPy1Iws3Cwle/hL6gUw=; b=URyqTwwyaYNJp/8oJ29z4z+MFYBqhg0E7elWWiDraZmxFcHu9gr1AM/W/mZInTfa3+ CpJtrkaTAjyZ3fzej6LjGXUlL2sHuTilwst1JVT/r0KlXBLW4E/TaXzMy78kdTL//nMm wkCSiTEQG+Y1Y0woQw55W8hRzRcuxKFM9c7D/oVdSb1phnD/pM4qGSnAJav/0IIxnaGJ D3JOga1ROgDyXwHqhoeY3YGybwNiWo/uRG/zM6wbgOtYg4Kl4KaP/XfVsgqKCUwzScbr HfUl+h7jnvzxwDVTwukcPX3i7zIdVB6vriMycvDD/iZufIxPI+hnlnKbwALb9lVVnKHZ deHg== X-Gm-Message-State: AC+VfDydV7hHin41TehCjHtQnKqouM+KtcTZmuxxKAk0pJcZTNDmVKa0 fh9uCdhwBeoUAltU0qTYv0JQVCO/ohTlNXnCHNDN+w== X-Received: by 2002:a17:907:3e97:b0:973:344:6a39 with SMTP id hs23-20020a1709073e9700b0097303446a39mr9687665ejc.76.1687241976885; Mon, 19 Jun 2023 23:19:36 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id a22-20020a1709063a5600b00988e699d07fsm729988ejf.112.2023.06.19.23.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:19:36 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH 1/4 v2] efi_loader: reconnect drivers on failure Date: Tue, 20 Jun 2023 09:19:28 +0300 Message-Id: <20230620061932.113292-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620061932.113292-1-ilias.apalodimas@linaro.org> References: <20230620061932.113292-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean efi_disconnect_controller() doesn't reconnect drivers in case of failure. Reconnect the disconnected drivers properly Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) -- 2.40.1 diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 5006c0e1e4af..d44562d8f4e0 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -97,6 +97,12 @@ static efi_status_t EFIAPI efi_disconnect_controller( efi_handle_t driver_image_handle, efi_handle_t child_handle); +static +efi_status_t EFIAPI efi_connect_controller(efi_handle_t controller_handle, + efi_handle_t *driver_image_handle, + struct efi_device_path *remain_device_path, + bool recursive); + /* Called on every callback entry */ int __efi_entry_check(void) { @@ -1298,7 +1304,7 @@ static efi_status_t efi_disconnect_all_drivers const efi_guid_t *protocol, efi_handle_t child_handle) { - efi_uintn_t number_of_drivers; + efi_uintn_t number_of_drivers, tmp; efi_handle_t *driver_handle_buffer; efi_status_t r, ret; @@ -1308,15 +1314,30 @@ static efi_status_t efi_disconnect_all_drivers return ret; if (!number_of_drivers) return EFI_SUCCESS; - ret = EFI_NOT_FOUND; + + tmp = number_of_drivers; while (number_of_drivers) { - r = EFI_CALL(efi_disconnect_controller( + ret = EFI_CALL(efi_disconnect_controller( handle, driver_handle_buffer[--number_of_drivers], child_handle)); - if (r == EFI_SUCCESS) - ret = r; + if (ret != EFI_SUCCESS) + goto reconnect; + } + + free(driver_handle_buffer); + return ret; + +reconnect: + /* Reconnect all disconnected drivers */ + for (; number_of_drivers < tmp; number_of_drivers++) { + r = EFI_CALL(efi_connect_controller(handle, + &driver_handle_buffer[number_of_drivers], + NULL, true)); + if (r != EFI_SUCCESS) + EFI_PRINT("Failed to reconnect controller\n"); } + free(driver_handle_buffer); return ret; } From patchwork Tue Jun 20 06:19:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 694430 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp143745wrm; Mon, 19 Jun 2023 23:20:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EQPqYugBWRFR5LczuDkjNhW5AjY1Y9IIWSNUMNWuZvkTzm8XV+acOh9c6h8aLm8/eAh1h X-Received: by 2002:a6b:794d:0:b0:77e:3d2f:d1f4 with SMTP id j13-20020a6b794d000000b0077e3d2fd1f4mr4231501iop.15.1687242020259; Mon, 19 Jun 2023 23:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687242020; cv=none; d=google.com; s=arc-20160816; b=gYR8KtHYHEf6tt3frx96ziBIF4ap7LXc7G9xudpr7CUx3Gd+Cc+4NfCSSPdez3r7+2 4zyl1UlbqzQNDl5nBLTQiREm1nUKkCGZSGOaUrZrPy1gBOlWf8aX4BV07Deg6R36hxLB tP+gTkXz62RmOpesI613S3z5scmaI/jvAHEMqLKF2mVcBDzoZP+xk35stawxtOMqtUPP vSmG26n1hjyrNUk12Oh99Fn6lOv1/MgE5kH/OLEU9154C80MuSvGnulbviDlHJZJRx2p A9AzxA3TTi7iElxrTgPrvlM5UgwZZoEMnu9ymLKCZ04ISloSRAunqvrEnPB2qsALU0Is dMZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e3+i1sJtqzLfxmZTa48YlUeLD6oSYsh1gFKhsfobpIs=; b=mronokaqzTgO8JcJ28aDGA8NC3clLNpc81zx1rrKx3ftqlribhveVAUn+jPcthLQ5k UQwApLINNFSlhngc+V5Yh8s392K9S2g+uJmejx1i5uHOD1ouKWz9wIkZ91EXhjSQvtEl PrBoiP8o8Lw8/0RCwl/CQw5+RHERhg3VkNWUEQgOPrxtZKKkcrc55UW0Xnf3op4Q/CPL JtkDc/1A2TYu8O7pfmEx9B4x4TOPxzjn29d8IYPNP0EPc9/kkfHMnfwSPtZEfd+MECZz 7buWkXI6XYCW+Yw0bRfpbo2evhc4HRU4irOvc3gWKbs0v5q4xGmsTAnb+87bFsVe4cv7 6ivg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xaJyPTET; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id cp27-20020a056638481b00b00418a86d79a8si647671jab.184.2023.06.19.23.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:20:20 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xaJyPTET; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2E6FC86342; Tue, 20 Jun 2023 08:19:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xaJyPTET"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2119686259; Tue, 20 Jun 2023 08:19:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2751B86259 for ; Tue, 20 Jun 2023 08:19:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-982a88ca610so511266566b.2 for ; Mon, 19 Jun 2023 23:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687241978; x=1689833978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e3+i1sJtqzLfxmZTa48YlUeLD6oSYsh1gFKhsfobpIs=; b=xaJyPTETlCkrZeKEL4Q70zPy6Z9V41smCzfrT0e3DplrjDuO12d7D8feC8v9oPWbwy ouaPYiUFx2Y1jLjC4gVffmjFVzVvVm419L4Ko26Zf95sI7JFKLlHXA4CDESGT6Ns/Vfh 694MPjEN4Bfz8tszjRFubezuI1w2CNCdn0TduVqWcWQs3DH0oyDSlRTGyaNI2bj1e64X atd4QBUARgGxOv+wAy25Xjy9ZuAwCVz7afRVIZZWVru0+k0+7DVdj/KGnY91kXLBnaLm 982CGj6V/a8Aiut/qc5XoId4os7ZmhFOhH6pt2tzRED2zmpTZeT9l7sEhV9PMZKizlMl hJNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687241978; x=1689833978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e3+i1sJtqzLfxmZTa48YlUeLD6oSYsh1gFKhsfobpIs=; b=eLaLqgoCQth6loRYOzRm0zgMj5AxoGlP4JM5RXVOocge1l0EdBlHaU9kkiABI2DvTf eyAnpisMJXhe4Ho6wPs8Xx/BzOQA3YASVoUETkeYlV9vXVsH9tfwZQUD+mZ8F5HNmW7c fommcTExZCqZOx/w79RLHUQyTtwtTdfcDcBt/nvWlLYzZeLq2vbNthwjToIGldmLVvm7 4Rgx4fmSmKWEjx6NUrVkbszoxIAbCpDzTX8pFCJqnRbRItYjvrGxCP89IeC7Ep1R0NMN QvicADy4ncAk9g5rkJWrq5ACzmYaAVW+tNhZ9UMG0OD6di8Xo6tXq/kaMSfTqCiytK4X CnXA== X-Gm-Message-State: AC+VfDxU12g/VePLeWgOiT0wPwyPM8ldptw3owyi2jXq30BdRjHK5bJB LsT+q0R/uAq2O8DT6wkA7DSZJcFC/M8RYPXycrBDnQ== X-Received: by 2002:a17:906:7312:b0:96a:3119:ac0 with SMTP id di18-20020a170906731200b0096a31190ac0mr8367510ejc.69.1687241977824; Mon, 19 Jun 2023 23:19:37 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id a22-20020a1709063a5600b00988e699d07fsm729988ejf.112.2023.06.19.23.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:19:37 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH 2/4 v2] efi_loader: check the status of disconnected drivers Date: Tue, 20 Jun 2023 09:19:29 +0300 Message-Id: <20230620061932.113292-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620061932.113292-1-ilias.apalodimas@linaro.org> References: <20230620061932.113292-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean efi_uninstall_protocol() calls efi_disconnect_all_drivers() but never checks the return value. Instead it tries to identify protocols that are still open after closing the ones that were opened with EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL, EFI_OPEN_PROTOCOL_GET_PROTOCOL and EFI_OPEN_PROTOCOL_TEST_PROTOCOL. Instead of doing that, check the return value early and exit if disconnecting the drivers failed. Also reconnect all the drivers of a handle if protocols are still found on the handle after disconnecting controllers and closing the remaining protocols. While at it fix a memory leak and properly free the opened protocol information when closing a protocol. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.40.1 diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d44562d8f4e0..bfcd913dfad9 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1374,17 +1374,23 @@ static efi_status_t efi_uninstall_protocol if (r != EFI_SUCCESS) goto out; /* Disconnect controllers */ - efi_disconnect_all_drivers(efiobj, protocol, NULL); + r = efi_disconnect_all_drivers(efiobj, protocol, NULL); + if (r != EFI_SUCCESS) { + r = EFI_ACCESS_DENIED; + goto out; + } /* Close protocol */ list_for_each_entry_safe(item, pos, &handler->open_infos, link) { if (item->info.attributes == EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL || item->info.attributes == EFI_OPEN_PROTOCOL_GET_PROTOCOL || item->info.attributes == EFI_OPEN_PROTOCOL_TEST_PROTOCOL) - list_del(&item->link); + efi_delete_open_info(item); } + /* if agents didn't close the protocols properly */ if (!list_empty(&handler->open_infos)) { r = EFI_ACCESS_DENIED; + EFI_CALL(efi_connect_controller(handle, NULL, NULL, true)); goto out; } r = efi_remove_protocol(handle, protocol, protocol_interface); From patchwork Tue Jun 20 06:19:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 694429 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp143702wrm; Mon, 19 Jun 2023 23:20:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Zg15qfzn0rDczqzlUF0oV1ImiHXktjkiUaMDpC2yaZX6X0lL8nowqKYNa5HB3BTPLHNWr X-Received: by 2002:a92:d590:0:b0:33c:5182:6d04 with SMTP id a16-20020a92d590000000b0033c51826d04mr10776192iln.7.1687242009623; Mon, 19 Jun 2023 23:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687242009; cv=none; d=google.com; s=arc-20160816; b=TjaQw3FFuTntn1JHYuWuvnfzxt9I6PTRGtmnTsuyuMzgdLTgOquFpMxqJdKxRMClkr 92oKzi7vKi1bKpEBuaZ0vJqpgxFmgk1Zh0RfyJTPVReY1sBK7e4wC1EQS+albrb8wt0a cAResiNlCI1goH7XL79bfGpAJo8FhrOd7aOIo7kkVbzQn6ZYxFBU2DLByoH3RAspDL/F 2wXjphHcbf8U5glI6nVy6wHsL7LugAUnYN+YHWQAobiW85fjOQ1tl8rBiSdRwF10QDuu dBveEPge0PeML+1y+siE2g+Abi01peflEkmRKUOMwMXLMFuirdEuisrQG0am36SaFoWB NeEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rRIlS0WOrDFNDf/dI9FgWLb0cebVBlSg4oZ92pTlM/o=; b=KARLsbalbirBpGBViYyILJAzsHbyqr6YombTskde7jEEzpVA7IbfgAC75x4YkYUFYW uVkZNWeQZEATbTz9ZWCd4CnbFuwdU8UJGVpVKenfbJDsqgCk9TSGmoMtM55U0qud8Ssn dTXxAPmQt4IG6xk8zr3w+nVpLuYT/CdXctcGFW+2ws6W840Bf+xmuYDWcIs2MDeeRgvG ItLMYN43jor6bhsn8FosqxmoAAdCWsmDZCobih3sLMXgyBJFefaEivjKxehMntdWTuDl LhBLZ5F7I6pVi7Mv4/zOouSA4T8mKal5jelcsh0/mHJqbSy33jFVk6kJxxuee+Y+URpK /dzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M7CDMj4A; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id w2-20020a92d2c2000000b00342845766e0si528236ilg.37.2023.06.19.23.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:20:09 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M7CDMj4A; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3A5E486335; Tue, 20 Jun 2023 08:19:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="M7CDMj4A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3681E86308; Tue, 20 Jun 2023 08:19:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5E51286334 for ; Tue, 20 Jun 2023 08:19:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-988e6fc41ccso156877266b.3 for ; Mon, 19 Jun 2023 23:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687241979; x=1689833979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rRIlS0WOrDFNDf/dI9FgWLb0cebVBlSg4oZ92pTlM/o=; b=M7CDMj4AFAMFHeHJ50RSm/sCPZDWSaUxm9hx9ZOwtn2h1ky5ze9J+ih3qvuh4tDCo+ dYFb24aZl5IBr0ijtyZKf8fGgEv+kbdwEyO0ruPVAGQrw8f16O4XqWqAEFrbQ5AFi8C/ yKtQgfCuA4zvUBB2Ed43gSshgcb0QrSSWa+kCCxJS8WSJa9ku/4B1kxC9srX2DcZUX/I CDrM9ZGDz0fND69wDQBxt+jlATlhc/ARFyooSuQpKXwscitvlA0bJLCs5dIYkHYnMb9w VMMqbgt3s67+uoH2gTdCkE7RT5mo/iuOqrtLKiDRcRah8hRp6u5Kj3ypUVJ0Rwhz0kPq VX2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687241979; x=1689833979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rRIlS0WOrDFNDf/dI9FgWLb0cebVBlSg4oZ92pTlM/o=; b=NdzJiQCr/zORwwcBJz/FbveD2+MwagwtALcahUJLxegnSlWwFBo93Kzyab7nsLO4bs xGapkDQPrMVkBSUCwF4bTLFH6ukep1NtUNc8UdmlQpLAPBbcupifzDoMDCwiC1VcyZuL qoI31OZiER6Ba9MJPQVofjMfJNBwlk+7DCPATVLyYpy2VkEqYCqbVGvkpHlYp7Mx2uQg L3eDypM2NVv1c41rj0qRDtMxZdwgiHeOUdlEAvEgzPEWA2Je/qrEZdTVZer9ahGCdLXx kZNSfsDbruqIk98kvZ81K50zGV4kmm6O6EPVGSqmTVUemHdD8pjO3XELNz+H52zGm9qh 7ozA== X-Gm-Message-State: AC+VfDxC7cXGqbaa7rIWVA79asB1ltqEITOJedOK1C8prpSu0fSf5UyY 6e0X0Mu/rANTIBE4iSurkN4Wy50T6ePAIwUpCclEOA== X-Received: by 2002:a17:906:f84d:b0:965:6a32:7de6 with SMTP id ks13-20020a170906f84d00b009656a327de6mr7398012ejb.30.1687241978895; Mon, 19 Jun 2023 23:19:38 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id a22-20020a1709063a5600b00988e699d07fsm729988ejf.112.2023.06.19.23.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:19:38 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH 3/4 v2] efi_loader: fix the return codes of UninstallProtocol Date: Tue, 20 Jun 2023 09:19:30 +0300 Message-Id: <20230620061932.113292-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620061932.113292-1-ilias.apalodimas@linaro.org> References: <20230620061932.113292-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Up to now we did not check the return value of DisconnectController. A previous patch is fixing that taking into account what happened during the controller disconnect. But that check takes place before our code is trying to figure out if the interface exists to begin with. In case a driver is not allowed to unbind -- e.g returning EFI_DEVICE_ERROR, we will end up returning that error instead of EFI_NOT_FOUND. Add an extra check on the top of the function to make sure the protocol interface exists before trying to disconnect any drivers Reviewed-by: Heinrich Schuchardt Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_boottime.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.40.1 diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index bfcd913dfad9..d75a3336e3f1 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1373,6 +1373,8 @@ static efi_status_t efi_uninstall_protocol r = efi_search_protocol(handle, protocol, &handler); if (r != EFI_SUCCESS) goto out; + if (handler->protocol_interface != protocol_interface) + return EFI_NOT_FOUND; /* Disconnect controllers */ r = efi_disconnect_all_drivers(efiobj, protocol, NULL); if (r != EFI_SUCCESS) { From patchwork Tue Jun 20 06:19:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 694431 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp143804wrm; Mon, 19 Jun 2023 23:20:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5fXwYQHiU13VrQM1QLbuj3m06LO8N1y31mX2Ci+vURQ3f9KPb3g+FxIWV41WAfNFBXXTjI X-Received: by 2002:a92:cac8:0:b0:342:3364:f089 with SMTP id m8-20020a92cac8000000b003423364f089mr6049913ilq.11.1687242030724; Mon, 19 Jun 2023 23:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687242030; cv=none; d=google.com; s=arc-20160816; b=frU7tjivcRxixSkz3PxDLGlJP6k65L9ZNVmlknttsbt9T56nUmSbWLLiTnQDLLoayC FJxMYo7UgNAGhP0P7MnSNitgQjwdL/D1rna85ycuhKdi5Cf9stM6okEbYUFUhHS+dYcz DhVD4q+YIKOTFxVUoV578Ktm561I4yCMaT9V3n0PZJyUPmpXcLYMslt+076VemdsJDsB M3P1KslGpBnD9hj3wt28zQpYfjreLGnurJ6CJuvkEqkxmW+zDZyvDhKyiBizl77IvUyq 3ORcTIekfMU25RJJMkhsvZ79+k+Ug6zVnO0fBJ5x27btFfwLJr3Iw3Zbum3RfBwXMnwd Su1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LiDqNeZhZLIM3D16KTYBWODvOmJ+EKbVPW9xfazmhGY=; b=Oi57ceUiu4O3CkZY+8GuYctYVa+esje1yl5HB2TV48ztXS2S1DDeQy6Y6qYrSCE0qA 2nFD+KEBWoF4w1iEbOr1UfZuTad5BfZ9V93VU1QhSzaUL1Mpv3id+etf1yt+AoTjZFvf rR/h5fAt4Hv+JUYPc83Ep53o6kIqRZBOO2EyrNwZYhkeD3QqMnnlZUZJeXJsBgyiwugD 0okyQJ5ssodACSTv9XFUfjwHNQVTsAtvCZwzcxcYt969VymeopCichmRo1Al1yn6QiQz gcX3/zQ2mYpcvK+TCFIEixYyQ0XzjV0wMwtcC31PGGUj0/etAIOIKJ0wqiro2BaPy8/G kOug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CgoLlrhS; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id y15-20020a92c98f000000b0033bd634fe03si563869iln.155.2023.06.19.23.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:20:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CgoLlrhS; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3435686372; Tue, 20 Jun 2023 08:19:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="CgoLlrhS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F24C85FE5; Tue, 20 Jun 2023 08:19:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 390C286341 for ; Tue, 20 Jun 2023 08:19:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-983f499fc81so521122366b.3 for ; Mon, 19 Jun 2023 23:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687241980; x=1689833980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LiDqNeZhZLIM3D16KTYBWODvOmJ+EKbVPW9xfazmhGY=; b=CgoLlrhSL3LeBDkNy1sjiiyccUlFoWNtLaWyPnWDZcbd7mLJkt4+vBC9zsDpFyqwvn T2goWvAh1+AfgeBEdahMPwWY6F4DLou/7tcbMjOCu+Va4cIgxFiUWgTuc2q/+ByjKaX7 OhK9wjsKvAgxJFg25mZ2K3jl5zjyVAVpEUKLP7nVvwpbJdApnbDszt8Iqb+azEphEMos 3cOtFM5nFWYTpn2WPLPaypQ3RtZ2FmMmHxW+KOa+TJoNC6IOqrGXRxptXeDRog9ZLlD2 ly3HpmdofitxbTSqjajKC0WMqI1oPfLvaXXhkYKtRQR0MfC4NBJoPgUvcUDsCwE7Wx83 gyyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687241980; x=1689833980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LiDqNeZhZLIM3D16KTYBWODvOmJ+EKbVPW9xfazmhGY=; b=YbN/JbD60ezrEVLFxpgJBSLqa6VRrRx/cuX9Rs1396iLMGfZBaVHSesg7UYNBVBbaA ndEdixc2op9qrlfp46cGuTpHFWZJ/uf4rlCvmnHr8M55UfljzfFJ766KSsZ3xPg1Hgrm aWZ+N71bzfhMwfpDaQVHzGmOl+cbvscViTEqtYQyK59MmNrxxSWSig5s/taz6qyjinh/ wv50xXcErzBXlQCYXhZjNGisrCZHb20u0z3tPltF14sQxI+xWPl3Hd0itCkTZMJBhbZH todTzQYblVH//zNuSibnu64Vr2mkuL5UKwR8eEHxZKhTe6XX5iht+OXH4myAGBHWk3Cz 9E8Q== X-Gm-Message-State: AC+VfDxAypDpGxVpQAziyZhwqDbq77gPGPvSPAutwe7J1+qQPQgEKLzu 1zFdO8+5LSGS3wu3A/3T9D21pRcYd+/cS/RBzwgw2g== X-Received: by 2002:a17:907:934e:b0:989:5d0:3189 with SMTP id bv14-20020a170907934e00b0098905d03189mr2477362ejc.33.1687241979837; Mon, 19 Jun 2023 23:19:39 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id a22-20020a1709063a5600b00988e699d07fsm729988ejf.112.2023.06.19.23.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 23:19:39 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH 4/4 v2] efi_selftests: add extra testcases on controller handling Date: Tue, 20 Jun 2023 09:19:31 +0300 Message-Id: <20230620061932.113292-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620061932.113292-1-ilias.apalodimas@linaro.org> References: <20230620061932.113292-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean We recently fixed a few issues wrt to controller handling. Add a few test cases to cover the new code. - return EFI_DEVICE_ERROR the first time the protocol interface of the controller is uninstalled, after all the children have been disconnected. This should make the drivers reconnect - add tests to verify controllers are reconnected when uninstalling a protocol fails - add tests to make sure EFI_NOT_FOUND is returned if a non existent interface is being removed Signed-off-by: Ilias Apalodimas --- lib/efi_selftest/efi_selftest_controllers.c | 44 +++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) -- 2.40.1 diff --git a/lib/efi_selftest/efi_selftest_controllers.c b/lib/efi_selftest/efi_selftest_controllers.c index 79bc86fb0c3a..513c9868fda9 100644 --- a/lib/efi_selftest/efi_selftest_controllers.c +++ b/lib/efi_selftest/efi_selftest_controllers.c @@ -28,6 +28,7 @@ static efi_guid_t guid_child_controller = static efi_handle_t handle_controller; static efi_handle_t handle_child_controller[NUMBER_OF_CHILD_CONTROLLERS]; static efi_handle_t handle_driver; +static bool allow_removal; /* * Count child controllers @@ -85,8 +86,8 @@ static efi_status_t EFIAPI supported( controller_handle, EFI_OPEN_PROTOCOL_BY_DRIVER); switch (ret) { case EFI_ACCESS_DENIED: - case EFI_ALREADY_STARTED: return ret; + case EFI_ALREADY_STARTED: case EFI_SUCCESS: break; default: @@ -124,8 +125,8 @@ static efi_status_t EFIAPI start( controller_handle, EFI_OPEN_PROTOCOL_BY_DRIVER); switch (ret) { case EFI_ACCESS_DENIED: - case EFI_ALREADY_STARTED: return ret; + case EFI_ALREADY_STARTED: case EFI_SUCCESS: break; default: @@ -238,6 +239,9 @@ static efi_status_t EFIAPI stop( if (ret != EFI_SUCCESS) efi_st_error("Cannot free buffer\n"); + if (!allow_removal) + return EFI_DEVICE_ERROR; + /* Detach driver from controller */ ret = boottime->close_protocol( controller_handle, &guid_controller, @@ -342,6 +346,7 @@ static int execute(void) return EFI_ST_FAILURE; } /* Destroy remaining child controllers and disconnect controller */ + allow_removal = true; ret = boottime->disconnect_controller(handle_controller, NULL, NULL); if (ret != EFI_SUCCESS) { efi_st_error("Failed to disconnect controller\n"); @@ -393,7 +398,40 @@ static int execute(void) efi_st_error("Number of children %u != %u\n", (unsigned int)count, NUMBER_OF_CHILD_CONTROLLERS); } - /* Uninstall controller protocol */ + + allow_removal = false; + /* Try to uninstall controller protocol using the wrong interface */ + ret = boottime->uninstall_protocol_interface(handle_controller, + &guid_controller, + &interface1); + if (ret != EFI_NOT_FOUND) { + efi_st_error("Interface not checked when uninstalling protocol\n"); + return EFI_ST_FAILURE; + } + + /* + * Uninstall a protocol while Disconnect controller won't + * allow it. + */ + ret = boottime->uninstall_protocol_interface(handle_controller, + &guid_controller, + &interface2); + if (ret != EFI_ACCESS_DENIED) { + efi_st_error("Uninstall protocol interface failed\n"); + return EFI_ST_FAILURE; + } + /* + * Check number of child controllers and make sure children have + * been reconnected + */ + ret = count_child_controllers(handle_controller, &guid_controller, + &count); + if (ret != EFI_SUCCESS || count != NUMBER_OF_CHILD_CONTROLLERS) { + efi_st_error("Number of children %u != %u\n", + (unsigned int)count, NUMBER_OF_CHILD_CONTROLLERS); + } + + allow_removal = true; ret = boottime->uninstall_protocol_interface(handle_controller, &guid_controller, &interface2);