From patchwork Tue Apr 4 11:14:32 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: 9661401 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 6EC6A602B9 for ; Tue, 4 Apr 2017 11:16:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 619ED27813 for ; Tue, 4 Apr 2017 11:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56375284DB; Tue, 4 Apr 2017 11:16:47 +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 0908F27813 for ; Tue, 4 Apr 2017 11:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753408AbdDDLQT (ORCPT ); Tue, 4 Apr 2017 07:16:19 -0400 Received: from mout.web.de ([217.72.192.78]:61850 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753827AbdDDLOu (ORCPT ); Tue, 4 Apr 2017 07:14:50 -0400 Received: from [192.168.1.2] ([77.181.94.222]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MX0Q4-1caaRq1D1A-00Vw4y; Tue, 04 Apr 2017 13:14:34 +0200 Subject: [PATCH 2/3] selinux: Return an error code only as a constant in sidtab_insert() From: SF Markus Elfring To: Casey Schaufler , Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts , linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Cc: LKML , kernel-janitors@vger.kernel.org References: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> Message-ID: <61cd20e9-211e-b974-3525-fcb5fdf8fa7e@users.sourceforge.net> Date: Tue, 4 Apr 2017 13:14:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <5704e656-708a-b611-5611-70fc65dc67e8@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:d6hBxYdqGFTxMdt64UPDXQ568x0U+0A8ta3bgVw1Tm+TrGkPhPE MKbJ2WI2aDgUj/Z9Ju2RT5U6BKaIKIZSGWLYPOOB60adsZU12Gva727/MTijshmBemSa+3U LLOadaE/dLNSvN6aw9zOWfuGrZL0Ru2DS5oGEkdv6udzDRZNngF5wmnrRYVaD74WvqENhJN UAYvOlpHOg5WT28UXzIxQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:KoKMeW1pshQ=:4INxQRCrQpomVVBTM4iKcR aKLkceXO453ovjKUTZsURXhm5ugdGzXk8pr3w4cGo4aihYp5Krnvc81lDCPOsllthn8Upbilc kwKVGjYYUwy/kWAVaeIusxQWy+IhWWIcCXfXSIqCXWU8PPk3TDe+NgnnvVH/dZV4VYm1yZAcS qD63HXfdHV+bseLWOdOxJADLNzRU499HCMZMONJj364yQn0JyuldyDA1X48CBTzZ7aDkkxWof kVjKhwUTnxnyV+9k+YujMYMBHY755RNndGo515x4Wwxq5VipyL41leIKGHew0pKrn4Mfh9eZl t/h2e4YIoBSzZ06gFJm9No0gQW35KQfvil4gtgRfMWcHgJiyIyyCYa0Mb34sPHEWbsIRTmc93 lrKe3Ne1MNeiZWVukWZiZJN3jVIb84DYB/pE+QZ1zlQ07cmvcGpI6c1zLRtGJVHljzOhCbFeJ BGWTWWEshpTHfFSRNtXoLXqQ0HfCJFT3UiICQxJlQ2D4fF+ou5tq6hzTve3o5CupvXsUi/uKA VBCTnGi+/rCsmY63tsDAdK+oDbrWamT/L2kGJsYXwu+2tai1cgFbcZ8CH1UR0piTwQWvvU300 l4PpZ2bassq0C7dZ52ZlPFyXty7LKF5b4JGPu2UStxjd2DUYDgopqV25efA15LOQ6LSei5UhK l7w7+FF9KpVc0HLHcfXOUjzMHmrHj2FMWYN8gMUa8qKC3hEKW7Hn3UOwsSFT9iHxCFgBhZBQ/ 0T2A7nglzB81cNJlKhki6zmh6ynhuZGNxcbMCReOFgibTBwrMT21B2F1BY7fDNWrBKTeWTilF 1q5uw8U Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 4 Apr 2017 11:33:53 +0200 * Return an error code without storing it in an intermediate variable. * Delete the local variable "rc" and the jump label "out" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- security/selinux/ss/sidtab.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/security/selinux/ss/sidtab.c b/security/selinux/ss/sidtab.c index f6915f257486..c5f436b15d19 100644 --- a/security/selinux/ss/sidtab.c +++ b/security/selinux/ss/sidtab.c @@ -32,13 +32,11 @@ int sidtab_init(struct sidtab *s) int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) { - int hvalue, rc = 0; + int hvalue; struct sidtab_node *prev, *cur, *newnode; - if (!s) { - rc = -ENOMEM; - goto out; - } + if (!s) + return -ENOMEM; hvalue = SIDTAB_HASH(sid); prev = NULL; @@ -48,21 +46,17 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) cur = cur->next; } - if (cur && sid == cur->sid) { - rc = -EEXIST; - goto out; - } + if (cur && sid == cur->sid) + return -EEXIST; newnode = kmalloc(sizeof(*newnode), GFP_ATOMIC); - if (!newnode) { - rc = -ENOMEM; - goto out; - } + if (!newnode) + return -ENOMEM; + newnode->sid = sid; if (context_cpy(&newnode->context, context)) { kfree(newnode); - rc = -ENOMEM; - goto out; + return -ENOMEM; } if (prev) { @@ -78,8 +72,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) s->nel++; if (sid >= s->next_sid) s->next_sid = sid + 1; -out: - return rc; + return 0; } static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)