From patchwork Sun Oct 7 03:26:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 980020 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42STSJ4xBZz9sj3 for ; Sun, 7 Oct 2018 14:26:52 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id AC532C21EA6; Sun, 7 Oct 2018 03:26:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 48559C21DD7; Sun, 7 Oct 2018 03:26:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1A294C21DB3; Sun, 7 Oct 2018 03:26:37 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lists.denx.de (Postfix) with ESMTPS id 76F73C21CB1 for ; Sun, 7 Oct 2018 03:26:37 +0000 (UTC) Received: from localhost.localdomain ([46.232.147.139]) by mail.gmx.com (mrgmx001 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MQ2Wx-1g4r7K12Kx-005Ld9; Sun, 07 Oct 2018 05:26:33 +0200 Received: from localhost.localdomain ([46.232.147.139]) by mail.gmx.com (mrgmx001 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MQ2Wx-1g4r7K12Kx-005Ld9; Sun, 07 Oct 2018 05:26:33 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sun, 7 Oct 2018 05:26:26 +0200 Message-Id: <20181007032626.20635-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:rrqcoVYwEetSSIFfI18zUAEng3LEC+jy/kUI6dA/ZFoKNiJT9zG ZEjyUGRk6cLB5SMx0exfyCnzi9NAkDl5PtrqcjGQmXxn5X8bVF0pO7PRxVZOsYIkLbmzmf/ /C3n/Vg5e6EJ+7FHOKOL1jN4aKOgP2x3akz1njPzLte+r0zfxqhmh/auqoA4CCXEpleCOCk aD7Tq0juCSunG4ACcygkA== X-UI-Out-Filterresults: notjunk:1; V01:K0:D/egWoUyA+4=:+2pd4/7MlflId882kp3ugg wD2UvznTXV/3u2tF3iS5fM+KYYlem7sQ4YxX+7M2eeDyo8Ut9zTKkO8pMouEEaDk4YkrErE9s t1LtVsZgtcdnatdcfVFdQMZILbsq9sRnrtF2aSW0Aqqmzf5Mrsy8U5L0+QYxBZLO86boWYPzD PM7IHttbcZCdMGC2JUnMJvn4/ps7aRPbaRMYVwobnGTNnmtjYxCIEo7hBr4zlVt3iIb93H/xA GuT3Rkl3RjHLET0F6ik06FikihlPcwtALzhl16P68wHlepszhDN9mg/qgz2ZDXdzcJhJZjN+j bV9TjF+jsuHPaknBHYnc25Pf9K1c/uU0VemZ3019p3bqyPpJTzVtmVHXjnGJV9y2fPdjX+d/+ Sj/IqeDfkjXtFvE6zUMmo2f0jzMvaK6+mzo2YD23P34WkDwpCWOetgVc7r6VUzpg5m+XBhUS8 uDC5p6A9+bgobmc0ypkRBJYoqlNPKVdAds6KacZlV/1rqppqC9IFi86zGWWikY2hhBktdwojP Z2IaxKurKcSZzewGL4ehXhmtXqDdMwMK+1LVcHjDrHxNCP1MsXrBnE4PC22/H9mQ0a9NR7JNi H+SOyJ4AhLLXNXbVaBKfNdMrqYLuPFsfFgXHHAXnnd+P9XmByHqJpwUmYofH9iTbAIg47YwNe Uz7gFNwnkPRDYr9+cOr4ybNePZLn2H8COUGyZgTcYOnJeu6r2feXx56Naa64HQJGBHHT354KW KULIGG0uWjaXQ5qkCLhxvWHquh2rQduu46EScV+epzxLSiprf3b9VXy0bKcBYngUHITAVq/8S xBRti0MB7iwxNbnToc6LDKOYAtdGg== Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Tom Rini Subject: [U-Boot] [PATCH 1/1] efi_loader: correct signature of GetPosition, SetPosition X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The UEFI spec requires that file positions are passed as u64 in GetPosition() and SetPosition(). Check if the file handle points to a directory in GetPosition(). Provide a unit test for GetPosition() and SetPosition(). Fix Coverity warning CID 184079 (CONSTANT_EXPRESSION_RESULT). Add comments. Fixes: b6dd57773719 ("efi_loader: use correct types in EFI_FILE_PROTOCOL") Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 4 +- lib/efi_loader/efi_file.c | 39 ++++++++++++++++---- lib/efi_selftest/efi_selftest_block_device.c | 30 ++++++++++++++- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index e6566bb358..3194db3517 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1175,9 +1175,9 @@ struct efi_file_handle { efi_status_t (EFIAPI *write)(struct efi_file_handle *file, efi_uintn_t *buffer_size, void *buffer); efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file, - efi_uintn_t *pos); + u64 *pos); efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file, - efi_uintn_t pos); + u64 pos); efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file, const efi_guid_t *info_type, efi_uintn_t *buffer_size, void *buffer); diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index f3226a8dc0..beb4fba917 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -443,28 +443,51 @@ error: return EFI_EXIT(ret); } +/** + * efi_file_getpos() - get current position in file + * + * This function implements the GetPosition service of the EFI file protocol. + * See the UEFI spec for details. + * + * @file: file handle + * @pos: pointer to file position + * Return: status code + */ static efi_status_t EFIAPI efi_file_getpos(struct efi_file_handle *file, - efi_uintn_t *pos) + u64 *pos) { + efi_status_t ret = EFI_SUCCESS; struct file_handle *fh = to_fh(file); EFI_ENTRY("%p, %p", file, pos); - if (fh->offset <= SIZE_MAX) { - *pos = fh->offset; - return EFI_EXIT(EFI_SUCCESS); - } else { - return EFI_EXIT(EFI_DEVICE_ERROR); + if (fh->isdir) { + ret = EFI_UNSUPPORTED; + goto out; } + + *pos = fh->offset; +out: + return EFI_EXIT(ret); } +/** + * efi_file_setpos() - set current position in file + * + * This function implements the SetPosition service of the EFI file protocol. + * See the UEFI spec for details. + * + * @file: file handle + * @pos: new file position + * Return: status code + */ static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file, - efi_uintn_t pos) + u64 pos) { struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_SUCCESS; - EFI_ENTRY("%p, %zu", file, pos); + EFI_ENTRY("%p, %llu", file, pos); if (fh->isdir) { if (pos != 0) { diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c index 1cd13042e9..d4e4fac1c7 100644 --- a/lib/efi_selftest/efi_selftest_block_device.c +++ b/lib/efi_selftest/efi_selftest_block_device.c @@ -308,6 +308,7 @@ static int execute(void) } system_info; efi_uintn_t buf_size; char buf[16] __aligned(ARCH_DMA_MINALIGN); + u64 pos; /* Connect controller to virtual disk */ ret = boottime->connect_controller(disk_handle, NULL, NULL, 1); @@ -392,21 +393,36 @@ static int execute(void) efi_st_error("Failed to open file\n"); return EFI_ST_FAILURE; } + ret = file->setpos(file, 1); + if (ret != EFI_SUCCESS) { + efi_st_error("SetPosition failed\n"); + return EFI_ST_FAILURE; + } buf_size = sizeof(buf) - 1; ret = file->read(file, &buf_size, buf); if (ret != EFI_SUCCESS) { efi_st_error("Failed to read file\n"); return EFI_ST_FAILURE; } - if (buf_size != 13) { + if (buf_size != 12) { efi_st_error("Wrong number of bytes read: %u\n", (unsigned int)buf_size); return EFI_ST_FAILURE; } - if (efi_st_memcmp(buf, "Hello world!", 12)) { + if (efi_st_memcmp(buf, "ello world!", 11)) { efi_st_error("Unexpected file content\n"); return EFI_ST_FAILURE; } + ret = file->getpos(file, &pos); + if (ret != EFI_SUCCESS) { + efi_st_error("GetPosition failed\n"); + return EFI_ST_FAILURE; + } + if (pos != 13) { + efi_st_error("GetPosition returned %u, expected 13\n", + (unsigned int)pos); + return EFI_ST_FAILURE; + } ret = file->close(file); if (ret != EFI_SUCCESS) { efi_st_error("Failed to close file\n"); @@ -434,6 +450,16 @@ static int execute(void) efi_st_error("Failed to close file\n"); return EFI_ST_FAILURE; } + ret = file->getpos(file, &pos); + if (ret != EFI_SUCCESS) { + efi_st_error("GetPosition failed\n"); + return EFI_ST_FAILURE; + } + if (pos != 7) { + efi_st_error("GetPosition returned %u, expected 7\n", + (unsigned int)pos); + return EFI_ST_FAILURE; + } /* Verify file */ boottime->set_mem(buf, sizeof(buf), 0);