From patchwork Thu Jun 1 12:06:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 687703 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp307801wru; Thu, 1 Jun 2023 05:06:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MlHRWUXMOhM5l3lA+pN7AWjr5o0h553qg6/2Cj6RmVhpbagmiAnuTvS84W10jjUzn3z0G X-Received: by 2002:a05:6a00:3923:b0:64d:42f6:4c7b with SMTP id fh35-20020a056a00392300b0064d42f64c7bmr9961229pfb.27.1685621200625; Thu, 01 Jun 2023 05:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621200; cv=none; d=google.com; s=arc-20160816; b=AYHMInZhd3tbUMDKWsqFBPtB2tu8l1UmUGMBvtb1Hya9DwZM9sWdJCE6tKTTQLMvWI ipy2L6A7DUfhA6FD0p0AE4l/4FCFxckI+tcPkErCL9xVdJsiUg1WXquqzmuWIulD4vzV JX2iN9SRxKGWOuhbKfwb7Tt0SDu1y0teVym61oUqDdKjgYlMBHwZW1cG+LQsjYnMnRe1 bP2SGy1J5eYvMcbHLyC7CwRCcSFbalKl65bAO0flg1bUUPo7TLIZ+p07Wuv4c3l4x8HW gyobVHabr92t9mqNRZkmd9410tdlzTvfwLzDonDSFPckK14VIM3/ymChlDzeX2J4zliU Xglw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=Lad3KiEH3JnoFsFx/7Ht/jIf2smrLTvkWs6hcocEV9A=; b=Ajfb2S53OlwCpvc6IAXtb7Gy6x3VIXS8izFePHcX7cs8meBiwdJ25EhGpgCbgFHW41 /jcLe6NivEeIrSOEWzP/8GMmvJp7TJIG/k3QPXPooQicWxUQig17OnA3z3ECDm/R2NSB grvgico/DKjXkbbjSL6g1IkESvqOFq3/ygWdxvSxkthh3cBDNPE9v5ZO2ECz+LhfrHLn xWk86BxD3n3e5lV68rasXaaesgquW3IYt74lFPz9TqjwTxOo7jAyzSYIfNOja8B3l8T5 5cHIMdP+g0M7JM95lvGzshx+f4KYNLTyElhX2xOkG4qEuBlQA+eHEHForx2GWS4uAczv Jdgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CmUffJ1Q; 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 h16-20020a633850000000b00530b3b98fc5si1604691pgn.417.2023.06.01.05.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 05:06:40 -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=CmUffJ1Q; 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 35925862D1; Thu, 1 Jun 2023 14:06:33 +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="CmUffJ1Q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 24F5B862F7; Thu, 1 Jun 2023 14:06:31 +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-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 919CD8627B for ; Thu, 1 Jun 2023 14:06:28 +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-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30c4775d05bso276078f8f.2 for ; Thu, 01 Jun 2023 05:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685621188; x=1688213188; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Lad3KiEH3JnoFsFx/7Ht/jIf2smrLTvkWs6hcocEV9A=; b=CmUffJ1QAqCdFwZPXJg9Y/5DooZsYZvg95LVki9h2Nig3cVHEq8wO87yyel9/84n6V QSKaRuLkZ3SQHvVIG2IRaxBz8TUYibtWM/7SqilG/5L0B8GyT5DeiEMGGHuGpQ0SvsVN AqmfIGN24Yir5imOeEV10dvjVvOm2Bxg+5efsJL5eWDDM/YywH6XAmhVqKopRTjEDqhh PMe9CwV+xE71XVWjpLpm4txMV2adpcgUjhaEped4ed/p+ITUCtiGk6bzYl/lh3juqUHU ukjncUztMA8da0DoNKRFTUk23Uc5w9WierrphCD3vk0TkA+bDDcCQYHHv+VM45ZJ2sdO mg4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685621188; x=1688213188; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Lad3KiEH3JnoFsFx/7Ht/jIf2smrLTvkWs6hcocEV9A=; b=VFLAv6MpTyl8I+SY9+v8uiP4TsO5kUDhulmyOTCs3bvzcZy1exkcxyJnpQpm1FBFRB 5SwFQzZjiHt3XStWc85AcmYQuS7IQDmXlLejN/ZYDy5vo82R/khxKRnTgcTbbAgT8OXN A/G1VukhsYivBvyRX74FS9jtiTdDlytA3L+Q4IjEGC8+coJiOkDdM0i/MfaPsLhsArgC b9tnbC3VPxHSygSvJ0TBXeYAFVEBWpza7w49ShSrCVublkzPY4x9hICKM/tlA82qMxpu PH3EcVIdCjaAtzcFkh68B6Tc/RH/8LuzevaRmXRTKSds8WL3p2xFO7PCjuHV52ogI13a eaYQ== X-Gm-Message-State: AC+VfDyPUEmgXJsCu917niRfutpbNvazih1q8nGSI4YhvI9IVz0D7BlE wQqQP49FAlQTgBmlpOlLK5//TRfLB2OKYrNSjUs= X-Received: by 2002:a05:6000:14b:b0:306:2fab:1f81 with SMTP id r11-20020a056000014b00b003062fab1f81mr1701851wrx.21.1685621187884; Thu, 01 Jun 2023 05:06:27 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id i14-20020adfe48e000000b0030ae499da59sm10097004wrm.111.2023.06.01.05.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 05:06:27 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH 1/2] efi_loader: delete handle from events when a protocol is uninstalled Date: Thu, 1 Jun 2023 15:06:23 +0300 Message-Id: <20230601120625.1843555-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.39.2 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 When a notification event is registered for a protocol the handle of the protocol is added in our event notification list. When all the protocols of the handle are uninstalled we delete the handle but we do not remove it from the event notification list. Clean up the protocol removal functions and add a wrapper which - Removes the to-be deleted handle from any lists it participates - Remove the handle if no more protocols are present It's worth noting that all our variants of efi_uninstall_protocol_*() and uninstall_multiple_protocol_*() end up calling efi_uninstall_protocol(). We could add the cleanup in that function only, however efi_reinstall_protocol_interface() expects the handle not to be removed. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_boottime.c | 45 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d5065f296aee..450524ddca2f 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -197,6 +197,35 @@ static bool efi_event_is_queued(struct efi_event *event) return !!event->queue_link.next; } +/** + * efi_handle_cleanup() - Clean the deleted handle from the various lists + * @handle: handle to remove + * @force: force removal even if protocols are still installed on the handle + * + * Return: status code + */ +static void efi_handle_cleanup(efi_handle_t handle, bool force) +{ + struct efi_register_notify_event *item, *next; + + if (!list_empty(&handle->protocols) || force) + return; + /* The handle is about to be freed. Remove it from events */ + list_for_each_entry_safe(item, next, &efi_register_notify_events, link) { + struct efi_protocol_notification *hitem, *hnext; + + list_for_each_entry_safe(hitem, hnext, &item->handles, link) { + if (handle == hitem->handle) { + list_del(&hitem->link); + free(hitem); + } + } + } + /* The last protocol has been removed, delete the handle. */ + list_del(&handle->link); + free(handle); +} + /** * efi_process_event_queue() - process event queue */ @@ -627,8 +656,7 @@ void efi_delete_handle(efi_handle_t handle) return; } - list_del(&handle->link); - free(handle); + efi_handle_cleanup(handle, true); } /** @@ -1396,11 +1424,8 @@ static efi_status_t EFIAPI efi_uninstall_protocol_interface if (ret != EFI_SUCCESS) goto out; - /* If the last protocol has been removed, delete the handle. */ - if (list_empty(&handle->protocols)) { - list_del(&handle->link); - free(handle); - } + /* Check if we have to purge the handle from various lists */ + efi_handle_cleanup(handle, false); out: return EFI_EXIT(ret); } @@ -2777,11 +2802,7 @@ efi_uninstall_multiple_protocol_interfaces_int(efi_handle_t handle, i++; } if (ret == EFI_SUCCESS) { - /* If the last protocol has been removed, delete the handle. */ - if (list_empty(&handle->protocols)) { - list_del(&handle->link); - free(handle); - } + efi_handle_cleanup(handle, false); goto out; }