From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0076.outbound.protection.outlook.com [157.55.234.76]) by dpdk.org (Postfix) with ESMTP id 3E7EC2BAB for ; Mon, 13 Jun 2016 16:19:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=MShoocCYFpZkJLCp28/MiXDBik0K+RREJH845iBMs1E=; b=A8omZWC1X/hAQ4Fj/limKUlGXx39jTP+u/yw6q2KbN/RzphIWXthDx2U0fgthnyIe5ILg5Et6NClfd70muzSxebtZ2bClcv4rrW8AHRYed0XZRobZ2yvbuDFoeaWCDsRhxQ3xbJINSwaea1+yw7Yn3sfx0bxt4mLFFd5ujYPWOQ= Received: from DB5PR0401MB2054.eurprd04.prod.outlook.com (10.166.11.137) by DB5PR0401MB2053.eurprd04.prod.outlook.com (10.166.11.136) with Microsoft SMTP Server (TLS) id 15.1.517.8; Mon, 13 Jun 2016 14:19:05 +0000 Received: from DB5PR0401MB2054.eurprd04.prod.outlook.com ([10.166.11.137]) by DB5PR0401MB2054.eurprd04.prod.outlook.com ([10.166.11.137]) with mapi id 15.01.0517.009; Mon, 13 Jun 2016 14:19:05 +0000 From: Shreyansh Jain To: Jan Viktorin CC: "dev@dpdk.org" , David Marchand , Thomas Monjalon , Bruce Richardson , Declan Doherty , "jianbo.liu@linaro.org" , "jerin.jacob@caviumnetworks.com" , "Keith Wiles" , Stephen Hemminger Thread-Topic: [dpdk-dev] [PATCH v1 02/28] eal: extract function eal_parse_sysfs_valuef Thread-Index: AdHFczetukg8uaENR3C7BYmp0weYJw== Date: Mon, 13 Jun 2016 14:18:40 +0000 Deferred-Delivery: Mon, 13 Jun 2016 14:18:32 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=shreyansh.jain@nxp.com; x-originating-ip: [192.88.169.1] x-ms-office365-filtering-correlation-id: 230752ba-9b78-4014-ee42-08d39395ad31 x-microsoft-exchange-diagnostics: 1; DB5PR0401MB2053; 6:SgQWCQCl0+AkVTN6xUPpMvX0Nkyphy0/6LVL6EahAfi/ruNIQOrFIeSoaI6lbx9nwvwDcMnlIstawSOdfIn6M88DgOSl5ziNAg4xXlmtBLVCwZSnANaIwkf+13KHt5aQShyazUESXlqlu/jFgGZNG0f47AZjjsHhVn9W/hDdjw023yMJQRiilT6ldGdUusz2lB/AVZXW1q2Ft0spfWb4+Rq0NlmMOImj3RyeHPvPkjZ8h5xavAwwMgaMyLDhjzTHpb8Bm3BN7M2rexUeNZL+eaTulk814Jun6FdryRuwdtFSAgXEjJ41T/apQxAeMUXQIeO8qBqv+rZuyS42B1FJMQ==; 5:B6zI8yXYrl9bVSeHS7LbCmR/KN7+vkXx0LYlWKLp6n+sfnsSytS17ESNw6vnicl6iaNG8hdO098QB5QqLp3juRZbNlJXhQ0fuaD/X0wPn1iLVRsO5/WaSdHJFOKnUxtQ6UA51ugELK4kCSqTAawT4w==; 24:YSGLNd1oksLF8gY5qjGwNg9b4xlaJPNl9ZcPiRBmfTatmxQc4l1qA/zewWkgBTclBgDWnTLT/jiSdGER+teOl25gjNMKh3URG107w0k6xlk=; 7:XdbOvq2pwkCxjAUDjT6+PBgA2cI4K1M4asZ/rof38Rr8md0CUYsDoDl4OFUKfrAPaQlzxobxeqXJ/Lb4P0/0nS2+Fy0q3Fjhvz9gptvtmoNyyyygRGNhi/+GO2Za0kpB2YueVl3sao5cg58e54zNu/7/x80xM5blI1NC6tOwpX3TyE1tqPqkWyRhy+WJeRrmLFXkCZ7qkfbBLh96TWa7p4aw65YCdAwZOkbWVZk1AP0= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR0401MB2053; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:DB5PR0401MB2053; BCL:0; PCL:0; RULEID:; SRVR:DB5PR0401MB2053; x-forefront-prvs: 0972DEC1D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(199003)(189002)(13464003)(377454003)(81166006)(81156014)(33656002)(5008740100001)(106356001)(5003600100002)(68736007)(19580405001)(19580395003)(9686002)(3280700002)(66066001)(4326007)(50986999)(54356999)(5002640100001)(8936002)(122556002)(189998001)(110136002)(5004730100002)(11100500001)(101416001)(87936001)(97736004)(2900100001)(92566002)(77096005)(74316001)(10400500002)(105586002)(3660700001)(2906002)(86362001)(6116002)(102836003)(3846002)(586003)(76576001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR0401MB2053; H:DB5PR0401MB2054.eurprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; CAT:NONE; LANG:en; CAT:NONE; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2016 14:19:05.2530 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR0401MB2053 Subject: Re: [dpdk-dev] [PATCH v1 02/28] eal: extract function eal_parse_sysfs_valuef X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2016 14:19:07 -0000 Hi Jan, > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jan Viktorin > Sent: Friday, May 06, 2016 7:18 PM > To: dev@dpdk.org > Cc: Jan Viktorin ; David Marchand > ; Thomas Monjalon ; > Bruce Richardson ; Declan Doherty > ; jianbo.liu@linaro.org; > jerin.jacob@caviumnetworks.com; Keith Wiles ; Step= hen > Hemminger > Subject: [dpdk-dev] [PATCH v1 02/28] eal: extract function > eal_parse_sysfs_valuef >=20 > The eal_parse_sysfs_value function accepts a filename however, such inter= face > introduces race-conditions to the code. Introduce the variant of this > function > that accepts an already opened file instead of a filename. >=20 > Signed-off-by: Jan Viktorin > --- > lib/librte_eal/common/eal_filesystem.h | 5 +++++ > lib/librte_eal/linuxapp/eal/eal.c | 36 +++++++++++++++++++++++-----= ---- > -- > 2 files changed, 30 insertions(+), 11 deletions(-) >=20 > diff --git a/lib/librte_eal/common/eal_filesystem.h > b/lib/librte_eal/common/eal_filesystem.h > index fdb4a70..7875454 100644 > --- a/lib/librte_eal/common/eal_filesystem.h > +++ b/lib/librte_eal/common/eal_filesystem.h > @@ -43,6 +43,7 @@ > /** Path of rte config file. */ > #define RUNTIME_CONFIG_FMT "%s/.%s_config" >=20 > +#include > #include > #include > #include > @@ -115,4 +116,8 @@ eal_get_hugefile_temp_path(char *buffer, size_t bufle= n, > const char *hugedir, int > * Used to read information from files on /sys */ > int eal_parse_sysfs_value(const char *filename, unsigned long *val); >=20 > +/** Function to read a single numeric value from a file on the filesyste= m. > + * Used to read information from files on /sys */ > +int eal_parse_sysfs_valuef(FILE *f, unsigned long *val); > + > #endif /* EAL_FILESYSTEM_H */ > diff --git a/lib/librte_eal/linuxapp/eal/eal.c > b/lib/librte_eal/linuxapp/eal/eal.c > index 4b28197..e8fce6b 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -126,13 +126,30 @@ rte_eal_get_configuration(void) > return &rte_config; > } >=20 > +int > +eal_parse_sysfs_valuef(FILE *f, unsigned long *val) Trivial Comment: Maybe it is just me, but this function name is too close t= o its caller 'eal_parse_sysfs_value'. Probably, the name of the caller can = be changed to 'eal_parse_sysfs' because anyways value parsing is being done= in this ('eal_parse_sysfs_valuef()) function now. And, of course, dropping= the '..f' in this name. I almost skipped the '..f' in the name and wondered how two functions havin= g same name exist :D > +{ > + char buf[BUFSIZ]; > + char *end =3D NULL; > + > + RTE_VERIFY(f !=3D NULL); > + > + if (fgets(buf, sizeof(buf), f) =3D=3D NULL) > + return -1; > + > + *val =3D strtoul(buf, &end, 0); > + if ((buf[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\n')) > + return -2; > + > + return 0; > +} > + > /* parse a sysfs (or other) file containing one integer value */ > int > eal_parse_sysfs_value(const char *filename, unsigned long *val) > { > + int ret; > FILE *f; > - char buf[BUFSIZ]; > - char *end =3D NULL; >=20 > if ((f =3D fopen(filename, "r")) =3D=3D NULL) { > RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n", > @@ -140,21 +157,18 @@ eal_parse_sysfs_value(const char *filename, unsigne= d > long *val) > return -1; > } >=20 > - if (fgets(buf, sizeof(buf), f) =3D=3D NULL) { > + ret =3D eal_parse_sysfs_valuef(f, val); > + if (ret =3D=3D -1) { > RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n", > - __func__, filename); > - fclose(f); > - return -1; > + __func__, filename); > } > - *val =3D strtoul(buf, &end, 0); > - if ((buf[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\n')) { > + else if (ret < 0) { > RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n", > __func__, filename); > - fclose(f); > - return -1; > } > + > fclose(f); > - return 0; > + return ret; > } >=20 >=20 > -- > 2.8.0 - Shreyansh