Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031689AbdDTS4f (ORCPT ); Thu, 20 Apr 2017 14:56:35 -0400 Received: from mga06.intel.com ([134.134.136.31]:29391 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965125AbdDTS4e (ORCPT ); Thu, 20 Apr 2017 14:56:34 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,225,1488873600"; d="scan'208";a="79289681" Date: Thu, 20 Apr 2017 11:57:13 -0700 (PDT) From: Shivappa Vikas X-X-Sender: vikas@vshiva-Udesk To: Thomas Gleixner cc: Vikas Shivappa , vikas.shivappa@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, sai.praneeth.prakhya@intel.com, hpa@zytor.com, mingo@kernel.org, "Shankar, Ravi V" , tony.luck@intel.com, "Yu, Fenghua" Subject: Re: [PATCH 3/3] x86/intel_rdt: Return error for incorrect resource names in schemata In-Reply-To: Message-ID: References: <1492645804-17465-1-git-send-email-vikas.shivappa@linux.intel.com> <1492645804-17465-4-git-send-email-vikas.shivappa@linux.intel.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1830 Lines: 75 On Thu, 20 Apr 2017, Thomas Gleixner wrote: > On Wed, 19 Apr 2017, Vikas Shivappa wrote: > >> } > > The resulting loop is just horrible to read. We can do better than > that. Patch below. > > Thanks, > > tglx > 8<------------- > > --- a/arch/x86/kernel/cpu/intel_rdt_schemata.c > +++ b/arch/x86/kernel/cpu/intel_rdt_schemata.c > @@ -187,6 +187,17 @@ static int update_domains(struct rdt_res > return 0; > } > > +static int rdtgroup_parse_resource(char *resname, char *tok, int closid) > +{ > + struct rdt_resource *r; > + > + for_each_enabled_rdt_resource(r) { > + if (!strcmp(resname, r->name) && closid < r->num_closid) > + return parse_line(tok, r); > + } > + return -EINVAL; > +} > + > ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, > char *buf, size_t nbytes, loff_t off) > { > @@ -209,9 +220,10 @@ ssize_t rdtgroup_schemata_write(struct k > > closid = rdtgrp->closid; > > - for_each_enabled_rdt_resource(r) > + for_each_enabled_rdt_resource(r) { > list_for_each_entry(dom, &r->domains, list) > dom->have_new_ctrl = false; > + } > > while ((tok = strsep(&buf, "\n")) != NULL) { > resname = strsep(&tok, ":"); > @@ -219,19 +231,9 @@ ssize_t rdtgroup_schemata_write(struct k > ret = -EINVAL; > goto out; > } > - for_each_enabled_rdt_resource(r) { > - if (!strcmp(strim(resname), r->name) && > - closid < r->num_closid) { > - ret = parse_line(tok, r); > - if (ret) > - goto out; > - break; > - } > - } > - if (!r->name) { > - ret = -EINVAL; > + ret = rdtgroup_parse_resource(strim(resname), tok, closid); > + if (ret) > goto out; > - } > } Ok agree its better way. I was trying to add a NULL which Tony already said was Nacked, did not really want to use a pointer which may be out of bounds although we dont check the contents. Thanks, Vikas