linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shivappa Vikas <vikas.shivappa@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Vikas Shivappa <vikas.shivappa@linux.intel.com>,
	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" <ravi.v.shankar@intel.com>,
	tony.luck@intel.com, "Yu, Fenghua" <fenghua.yu@intel.com>
Subject: Re: [PATCH 3/3] x86/intel_rdt: Return error for incorrect resource names in schemata
Date: Thu, 20 Apr 2017 11:57:13 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.10.1704201139240.3411@vshiva-Udesk> (raw)
In-Reply-To: <alpine.DEB.2.20.1704201541230.2059@nanos>



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

  reply	other threads:[~2017-04-20 18:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19 23:50 [PATCH 0/3] x86/intel_rdt: Fixes for schemata parsing issues Vikas Shivappa
2017-04-19 23:50 ` [PATCH 1/3] x86/intel_rdt: Fix padding when resource is enabled via mount Vikas Shivappa
2017-04-20 14:03   ` [tip:x86/cpu] " tip-bot for Vikas Shivappa
2017-04-19 23:50 ` [PATCH 2/3] x86/intel_rdt: Trim whitespace while parsing schemata input Vikas Shivappa
2017-04-20 13:51   ` Thomas Gleixner
2017-04-20 17:51     ` Shivappa Vikas
2017-04-20 17:52       ` Thomas Gleixner
2017-04-20 21:19         ` Shivappa Vikas
2017-04-20 14:04   ` [tip:x86/cpu] " tip-bot for Vikas Shivappa
2017-04-19 23:50 ` [PATCH 3/3] x86/intel_rdt: Return error for incorrect resource names in schemata Vikas Shivappa
2017-04-20 13:44   ` Thomas Gleixner
2017-04-20 18:57     ` Shivappa Vikas [this message]
2017-04-20 14:04   ` [tip:x86/cpu] " tip-bot for Vikas Shivappa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.10.1704201139240.3411@vshiva-Udesk \
    --to=vikas.shivappa@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vikas.shivappa@linux.intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).