From patchwork Mon Jun 12 15:35:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 691629 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d91:0:0:0:0:0 with SMTP id b17csp214419wru; Mon, 12 Jun 2023 08:36:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7TSyNxMYnyRfeCBgd1XFAgr/K7G2OQQcFrR6WNGq+4jruMpiD1xjZGLBEcimPXX99LUVD2 X-Received: by 2002:a05:6a00:22ce:b0:64d:2c58:f86f with SMTP id f14-20020a056a0022ce00b0064d2c58f86fmr11707731pfj.0.1686584176603; Mon, 12 Jun 2023 08:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686584176; cv=none; d=google.com; s=arc-20160816; b=P4itq8U5icdwoLsLdcICLG77BXvQhTZqgipXqOBAgqOsmkFH4ydJxfoY9tokXW4+iX xqJcwu46+A+EvJgoEdiBhDb3Tc5tomkRJ0dsHBiHPee4kPteIM0CxNQ4JOsISmNcheiQ euBVfsCXCjRYC8g9zP1oiH9PyAnbX9G3y47SMeLtEsOt1epBwlb7hzAnofW6F649gyVn 3I917bkkMevp9TBOg5jDvNrczVYbUsH+Y/l82qDLmbsXA8RT/ol85P/rcDcjodebTCTo 6EHUvcjZTSpNZSIRfHFWc+pabNH7NB7BP9bDs+bUyjaywC721LUeZl4yzahm3C3HW6iy fnhw== 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=itQBwcnRMwYgaRV1u3GCdxr2r5dIz320Si025D6k12I=; b=0aRxzR8wV5bKVWqC8x6mUKXhWumOq9gBSR4fkA6+hR6ydli98pk8SWjunVdUPyq1Zu u833TKlhgKrQfwoborB8Pmyp8YhAEr79cBGuIHRmGbMc4wGNX3dPd6o6oJa/PudEks5v et//zxr6173aQp5F3SjDCKAurFRd5UCNaB3jATiiNEGPPIMV15Y5br0lz90QEjJsepT2 SxjpV8c3SZIUBHe74ZzWVyQmUJilxorpMizVtJFvrpKH/mnecYsWIrwDTR89QgAf1I6S IhPuwXkEqPdhXi5JCG81XvNT1bJEOgQyv1ndxXfwCmCJjLWILzwV0OOUJjTsICqgfS+V nkRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CthUqnCV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id d18-20020aa797b2000000b00654d446d357si6949796pfq.177.2023.06.12.08.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 08:36:16 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CthUqnCV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 CEADE84682; Mon, 12 Jun 2023 17:36:07 +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="CthUqnCV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B992385CB5; Mon, 12 Jun 2023 17:36:05 +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-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 B461B8211C for ; Mon, 12 Jun 2023 17:36:02 +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-x329.google.com with SMTP id 5b1f17b1804b1-3f732d37d7cso45515365e9.2 for ; Mon, 12 Jun 2023 08:36:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686584162; x=1689176162; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=itQBwcnRMwYgaRV1u3GCdxr2r5dIz320Si025D6k12I=; b=CthUqnCVRkUc+6lpjhxwvk1YNsppQOE654G8c+Gko+wwkVXxlkic7aXH+MGnombl3k Ueod9AMe3SaipZsdBEPQK5NlOkbDJ870ct0X9ZZET+ADlHhG75RXX5LTZe6DNBOqbvZv bJPzhx2rkxaxKVTmo9aZVKdxVV9r1mUpdxywaI2FsvZQhBT6Yc+CMve38hPts2IpR8JU E3wN6Rap4DIxdjNrYbbXNFAMAwdC+i3fulLZA6q8S+CyOPkEteFn0RSQdD/FIIIy+dKn /XNcFaf142Q7QCU6gbW3y0t2taC5ARf8RZLwiwtt3VxT4AxgUDyCRgFlzBUK9cK2VyEf VG7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686584162; x=1689176162; 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=itQBwcnRMwYgaRV1u3GCdxr2r5dIz320Si025D6k12I=; b=GsoTO17jB64YDYp09M2U59nMLSYh4uI4ZdTSEkssy5QrkUGaV2O4mENE4D2kPRaN2k 8D9slSh0X8DZPZC4o9wwlGSYDNbMs+RpguI9gocU/geAeOA5iF+YmBqOTju4/95AZ0wq BFIcb65c4wwrZSEXlLAK/rygEn0DIZLs5c+SZw1ttXFnAgxn/mn3MXGVo1JIEe+4dnf9 JVfAtEnWoTHaQGhoW7tQ+zsdm1Co0qSME96buwe2nhYUUQFPKvhGshAeBijJfLgxac0l 7QHzAitDr1CdJkExA/XAbpFKFPQ2yhk1JHIGvYUqY0bQJu/55F0An7lSSCvnCKbo8jJN PtNA== X-Gm-Message-State: AC+VfDzzKfA3fa/3YU2PKvSk0OxdCRc7ZipcRKqXaQ26SKBNgCaW4G2r cksqnsXhzICZjvbRfBlhu9GnqIpSKJgNry4a5XpHdw== X-Received: by 2002:a05:600c:aca:b0:3f6:2ae:230e with SMTP id c10-20020a05600c0aca00b003f602ae230emr7667702wmr.3.1686584162103; Mon, 12 Jun 2023 08:36:02 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c230800b003f7ed9dae70sm11770909wmo.0.2023.06.12.08.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 08:36:01 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH v2] efi_loader: simplify efi_disk_remove Date: Mon, 12 Jun 2023 18:35:58 +0300 Message-Id: <20230612153558.588760-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. Signed-off-by: Ilias Apalodimas --- - Fix CI issues. dev_tag_get_ptr() is called for UCLASS_BLK or UCLASS_PARTITION only lib/efi_loader/efi_disk.c | 80 ++++++++++----------------------------- 1 file changed, 19 insertions(+), 61 deletions(-) -- 2.39.2 diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index d2256713a8e7..62ca8d7fa516 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -691,90 +691,48 @@ 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 = event->data.dm.dev; efi_handle_t handle; struct blk_desc *desc; - struct efi_disk_obj *diskobj; + struct efi_disk_obj *diskobj = NULL; + + id = device_get_uclass_id(dev); + if (id != UCLASS_BLK && id != UCLASS_PARTITION) + return 0; 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 (id == UCLASS_BLK) { + desc = dev_get_uclass_plat(dev); + if (desc && desc->uclass_id != UCLASS_EFI_LOADER) + diskobj = container_of(handle, struct efi_disk_obj, header); + } else if (id == UCLASS_PARTITION) { diskobj = container_of(handle, struct efi_disk_obj, header); - efi_free_pool(diskobj->dp); } - 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); 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 *