From patchwork Mon Jun 12 10:07:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 691628 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d91:0:0:0:0:0 with SMTP id b17csp58640wru; Mon, 12 Jun 2023 03:08:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66iX6zmb1yS1ks7ZLEgU6DfmHwpK9JCFlURguSJBJM0fZ4J9r4g6qXBgZFxPBK7lvOrxnb X-Received: by 2002:a05:6a20:5481:b0:10f:9bea:5a61 with SMTP id i1-20020a056a20548100b0010f9bea5a61mr11347103pzk.2.1686564481232; Mon, 12 Jun 2023 03:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686564481; cv=none; d=google.com; s=arc-20160816; b=ULaHTMsYvvCheabraaE+uQYvsXedz9BboCZsqluqbvkLVgvEaQzZVH4bFe2qHbklrd 9j8rnOiCP9Pp7Sx4lKCVqmYThjDayAthHMs44W6IsFQU/iPOZRKR+ub1xpTbkFs+XabY ajTLQvUA7CgHCPOYfa6qks54Fvjh40N5krfXRTzCQmkybwFmOfr3YdAXMqTsiLDDe2G5 CtnMkuRAGeKULAXaNHVfn4cVb1qnDTeHuomPuExjCOy8+Ms4oZiWesXemzlqc8f8nhTI e/moR2TkbTMvszEaUi1NVg4bgyx9lJsv4w8+o5DxX0bSsFWB4tJ9qWBltw76hfCDZp+A EJ3A== 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=dCXg3XgwXY1UylHnBicMHjM5UNDgtRkm6Dtn1DaSqCA=; b=tg7a+zBohtUdb4WrzzU7+aWAfWRBis7umaaqxx1/IFv60XuuNjkLwoQHophwX0pXo8 fuS7GBvcyTdoWjJvPcqVLT6D5SRx+I+4TYsNjsib5TK94+aXtYG7PaH4hsO3ZGTj0r7x yz0vVGr/irRA0csF4JlosWHmTavziTeeXkclMIbL4E4K49j1V3wg6fQ/Ehk8MsVOFza3 02yIk7IWBx4ZF+78kg7EFQISV4zyTESb+MJ5gfc09tB3wZ17gJkACpp0AvrUhfMk2X2I B31NPH5O0ug8+ZFVCSRx1P+5EYVrt8wvryUFrpd0aAk8KUy8hNwecGufYbEJhoVjCEXp Me5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=btiu5etL; 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 j191-20020a638bc8000000b00536e63c8643si6759669pge.558.2023.06.12.03.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 03:08:01 -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=btiu5etL; 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 EE62B84682; Mon, 12 Jun 2023 12:07:53 +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="btiu5etL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA03384682; Mon, 12 Jun 2023 12:07:51 +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-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 9C8F382A2C for ; Mon, 12 Jun 2023 12:07:48 +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-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f7f543fe2fso41398275e9.2 for ; Mon, 12 Jun 2023 03:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686564468; x=1689156468; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dCXg3XgwXY1UylHnBicMHjM5UNDgtRkm6Dtn1DaSqCA=; b=btiu5etLXeLeFp2rwy5N2m21L4oN8jIAtI5tQKaRtMR/iwKhIpSYlWnK694FjJyKFO CgyovyC6GbStVxzwwwSEvsiwxo1cAiWR2l0QUqhjMEcscjELdFDxbY7315kW/vVl6OJC jcN4/m9xBr4lXxKEI1Orw1gxSzbRr+xxRCWusj8Hydmri6c1rOlt43SH9OUyl+lq7Qdm zzZh+xZJv6uLSySqNgdpL9CKhJk1V6AxMWVzFNtUjllQSIJmBtN/msoAecdh6tZHIITi Tg/oA6BL5uQ5JSHlBUOw+uqeOJ0HB5IEIEK65oP6uVoFiTvlj9drsn1I3mQreLQUT3p/ gqyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686564468; x=1689156468; 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=dCXg3XgwXY1UylHnBicMHjM5UNDgtRkm6Dtn1DaSqCA=; b=mFggfFzeekJR05z3UbrQZkmGJgNHwJpEz8UPxpX4A9pPVRRTHE6oVrySz0o8PtmBKf a8JaWmarFNV/ZLaNyQijCCNwTNmi3VeTMzAM77bNAc/4Zg+UQm3azJmYh1ckZlK+EDjr OJj+25OUd2kawwfWvNk9dgKjmwpaqMJvyWhRxC+qtvTljEk4IKfTt2aNoO96ZCG6SQd0 RpKg3WNbXEVdSmUprymc/sq/nUo5TCdtJqW2T6pEaKyuewzrrPSIR/ymKn33UrqUPeNh OyJlVNtMnKczsb3/c7wpekA5nVMCYy6cB2FsEtaK4ecUb2RCtf5uvLD/ImLaUBmx85bb 9Row== X-Gm-Message-State: AC+VfDz4ZAwmkrQIwp7oI/ZbYeZyf5AAHpoYRVfbGcjtLd39Zms9W0gt cIw2/JfpUe+0nTHukBffrU7ZwehXXikHJhADqMQU/w== X-Received: by 2002:a05:600c:b41:b0:3f6:f56:5e82 with SMTP id k1-20020a05600c0b4100b003f60f565e82mr6706664wmr.3.1686564467922; Mon, 12 Jun 2023 03:07:47 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id f25-20020a7bcd19000000b003f7ff520a14sm10858310wmj.22.2023.06.12.03.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 03:07:47 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH] efi_loader: simplify efi_disk_remove Date: Mon, 12 Jun 2023 13:07:44 +0300 Message-Id: <20230612100744.39306-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 Instead of discovering the ID of the device and call two different functions for a block device or a partition, we can rewrite efi_disk_remove() and handle the minor differences between the two variants internally. As a results we can simplify efi_disk_remove() a lot and get rid of the extra efi_disk_delete_raw/blk calls. bloat-o-meter seems the size reduction as well add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-84 (-84) Function old new delta efi_disk_remove 160 76 -84 Total: Before=784824, After=784740, chg -0.01% Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_disk.c | 82 +++++++++++---------------------------- 1 file changed, 22 insertions(+), 60 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index d2256713a8e7..8ab476b02445 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -691,90 +691,52 @@ int efi_disk_probe(void *ctx, struct event *event) } /* - * Delete an efi_disk object for a whole raw disk + * Delete an efi_disk object for a block device * - * @dev uclass device (UCLASS_BLK) + * @dev uclass device (UCLASS_BLK or UCLASS_PARTITION) * * Delete an efi_disk object which is associated with @dev. - * The type of @dev must be UCLASS_BLK. + * The type of @dev must be either UCLASS_BLK or UCLASS_PARTITION. + * This function is expected to be called at EV_PM_PRE_REMOVE. * * @return 0 on success, -1 otherwise */ -static int efi_disk_delete_raw(struct udevice *dev) +int efi_disk_remove(void *ctx, struct event *event) { + enum uclass_id id; + struct udevice *dev; efi_handle_t handle; struct blk_desc *desc; - struct efi_disk_obj *diskobj; + struct efi_disk_obj *diskobj = NULL; + + dev = event->data.dm.dev; if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) return -1; desc = dev_get_uclass_plat(dev); - if (desc->uclass_id != UCLASS_EFI_LOADER) { + if (desc && desc->uclass_id == UCLASS_EFI_LOADER) + goto out; + + id = device_get_uclass_id(dev); + switch (id) { + case UCLASS_BLK: + case UCLASS_PARTITION: diskobj = container_of(handle, struct efi_disk_obj, header); - efi_free_pool(diskobj->dp); + default: + return 0; } - efi_delete_handle(handle); - dev_tag_del(dev, DM_TAG_EFI); - - return 0; -} - -/* - * Delete an efi_disk object for a disk partition - * - * @dev uclass device (UCLASS_PARTITION) - * - * Delete an efi_disk object which is associated with @dev. - * The type of @dev must be UCLASS_PARTITION. - * - * @return 0 on success, -1 otherwise - */ -static int efi_disk_delete_part(struct udevice *dev) -{ - efi_handle_t handle; - struct efi_disk_obj *diskobj; - - if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) - return -1; - - diskobj = container_of(handle, struct efi_disk_obj, header); + if (diskobj) + efi_free_pool(diskobj->dp); - efi_free_pool(diskobj->dp); +out: efi_delete_handle(handle); dev_tag_del(dev, DM_TAG_EFI); return 0; } -/* - * Delete an efi_disk object for a block device - * - * @dev uclass device (UCLASS_BLK or UCLASS_PARTITION) - * - * Delete an efi_disk object which is associated with @dev. - * The type of @dev must be either UCLASS_BLK or UCLASS_PARTITION. - * This function is expected to be called at EV_PM_PRE_REMOVE. - * - * @return 0 on success, -1 otherwise - */ -int efi_disk_remove(void *ctx, struct event *event) -{ - enum uclass_id id; - struct udevice *dev; - - dev = event->data.dm.dev; - id = device_get_uclass_id(dev); - - if (id == UCLASS_BLK) - return efi_disk_delete_raw(dev); - else if (id == UCLASS_PARTITION) - return efi_disk_delete_part(dev); - else - return 0; -} - /** * efi_disk_get_device_name() - get U-Boot device name associated with EFI handle *