From patchwork Mon Mar 6 21:55:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9607727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F4187602B4 for ; Mon, 6 Mar 2017 22:06:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF0C127BE5 for ; Mon, 6 Mar 2017 22:06:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E389128477; Mon, 6 Mar 2017 22:06:37 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 86BFC27BE5 for ; Mon, 6 Mar 2017 22:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932212AbdCFWGg (ORCPT ); Mon, 6 Mar 2017 17:06:36 -0500 Received: from mail-pg0-f43.google.com ([74.125.83.43]:36470 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932156AbdCFWGd (ORCPT ); Mon, 6 Mar 2017 17:06:33 -0500 Received: by mail-pg0-f43.google.com with SMTP id 187so16943109pgb.3 for ; Mon, 06 Mar 2017 14:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xLWjX2ZS37+GYvs36q9CmIX2VsHt9okNcat1z02BpOI=; b=INohHxOYz6oCcPBICMaoTDFal6WSN+Hfbx354gGCgCiZ+dmIL0n0LP//kLE25HofBE euHng8EJZvAxCA17yzf6jPcIJT1OuM5tCn4wRSaD/wSa0xZi7iT2fYvd6ChTd7bVYOT5 pZLf9PJ4BFCHGqUuLV/N090VjSkX+OYGA5/fg= 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:in-reply-to :references; bh=xLWjX2ZS37+GYvs36q9CmIX2VsHt9okNcat1z02BpOI=; b=tec8iGsrakMUTdw4L1OZROxrBZUk4Z8w+dHPcm3OGWdoxYcKsD7NhJUxrDY5VJbrMS CYVa2yWxculJKTIBss/6P1wjQbp4GKMBjMxRt4X/ii9HjPqvG9PQmbzrvsIrrxuMmhD5 ZGLMULeVlVEb0cpjvJHblVn4NeslUDRLB4VZhfsjaTslApJ83zzK1zTcMR5SnXkVtDmt /EUG2JdYTYLRtfm6UbBlA4Gk27evqNwtItraIDBHJDHZP9fDhF2O2QnAcSJ/YN7s5yvB /HUANlwSVjGv7RqUS6Bamo7XH3+jGqbB/miJHznNUAGddWCJKJwOl9cCcML53TBeeV8P vgJg== X-Gm-Message-State: AMke39modycm1VP+MG27NYDRkRW3IyXWvRXJOQ10cJA1BtdFRJjEL7jwFjryvyOE4I7ZeMjJ X-Received: by 10.84.215.155 with SMTP id l27mr29542567pli.31.1488837339302; Mon, 06 Mar 2017 13:55:39 -0800 (PST) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id e68sm41331092pfa.85.2017.03.06.13.55.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 13:55:38 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Nobuhiro Iwamatsu , Qiuxu Zhuo , Ard Biesheuvel , Anton Vorontsov , Colin Cross , Tony Luck , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Rafael J. Wysocki" , Len Brown , Matt Fleming , Nathan Fontenot , Pan Xinhui , Daniel Axtens , Paul Gortmaker , Geliang Tang , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 07/18] pstore: Move record decompression to function Date: Mon, 6 Mar 2017 13:55:21 -0800 Message-Id: <1488837332-71582-8-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488837332-71582-1-git-send-email-keescook@chromium.org> References: <1488837332-71582-1-git-send-email-keescook@chromium.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This moves the record decompression logic out to a separate function to avoid the deep indentation. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 67 +++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 3fa1575a6e36..0503380704de 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -757,6 +757,37 @@ void pstore_unregister(struct pstore_info *psi) } EXPORT_SYMBOL_GPL(pstore_unregister); +static void decompress_record(struct pstore_record *record) +{ + int unzipped_len; + + /* Only PSTORE_TYPE_DMESG support compression. */ + if (!record->compressed || record->type != PSTORE_TYPE_DMESG) { + pr_warn("ignored compressed record type %d\n", record->type); + return; + } + + /* No compression method has created the common buffer. */ + if (!big_oops_buf) { + pr_warn("no decompression buffer allocated\n"); + return; + } + + unzipped_len = pstore_decompress(record->buf, big_oops_buf, + record->size, big_oops_buf_sz); + if (unzipped_len > 0) { + if (record->ecc_notice_size) + memcpy(big_oops_buf + unzipped_len, + record->buf + record->size, + record->ecc_notice_size); + kfree(record->buf); + record->buf = big_oops_buf; + record->size = unzipped_len; + record->compressed = false; + } else + pr_err("decompression failed: %d\n", unzipped_len); +} + /* * Read all the records from the persistent store. Create * files in our filesystem. Don't warn about -EEXIST errors @@ -768,7 +799,6 @@ void pstore_get_records(int quiet) struct pstore_info *psi = psinfo; struct pstore_record record = { .psi = psi, }; int failed = 0, rc; - int unzipped_len = -1; if (!psi) return; @@ -782,41 +812,18 @@ void pstore_get_records(int quiet) &record.buf, &record.compressed, &record.ecc_notice_size, record.psi)) > 0) { - if (record.compressed && - record.type == PSTORE_TYPE_DMESG) { - if (big_oops_buf) - unzipped_len = pstore_decompress( - record.buf, - big_oops_buf, - record.size, - big_oops_buf_sz); - - if (unzipped_len > 0) { - if (record.ecc_notice_size) - memcpy(big_oops_buf + unzipped_len, - record.buf + recorrecord.size, - record.ecc_notice_size); - kfree(record.buf); - record.buf = big_oops_buf; - record.size = unzipped_len; - record.compressed = false; - } else { - pr_err("decompression failed;returned %d\n", - unzipped_len); - record.compressed = true; - } - } + + decompress_record(&record); rc = pstore_mkfile(record.type, psi->name, record.id, record.count, record.buf, record.compressed, record.size + record.ecc_notice_size, record.time, record.psi); - if (unzipped_len < 0) { - /* Free buffer other than big oops */ + + /* Free buffer other than big oops */ + if (record.buf != big_oops_buf) kfree(record.buf); - record.buf = NULL; - } else - unzipped_len = -1; + if (rc && (rc != -EEXIST || !quiet)) failed++;