From patchwork Thu May 2 04:04:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Yi Lee X-Patchwork-Id: 10925985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADF03933 for ; Thu, 2 May 2019 04:04:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 999BD28A6F for ; Thu, 2 May 2019 04:04:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88C5628A93; Thu, 2 May 2019 04:04:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1876828A6F for ; Thu, 2 May 2019 04:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725536AbfEBEEw (ORCPT ); Thu, 2 May 2019 00:04:52 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42450 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbfEBEEw (ORCPT ); Thu, 2 May 2019 00:04:52 -0400 Received: by mail-pl1-f193.google.com with SMTP id x15so397958pln.9; Wed, 01 May 2019 21:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rM4F3y1QRq9xFsJANLJ2PQUCgusKq4bJmMsIhz12PE0=; b=Ts+TRyYTEECnYuiapH/JiLE3aOdUcKZNWtildqgDgHamRd1VdgzSGCAWO44xInhGdj +mSemGh+TE4HS0enaJJsBrtkBbEcqWjz1lpnryVQHRWMubhUVwQSTmS9EEIDPhXvjgjU 6g+o0scjwM2Wa4GBwJx9KfNyLLX34ZxZRDRKa2cvK6CWUZXFH0y6AEjV9qy3spZmahNA b+SQITUSMYLUc8ch/bNzxbVNjMDumR6A+WyTsRmnX8GEt5nMTj+WfPGejfq+coffthgc ++DUO+WcK0FirgVSRFVswobYbN0c12GGZ64G5JL7y1dbW1ZfpZpkx9vTuLSTED8o15Aa 1gWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rM4F3y1QRq9xFsJANLJ2PQUCgusKq4bJmMsIhz12PE0=; b=PIQfgCDkuK6JeaM8WapizqgQYIoEHVzR4evwt9U4hEUUPDxqCNDlSguhadEdALMLh1 a2AQEtCa6FgXBLYjkUbo6JtMUoSf+NKSeYyODoeWeZq1F2UL1ChnjgyhTSKrCABE3PiB ahrglisHc/uQp0lJ321PI0qoKfi+ttaSiBSvznCX2PlZJaK3AZrUHbfpRuRpT3my1lg2 IwW1rVUW3gofKfZ9J12BsogSYPK0P6Fk4OioyRRd30B49wpqj4hB+Rhci4mcLqPtangr 6kuXjFbt2wZB0RQYAQ5QASeALElXZpDSBl1wlLR3efH6M5yxoLzjowDufz4iO9QMZjy0 iNzg== X-Gm-Message-State: APjAAAUhdwqVlMuycEHwAssfkVJPYJEbEz22/zHr4S752TayfVZcK/3G QUiBNFaZLmeFJi9PmEhatfc= X-Google-Smtp-Source: APXvYqwIlSDxRSKdkfXgyWtEN1++MlQ6biUp+2bnooCkGaXvtPFj1C9E0K1kp+y/Rsm678WOZw1y7g== X-Received: by 2002:a17:902:b28:: with SMTP id 37mr1260911plq.322.1556769891072; Wed, 01 May 2019 21:04:51 -0700 (PDT) Received: from linux-l9pv.suse ([202.47.205.198]) by smtp.gmail.com with ESMTPSA id k4sm1107687pgh.27.2019.05.01.21.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 May 2019 21:04:50 -0700 (PDT) From: "Lee, Chun-Yi" X-Google-Original-From: "Lee, Chun-Yi" To: Ard Biesheuvel , James Morris , "Serge E . Hallyn" , David Howells , Josh Boyer , Nayna Jain , Mimi Zohar Cc: linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck Subject: [PATCH 1/2 v2] efi: add a function to convert the status value to string Date: Thu, 2 May 2019 12:04:39 +0800 Message-Id: <20190502040441.30372-1-jlee@suse.com> X-Mailer: git-send-email 2.12.3 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This function can be used to convert EFI status value to string for printing out debug message. Using this function can improve the readability of log. v2. - Changed the wording in subject and description. - Moved the marco immediately after the status value definitions. - Turned into a proper function instead of inline. Cc: Ard Biesheuvel Cc: Kees Cook Cc: Anton Vorontsov Cc: Colin Cross Cc: Tony Luck Signed-off-by: "Lee, Chun-Yi" --- include/linux/efi.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 54357a258b35..6f3f89a32eef 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -42,6 +42,34 @@ #define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1))) #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1))) +#define EFI_STATUS_STR(_status) \ +case EFI_##_status: \ + return "EFI_" __stringify(_status); + +static __attribute__((unused)) char * +efi_status_to_str(unsigned long status) +{ + switch (status) { + EFI_STATUS_STR(SUCCESS) + EFI_STATUS_STR(LOAD_ERROR) + EFI_STATUS_STR(INVALID_PARAMETER) + EFI_STATUS_STR(UNSUPPORTED) + EFI_STATUS_STR(BAD_BUFFER_SIZE) + EFI_STATUS_STR(BUFFER_TOO_SMALL) + EFI_STATUS_STR(NOT_READY) + EFI_STATUS_STR(DEVICE_ERROR) + EFI_STATUS_STR(WRITE_PROTECTED) + EFI_STATUS_STR(OUT_OF_RESOURCES) + EFI_STATUS_STR(NOT_FOUND) + EFI_STATUS_STR(ABORTED) + EFI_STATUS_STR(SECURITY_VIOLATION) + default: + pr_warn("Unknown efi status: 0x%lx", status); + } + + return "Unknown efi status"; +} + typedef unsigned long efi_status_t; typedef u8 efi_bool_t; typedef u16 efi_char16_t; /* UNICODE character */