From patchwork Wed Dec 23 18:12:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 7913501 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D81939F318 for ; Wed, 23 Dec 2015 18:12:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1F0F2039E for ; Wed, 23 Dec 2015 18:12:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1356020397 for ; Wed, 23 Dec 2015 18:12:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933517AbbLWSM1 (ORCPT ); Wed, 23 Dec 2015 13:12:27 -0500 Received: from mout.web.de ([212.227.17.12]:55241 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932750AbbLWSM0 (ORCPT ); Wed, 23 Dec 2015 13:12:26 -0500 Received: from [192.168.1.3] ([78.49.98.159]) by smtp.web.de (mrweb101) with ESMTPSA (Nemesis) id 0MPpQU-1a6sDc440Y-004z7M; Wed, 23 Dec 2015 19:12:23 +0100 Subject: [PATCH 4/5] block-LDM: Less function calls in ldm_validate_privheads() after error detection To: linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, Jens Axboe , Richard Russon References: <566ABCD9.1060404@users.sourceforge.net> <567A6CDB.4030703@users.sourceforge.net> <567AE1C6.9020108@users.sourceforge.net> Cc: Julia Lawall , LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <567AE405.9030308@users.sourceforge.net> Date: Wed, 23 Dec 2015 19:12:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <567AE1C6.9020108@users.sourceforge.net> X-Provags-ID: V03:K0:NlUrKEEg3r+5Qtt5crbLfcFbG4pbElTh+nyr+l7FDfvsGFqtro0 h9COmfgAh4ZdMIkdk8311/cO3gf4kK0XyKgCL9t1/yQH+ocNpeZ0LTv1nGCcvKWCT5GY0dH 8mC7Ms4nCZ4O6xldTgi9jLKUAEp5ZhPAIwTVlY0tkEFFInFN+7bahAyxOKABTjG+GxWa1eC J/VHQGyfL0TyIq3NGkdZA== X-UI-Out-Filterresults: notjunk:1; V01:K0:B7XlMc1qfyc=:7E07bFMniTfyw7SsaLbKm1 lKE6x3MfgwiMil91nAu61otSRTvgbOQj8wGnUrZvdMVaolsXT3zKKcwqmdk+9k1pDiDfZTxGC zGmLpXZJiJRTFBbyV40uYtjY0tKjH63CVyXU2zfI1Ev6BuunfjKLEmJUUi0y1XQ75KuXZ60Lw AUMd+79w54EoRh/3zDG1ytig7uAKn/TEQaNjaznFFl15JtVkXNVyFdAi4//wf4q4k/9lxOYu/ KZzaNmS1x5NPAOZCYqNEkb8IzKGVLJpbedgeU+yw0KEgixrVrEDlIyWBhq5n2/rMhIZgO5oGM vTPWON1DdMEAH0om33QgRcvUt6EbHi62pug1uW4YegFs66U6KWSpUlZdUz9YzaPnVoNrxTp9p T7HxllPF9RMXMmfbrJvDnFRx15BSqUuUGZlx7hlE+wTD4k7yMPFx66oZaCWuk9kINYcN/jStY jSefbPflhG1JSP3RR5d3AJ482tkZUlDQ9SJvFtyTvy4SQ6UpG0m0Esl5eim2rb9HtNnoKITyQ VeZqvWGX5Z9hL9C/p78j94JszNhw66o0KCGo9PF7nXKtdqXiMscnCfY7C5vFi0j0FVn2Sog0S dtynoKVxECGsgowIti37SK26YcgcUqa5bmHecztMaCRsOL1060cYIDREo1K1hhrT1A0z/26aG 58S4klX0kNUF1VtfN5yuIQU/gLyz8eiwPTJ69GQ3Sgq53ApDetjZdl4YZqLRUIzj2swj6VcYK /LokRaj9NJFmF2oT80gvVx9b8cm5DRSbEKMNJR9DOgj5/Bi+2/ne6ap2QX9aMNfv5y+GKrqZ0 pKWTsA6 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Wed, 23 Dec 2015 14:31:01 +0100 The kfree() function was called by the ldm_validate_privheads() function during error handling even if the passed variable "ph" contained a null pointer. * Corresponding implementation details could be improved by adjustments for jump targets according to the Linux coding style convention. * The variable "result" will eventually be set to an appropriate value. Thus let us omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring --- block/partitions/ldm.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c index 3118d24..6fc9150 100644 --- a/block/partitions/ldm.c +++ b/block/partitions/ldm.c @@ -335,16 +335,20 @@ static bool ldm_validate_privheads(struct parsed_partitions *state, struct privhead *ph[3] = { ph1 }; Sector sect; u8 *data; - bool result = false; + bool result; long num_sects; int i; BUG_ON (!state || !ph1); ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL); + if (!ph[1]) + return false; ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL); - if (!ph[1] || !ph[2]) - goto out; + if (!ph[2]) { + result = false; + goto free_a_head; + } /* off[1 & 2] are relative to ph[0]->config_start */ ph[0]->config_start = 0; @@ -355,14 +359,15 @@ static bool ldm_validate_privheads(struct parsed_partitions *state, §); if (!data) { ldm_crit ("Disk read failed."); - goto out; + result = false; + goto free_another_head; } result = ldm_parse_privhead (data, ph[i]); put_dev_sector (sect); if (!result) { ldm_error ("Cannot find PRIVHEAD %d.", i+1); /* Log again */ if (i < 2) - goto out; /* Already logged */ + goto free_another_head; /* Already logged */ else break; /* FIXME ignore for now, 3rd PH can fail on odd-sized disks */ } @@ -373,30 +378,31 @@ static bool ldm_validate_privheads(struct parsed_partitions *state, if ((ph[0]->config_start > num_sects) || ((ph[0]->config_start + ph[0]->config_size) > num_sects)) { ldm_crit ("Database extends beyond the end of the disk."); - goto out; + goto free_another_head; } if ((ph[0]->logical_disk_start > ph[0]->config_start) || ((ph[0]->logical_disk_start + ph[0]->logical_disk_size) > ph[0]->config_start)) { ldm_crit ("Disk and database overlap."); - goto out; + goto free_another_head; } if (!ldm_compare_privheads (ph[0], ph[1])) { ldm_crit ("Primary and backup PRIVHEADs don't match."); - goto out; + goto free_another_head; } /* FIXME ignore this for now if (!ldm_compare_privheads (ph[0], ph[2])) { ldm_crit ("Primary and backup PRIVHEADs don't match."); - goto out; + goto free_another_head; }*/ ldm_debug ("Validated PRIVHEADs successfully."); result = true; -out: - kfree (ph[1]); - kfree (ph[2]); +free_another_head: + kfree(ph[2]); +free_a_head: + kfree(ph[1]); return result; }