From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965319AbdCWVUT (ORCPT ); Thu, 23 Mar 2017 17:20:19 -0400 Received: from mail-vk0-f67.google.com ([209.85.213.67]:35054 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753656AbdCWVUQ (ORCPT ); Thu, 23 Mar 2017 17:20:16 -0400 MIME-Version: 1.0 X-Originating-IP: [108.49.102.27] In-Reply-To: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> References: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> From: Paul Moore Date: Thu, 23 Mar 2017 17:20:14 -0400 Message-ID: Subject: Re: [PATCH 07/46] selinux: Delete unnecessary variable assignments in policydb_index() To: SF Markus Elfring Cc: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , "Serge E. Hallyn" , Stephen Smalley , William Roberts , LKML , kernel-janitors@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 15, 2017 at 10:04 AM, SF Markus Elfring wrote: > 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(-) Like you, I generally despise the notion of unconditionally setting return codes to an error value *before* the faulting call; see Eric's response on patch 0/46, my preferred style is different from Eric. However, I agree with Casey that this patch is mostly just code churn so I'm going to drop this from your series. > 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; > } > > /* > -- > 2.11.0 > -- paul moore www.paul-moore.com From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Moore Date: Thu, 23 Mar 2017 21:20:14 +0000 Subject: Re: [PATCH 07/46] selinux: Delete unnecessary variable assignments in policydb_index() Message-Id: List-Id: References: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> In-Reply-To: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-security-module@vger.kernel.org On Sun, Jan 15, 2017 at 10:04 AM, SF Markus Elfring wrote: > 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(-) Like you, I generally despise the notion of unconditionally setting return codes to an error value *before* the faulting call; see Eric's response on patch 0/46, my preferred style is different from Eric. However, I agree with Casey that this patch is mostly just code churn so I'm going to drop this from your series. > 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; > } > > /* > -- > 2.11.0 > -- paul moore www.paul-moore.com From mboxrd@z Thu Jan 1 00:00:00 1970 From: paul@paul-moore.com (Paul Moore) Date: Thu, 23 Mar 2017 17:20:14 -0400 Subject: [PATCH 07/46] selinux: Delete unnecessary variable assignments in policydb_index() In-Reply-To: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> References: <247c0e27-c442-3408-4f92-492629d61fbf@users.sourceforge.net> Message-ID: To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org On Sun, Jan 15, 2017 at 10:04 AM, SF Markus Elfring wrote: > 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(-) Like you, I generally despise the notion of unconditionally setting return codes to an error value *before* the faulting call; see Eric's response on patch 0/46, my preferred style is different from Eric. However, I agree with Casey that this patch is mostly just code churn so I'm going to drop this from your series. > 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; > } > > /* > -- > 2.11.0 > -- paul moore www.paul-moore.com -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html