From patchwork Sun Jan 15 15:42:13 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: 9517597 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 BDC6462B6B for ; Sun, 15 Jan 2017 15:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD2F528387 for ; Sun, 15 Jan 2017 15:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F597283AC; Sun, 15 Jan 2017 15:42:29 +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 560A628387 for ; Sun, 15 Jan 2017 15:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbdAOPm2 (ORCPT ); Sun, 15 Jan 2017 10:42:28 -0500 Received: from mout.web.de ([212.227.15.4]:58675 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdAOPm1 (ORCPT ); Sun, 15 Jan 2017 10:42:27 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LpOKb-1cyGLC2kSb-00f6t8; Sun, 15 Jan 2017 16:42:16 +0100 Subject: [PATCH 42/46] selinux: One function call less in roles_init() after error detection 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: Date: Sun, 15 Jan 2017 16:42:13 +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:bCWmQKO9E+URE7U4zqrC/hDS26B26sIyPf9s3ZTC9ZxBknRbZFJ dg6mCp5Fr+iZTIOrt3/S4FHT2G3LrODpIas6HDSVzFKyUckmcfCE5zNQJq/qHuO8QUOruMz cIN1Kowx6ni4qh7hR99N4U5OQs0X4cxm04lVLPzmaGx3Y/D87RPkMaGazcfTG1W2NiH0nqg SclWz6KQhuGBqlePDpoVg== X-UI-Out-Filterresults: notjunk:1; V01:K0:rpmgTvyPJQw=:W4wK3QE6n2C8PVkXyiHNy8 Rg3AtXUGZKLyTJRe5y7T1+hfoDwOv0pJdexxFhBlJlSiQVzvayY8ugOWBOgVe43VLYq4g9UGn fjv2hP+FhwiiIw99iC9kyE6OiV+9F3sQCK7MAZCaa782E9XSWlLNzYCkLXJs3iDtU4urNFhoL EC0oPQegSq7jAlklBu2eHFQ/TnzI6k7g7PlmPMJhmeZmvanySePhO0RshFlbcAaZDLnhLQpMq D6cVE8ldKsE9T4N/j143RqDdkB69lhMbkZsX7znNuHs7+2Ma5pRHlO5F0WWuk97rt0fb7M1F/ 3f7804sKlP5hWb9a9dCiXY+5WN155YJLsVielhv0Bnt+ZohYASTdCnklj/3KnJAqCVkEvJitG RB8H9nzd8COLBBXiJk1FOf2OsmheA7dWAEa7OdG95kYnbhA7U2K/Ki2z1VbvB5Rnoxus5aOve dgAcMUGAo0Cfw61YojeawvbJ2X4Xeo2qGT8rkTEvmTmp2auAGKSe5V5PfxMsMV4/q6qIqE6fE aIslxBRmEl3hqV/WOoF4/jZzm2xHIbXgSXJ2I6fkHxyhi1obOrntJyo5rBZ7CJcOQUq6Pl9bh 0+aHHtd7sYXVx8AmhDY3WE3X1A9wKzsjIRXrO96LBf4jE75/BAMRV8wkmkJByTxWIlPdlYntd nUqSGZJwM3y1kfx5Rw3jaNSBGRBVj8i4vVldt9s04Kkcpafj7iyt3WKKlYsKU0pKgVbFeSH6x urKokEZKuv2ddWewC8d5mHiGDMOEzTx5SOXU+CEYYY3iKqlp4va97YGHa/6sJu/Ztxy8kxBwM hw7sWnF Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 15 Jan 2017 12:56:54 +0100 The kfree() function was called in up to two cases by the roles_init() function during error handling even if the passed variable contained a null pointer. * Adjust a jump target according to the Linux coding style convention. * Delete an initialisation for the variable "key" at the beginning which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index be445abf047b..7dd5c6f7786f 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -174,7 +174,7 @@ static struct policydb_compat_info *policydb_lookup_compat(int version) */ static int roles_init(struct policydb *p) { - char *key = NULL; + char *key; int rc; struct role_datum *role; @@ -185,13 +185,13 @@ static int roles_init(struct policydb *p) role->value = ++p->p_roles.nprim; if (role->value != OBJECT_R_VAL) { rc = -EINVAL; - goto out; + goto free_role; } key = kstrdup(OBJECT_R, GFP_KERNEL); if (!key) { rc = -ENOMEM; - goto out; + goto free_role; } rc = hashtab_insert(p->p_roles.table, key, role); @@ -201,6 +201,7 @@ static int roles_init(struct policydb *p) return 0; out: kfree(key); +free_role: kfree(role); return rc; }