From patchwork Sun Jan 15 15:45:05 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: 9517609 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 0DE05601B7 for ; Sun, 15 Jan 2017 15:52:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 826942849F for ; Sun, 15 Jan 2017 15:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7690C284A2; Sun, 15 Jan 2017 15:45:42 +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 2851D2849F for ; Sun, 15 Jan 2017 15:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751322AbdAOPpX (ORCPT ); Sun, 15 Jan 2017 10:45:23 -0500 Received: from mout.web.de ([212.227.15.14]:57341 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdAOPpW (ORCPT ); Sun, 15 Jan 2017 10:45:22 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MC6ZE-1cK1Z506XA-008qqS; Sun, 15 Jan 2017 16:45:07 +0100 Subject: [PATCH 45/46] selinux: Use common error handling code in sidtab_insert() 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: <36f95c73-4ae1-efbf-393c-6f4239a91478@users.sourceforge.net> Date: Sun, 15 Jan 2017 16:45:05 +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:uI16RxgtW15BGmH61B3IyLWKsdjYxaOdmT1wGiYQEMcjsjfZCeR vGENHbFRZGBvebz+5cVgESkwuvl0Wz1vefCuxNlXh6PN8SxcsZvhJ/BTsV3B0WvYMebNPhD T3U/ljCv3AaE7GD9mG7Fick9A0CdReMrdf7EAFLEwSFrGWi0Iqr/uBRNuA7o0wScQPxZTzZ EYKpA9OeeNc/NHZ0NsJkg== X-UI-Out-Filterresults: notjunk:1; V01:K0:5BTjB/CVaw8=:SqRBP3YUaTHM3bZCHsYhAe 0oN+9zqLs5ys8QX/RM7P5p3tqTWWpjqnxGpacrRsg9JIeBgvNyhsx0T01UWON3HPS+HOCBvUL lVuBedy7Gl0SiPOf9EQnUI8DM3JMlT37SN/bpsluvVPtTSTX84W6tdNE/JwgGB7CPM0TPVRjs 9bYmw1AtULmdlW9zmZ5vkBdSM5i8JRiFwfynWcAT7wOWlurua6CdNOiUZwGTdOkOIdLS+oPrh D4A0FMiiJWr9b05t6/nvuU8URbC3USK5h/AzkQvWMm/kNZorYVRM8d/mLayU+XMBOBNjzqjqP rAxZz6GD9ZQqsQx/pKqjnVzj3JrQXmpA/bYuJ5dJWYHzYZzF3yXFUvt7LweewwJq4SefLSC/x miNwU0qwB5u2nWVPDnBdf9O6cH1JBNdFu0J4uvQTB8uiVbb1EAmCU6D1K/vK8973fx6WnnuYV mnQL3R9XRzQk/qqmSQivee0J2aVyi+ofs+h08SQgZz+etusyi8UDowWcBhyoxEhAfyBU2Odb4 /8H3evprKSTcbUgqa3crcNbK3iSUC1+hybx0wXDsSyp+NWcODrCRXmL2HZSkdUSk1n0C/rKzc FlJ0zpHYRFQzgFXsxwgxYkhed977NSJhnUyjtIJDxaKugdkIadfTDV04ieswQWBxW15F3Cqdo KV7IRKC0EMtIHI5GpCNZg+q/j3kYNNwaI1Q9q2ExwiKdCyafojJRZnGmSDIZ13FsLykbJtaxz iR8gIxKUqeIJD55iFXaxzwOzH/tduEHJCvlNVzdGXprEN3mHsfTVShqJQYDTHu4w3WMajExtm mOvawAG 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 13:45:45 +0100 Add a jump target so that a bit of exception handling can be better reused at the end of this function. Signed-off-by: Markus Elfring --- security/selinux/ss/sidtab.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/security/selinux/ss/sidtab.c b/security/selinux/ss/sidtab.c index f6915f257486..4130f882808c 100644 --- a/security/selinux/ss/sidtab.c +++ b/security/selinux/ss/sidtab.c @@ -35,10 +35,8 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) int hvalue, rc = 0; struct sidtab_node *prev, *cur, *newnode; - if (!s) { - rc = -ENOMEM; - goto out; - } + if (!s) + goto failure_indication; hvalue = SIDTAB_HASH(sid); prev = NULL; @@ -54,15 +52,12 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) } newnode = kmalloc(sizeof(*newnode), GFP_ATOMIC); - if (!newnode) { - rc = -ENOMEM; - goto out; - } + if (!newnode) + goto failure_indication; newnode->sid = sid; if (context_cpy(&newnode->context, context)) { kfree(newnode); - rc = -ENOMEM; - goto out; + goto failure_indication; } if (prev) { @@ -80,6 +75,9 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) s->next_sid = sid + 1; out: return rc; +failure_indication: + rc = -ENOMEM; + goto out; } static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)