From patchwork Sun Jan 15 15:04:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9517457 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 B5FB660571 for ; Sun, 15 Jan 2017 15:05:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A814D28420 for ; Sun, 15 Jan 2017 15:05:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 996712842D; Sun, 15 Jan 2017 15:05:05 +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.9 required=2.0 tests=BAYES_00,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 38A1128420 for ; Sun, 15 Jan 2017 15:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750956AbdAOPFD (ORCPT ); Sun, 15 Jan 2017 10:05:03 -0500 Received: from mout.web.de ([212.227.15.14]:49345 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750831AbdAOPFC (ORCPT ); Sun, 15 Jan 2017 10:05:02 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M3BeZ-1ckZnR3jLL-00swaL; Sun, 15 Jan 2017 16:04:51 +0100 Subject: [PATCH 07/46] selinux: Delete unnecessary variable assignments in policydb_index() To: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts References: Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> Date: Sun, 15 Jan 2017 16:04:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:wjP36bF6Q1DpwZqBZmJDUEFPTklhWtZZMeaSr+FL5adyfAcRBy0 EvfGE6a/9XO1fZ4LWPw8I+5+Cenu9WDrHneXYwFQWUgbipoMn2tbKkKGd1fAvJMRuSjJezw mhYX/rJJoO0kQhiH/ZPb/4cpvpB+eolOEstwO0AtQjQHVH5/W4b2JA06r67EORiCGhfOr3r WgFGCcU/wL6CcQ6i85G9w== X-UI-Out-Filterresults: notjunk:1; V01:K0:Z8x/1lRzXnc=:UIXe3DMSy9WNFf548RgUhe S8dLZGAs6O2ZAM6lsyu3nBSlvi1CsZf7x94o9rfXdXEkcSt6VK3UINBPsxBabXfvuyBjwLps5 JzIzlBq6dFXzVgFqPmS68zg30QbNSSPy7JXXwoQP3GqCe1KwNgwYT0c647+Q3yLP/FZeRDz1x bN69mXayvti9r+/co4jq9cqKGV4pNqGYILoZbHTNFjitT0tCq/5GqxRFDNY3puC0upis49w/4 JkfiKJptiLu8X2UzbA18rkfkMwvSPVDkSCCjlmNv2PSrpnLotyxqBjOGqiMy00CiH+YBpnQRY qlO2ssNNjg9CUl+/b64gZ9c7kmMTEt0w97hdP2TidIzc7xY+92fKGVfYoEyMZeGxFRrOZS0KN QZKj3hw21eTPU30AXEWQZlryjUW+evk43B5GWYu9Jl5xAxxQQxyQpIlI4fGero3zxfwv7XFVu 1VGhJnSz+hUXIcUhaQzbXD/rFegMC6ciTwTZOHmJRguyOSd1j1IbSGoK6cODAvk4fZLz+ElMW 807egjmfAQ9wAVnY/Fe9IXmDv+i1tZttX1XSw+CQyR3gg818jGKjfcuipo7mBWYqiIhmt1Jhs JE3EXNT5zRb1oDCjXy3Hjo0aryrEOCp/ArUDlRaDtH35xGPTf5AoiLyC2AozgTLWbvjffwSyR 9rLVWLUaaJdsyGz8/AgPIP0VCdSVqpksfXRpXqBhLbT3eR/nSG8hFPyqHd1Q1IqChQ5jRy5RL 60uooOoo70p//2I229wDH7AJ4gMAUg2+TWRZz+AqG/DLVuIe2TvjH8j0nqVX9CUL6D6y+i0su P4XaGd0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 14 Jan 2017 13:40:25 +0100 The local variable "rc" was reset with an error code up to five times before a memory allocation failure was detected. Add a jump target so that this assignment will only be performed after a concrete software failure. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 21869b622c0c..4d4ba1ad910d 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -539,34 +539,30 @@ static int policydb_index(struct policydb *p) symtab_hash_eval(p->symtab); #endif - rc = -ENOMEM; p->class_val_to_struct = kcalloc(p->p_classes.nprim, sizeof(*p->class_val_to_struct), GFP_KERNEL); if (!p->class_val_to_struct) - goto out; + goto failure_indication; - rc = -ENOMEM; p->role_val_to_struct = kcalloc(p->p_roles.nprim, sizeof(*p->role_val_to_struct), GFP_KERNEL); if (!p->role_val_to_struct) - goto out; + goto failure_indication; - rc = -ENOMEM; p->user_val_to_struct = kcalloc(p->p_users.nprim, sizeof(*p->user_val_to_struct), GFP_KERNEL); if (!p->user_val_to_struct) - goto out; + goto failure_indication; /* Yes, I want the sizeof the pointer, not the structure */ - rc = -ENOMEM; p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); if (!p->type_val_to_struct_array) - goto out; + goto failure_indication; rc = flex_array_prealloc(p->type_val_to_struct_array, 0, p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); @@ -578,12 +574,11 @@ static int policydb_index(struct policydb *p) goto out; for (i = 0; i < SYM_NUM; i++) { - rc = -ENOMEM; p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), p->symtab[i].nprim, GFP_KERNEL | __GFP_ZERO); if (!p->sym_val_to_name[i]) - goto out; + goto failure_indication; rc = flex_array_prealloc(p->sym_val_to_name[i], 0, p->symtab[i].nprim, @@ -598,6 +593,9 @@ static int policydb_index(struct policydb *p) rc = 0; out: return rc; +failure_indication: + rc = -ENOMEM; + goto out; } /*