LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Moger, Babu" <Babu.Moger@amd.com>
To: Fenghua Yu <fenghua.yu@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, H Peter Anvin <hpa@zytor.com>,
	Tony Luck <tony.luck@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Reinette Chatre <reinette.chatre@intel.com>,
	James Morse <james.morse@arm.com>,
	Ravi V Shankar <ravi.v.shankar@intel.com>,
	Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
	Arshiya Hayatkhan Pathan <arshiya.hayatkhan.pathan@intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: RE: Fwd: [PATCH v2 2/8] selftests/resctrl: Add basic resctrl file system operations and data
Date: Tue, 30 Oct 2018 22:26:22 +0000	[thread overview]
Message-ID: <DM5PR12MB24718634BDBD91020E52218895CC0@DM5PR12MB2471.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20181030183544.GA173608@romley-ivt3.sc.intel.com>

Fenghua,

> -----Original Message-----
> From: Fenghua Yu <fenghua.yu@intel.com>
> Sent: Tuesday, October 30, 2018 1:36 PM
> To: Moger, Babu <Babu.Moger@amd.com>; Fenghua Yu
> <fenghua.yu@intel.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>; Ingo Molnar
> <mingo@redhat.com>; H Peter Anvin <hpa@zytor.com>; Tony Luck
> <tony.luck@intel.com>; Peter Zijlstra <peterz@infradead.org>; Reinette
> Chatre <reinette.chatre@intel.com>; James Morse
> <james.morse@arm.com>; Ravi V Shankar <ravi.v.shankar@intel.com>; Sai
> Praneeth Prakhya <sai.praneeth.prakhya@intel.com>; Arshiya Hayatkhan
> Pathan <arshiya.hayatkhan.pathan@intel.com>; linux-kernel <linux-
> kernel@vger.kernel.org>
> Subject: Re: Fwd: [PATCH v2 2/8] selftests/resctrl: Add basic resctrl file
> system operations and data
> 
> > From: Moger, Babu <Babu.Moger@amd.com>
> > > From: Fenghua Yu <fenghua.yu@intel.com>
> > > From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
> > >
> > > The basic resctrl file system operations and data are added for future
> > > usage by resctrl selftest tool.
> > >
> > > +     return 0;
> > > +}
> > > +
> > > +char get_sock_num(int cpu_no)
> > > +{
> > > +     char sock_num, phys_pkg_path[1024];
> > > +     FILE *fp;
> > > +
> > > +     sprintf(phys_pkg_path, "%s%d/topology/physical_package_id",
> > > +             PHYS_ID_PATH, cpu_no);
> > > +     fp = fopen(phys_pkg_path, "r");
> >
> > There should corresponding fclose for this. In general, I would check all the
> > fopens in this series. I found few of the files not closed while returning.
> > More comments below.
> >
> > > +     if (!fp || fscanf(fp, "%c", &sock_num) <= 0 || fclose(fp) == EOF) {
> 
> fclose is here.

Yes. It is there. Let's take a case(hypothetical) where fp is valid and fscanf returns -1.

             If( false || true || fclose(fp))

Will this execute fclose?  Or am I missing something here?


> 
> > > +             perror("Could not get socket number");
> > > +
> > > +             return -1;
> > > +     }
> > > +
> > > +      */
> > > +     if (!freopen("/dev/null", "w", stdout))
> > > +             PARENT_EXIT("Unable to direct BM op to /dev/null");
> >
> > Do you need fclose for this before returning from this function?
> 
> This fclose is missing. I will add it.
> 
> > > +     /* Write child pid to con_mon grp */
> > > +     fp = fopen(controlgroup, "w");
> >
> > I don't see corresponding fclose.
> >
> > > +     if (!fp || fprintf(fp, "%d\n", bm_pid) <= 0 || fclose(fp) == EOF) {
> 
> fclose is here:)
> 
> > > +             perror("Failed to write child to con_mon grp");
> > > +
> > > +             return errno;
> > > +     }
> > > +
> > > +     /* Write child pid to mon grp, only for "mbm" */
> > > +     if ((strcmp(resctrl_val, "mbm") == 0)) {
> > > +             if (mongrp) {
> > > +                     fp = fopen(monitorgroup, "w");
> > > +                     if (!fp || fprintf(fp, "%d\n", bm_pid) <= 0 ||
> > > +                         fclose(fp) == EOF) {
> >
> >
> > I feel too many checks at one place.  If fprintf fails,  will it fclose the
> > file? I suggest to separate these checks.
> 
> You are right. I will separate the checks in multiple lines.
> 
> >
> > > +
> > > +             fp = fopen(controlgroup, "w");
> > > +             if (!fp || fprintf(fp, "%s\n", schema) <= 0 ||
> > > +                 fclose(fp) == EOF) {
> >
> > Same comment as above.. If fprintf fails,  will it fclose the file? I suggest
> > to separate these checks.
> 
> Sure.
> 
> I will change code based on your comments.
> 
> Thanks.
> 
> -Fenghua

  reply	other threads:[~2018-10-30 22:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-25 23:06 [PATCH v2 0/8] selftests/resctrl: Add resctrl selftest Fenghua Yu
2018-10-25 23:06 ` [PATCH v2 1/8] selftests/resctrl: Add README for resctrl tests Fenghua Yu
2018-10-25 23:07 ` [PATCH v2 2/8] selftests/resctrl: Add basic resctrl file system operations and data Fenghua Yu
2018-10-29 21:51   ` Moger, Babu
     [not found]     ` <CALBSrqDRKbth2NAUFM+emBHVv7eZPX=O9Ki-=vUxi-QQc1wVnQ@mail.gmail.com>
2018-10-30 18:35       ` Fwd: " Fenghua Yu
2018-10-30 22:26         ` Moger, Babu [this message]
2018-10-25 23:07 ` [PATCH v2 3/8] selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system Fenghua Yu
2018-10-29 22:00   ` Moger, Babu
2018-10-29 22:14   ` Moger, Babu
2018-10-25 23:07 ` [PATCH v2 4/8] selftests/resctrl: Add callback to start a benchmark Fenghua Yu
2018-10-29 22:03   ` Moger, Babu
2018-10-25 23:07 ` [PATCH v2 5/8] selftests/resctrl: Add built in benchmark Fenghua Yu
2018-10-25 23:07 ` [PATCH v2 6/8] selftests/resctrl: Add mbm test Fenghua Yu
2018-10-25 23:07 ` [PATCH v2 7/8] selftests/resctrl: Add mba test Fenghua Yu
2018-10-25 23:07 ` [PATCH v2 8/8] selftests/resctrl: Add the test in MAINTAINERS Fenghua Yu
2018-10-29 22:56 ` [PATCH v2 0/8] selftests/resctrl: Add resctrl selftest Moger, Babu

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=DM5PR12MB24718634BDBD91020E52218895CC0@DM5PR12MB2471.namprd12.prod.outlook.com \
    --to=babu.moger@amd.com \
    --cc=arshiya.hayatkhan.pathan@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=reinette.chatre@intel.com \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --subject='RE: Fwd: [PATCH v2 2/8] selftests/resctrl: Add basic resctrl file system operations and data' \
    /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

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).