From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751095AbdAQSCo (ORCPT ); Tue, 17 Jan 2017 13:02:44 -0500 Received: from nm6.bullet.mail.ne1.yahoo.com ([98.138.90.69]:40442 "EHLO nm6.bullet.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750849AbdAQSCn (ORCPT ); Tue, 17 Jan 2017 13:02:43 -0500 X-Yahoo-Newman-Id: 830355.30691.bm@smtp209.mail.ne1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: UMyzjsMVM1mNPQllBkvDpZ4gQNBU4JyHF6dEO.rGBLTHXEb PBQA6AtUAYdq4zKZg9iZHBSTrpyDpPgYUQ97Z52FlaoIx8deRuSxkqI5hC3F VXYeQ7kEjm_ohU57dq4r3DV.L6XVZT5gkpk9OceLB.AmjcIx4NFmRkveRea2 5M_zvUI450t4PF5Z5Qr6P9ZrlR6HY.4ismZmF2OHUlre6oTjfDUJjEEeOdrA _B8J0IpayOez4w4nWSCauYERz5C7SgtzmnQHj8xUw_RmJe82KbeHTfAlj96Y BbXeBr0NAosPxUSXYpAwuWJN1fLC1YsnRo.Wz59wWgCGdYlIZQdgLm9SsMnr 6wZZf7ZwVtJj04EdKfSxXu3wlTNB1KW0bgvix.tHXVYjMCh3YQ5F4m9J0dfo ZOhAbAqWQI.wzcyqnSVWbRcKO4rpmDIhXOnJ7mz1NIU1yfncVUpRQhzFLxm5 n8fk80FBordD5w8zmK7CrfaVshlYfcN6l2AD_Tr48LEl33IHqxQzyrPLrnPe fwOytcL3vGmqH0YBhLRSEyZXm85sjzY0Gi2pWraKAW.jrjOxBFlnd.KY- X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- Subject: Re: [PATCH 45/46] selinux: Use common error handling code in sidtab_insert() To: SF Markus Elfring , linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts References: <36f95c73-4ae1-efbf-393c-6f4239a91478@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: Casey Schaufler Message-ID: <923ce5f2-48ce-9d90-db19-7c94b7c43794@schaufler-ca.com> Date: Tue, 17 Jan 2017 10:02:40 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <36f95c73-4ae1-efbf-393c-6f4239a91478@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/15/2017 7:45 AM, SF Markus Elfring wrote: > 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; Why not "return -ENOMEM;" ? > - } > + if (!newnode) > + goto failure_indication; > newnode->sid = sid; > if (context_cpy(&newnode->context, context)) { > kfree(newnode); > - rc = -ENOMEM; > - goto out; > + goto failure_indication; Again, "return -ENOMEM:" > } > > 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; Backward gotos are horrible. Don't do this. > } > > static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force) From mboxrd@z Thu Jan 1 00:00:00 1970 From: Casey Schaufler Date: Tue, 17 Jan 2017 18:02:40 +0000 Subject: Re: [PATCH 45/46] selinux: Use common error handling code in sidtab_insert() Message-Id: <923ce5f2-48ce-9d90-db19-7c94b7c43794@schaufler-ca.com> List-Id: References: <36f95c73-4ae1-efbf-393c-6f4239a91478@users.sourceforge.net> In-Reply-To: <36f95c73-4ae1-efbf-393c-6f4239a91478@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: SF Markus Elfring , linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts Cc: LKML , kernel-janitors@vger.kernel.org On 1/15/2017 7:45 AM, SF Markus Elfring wrote: > 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; Why not "return -ENOMEM;" ? > - } > + if (!newnode) > + goto failure_indication; > newnode->sid = sid; > if (context_cpy(&newnode->context, context)) { > kfree(newnode); > - rc = -ENOMEM; > - goto out; > + goto failure_indication; Again, "return -ENOMEM:" > } > > 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; Backward gotos are horrible. Don't do this. > } > > static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)