Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753991AbdC1Dit (ORCPT ); Mon, 27 Mar 2017 23:38:49 -0400 Received: from g2t1383g.austin.hpe.com ([15.233.16.89]:7497 "EHLO g2t1383g.austin.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753864AbdC1Dir (ORCPT ); Mon, 27 Mar 2017 23:38:47 -0400 From: "Elliott, Robert (Persistent Memory)" To: "kan.liang@intel.com" , "peterz@infradead.org" , "mingo@redhat.com" , "acme@kernel.org" , "linux-kernel@vger.kernel.org" CC: "tglx@linutronix.de" , "eranian@google.com" , "jolsa@kernel.org" , "ak@linux.intel.com" Subject: RE: [PATCH 2/3] tools lib api fs: Add sysfs__write_int function Thread-Topic: [PATCH 2/3] tools lib api fs: Add sysfs__write_int function Thread-Index: AQHSpASaO2AHZD3CoEilt03W1ETD+qGpm+Dw Date: Tue, 28 Mar 2017 03:38:21 +0000 Message-ID: References: <1490293551-5552-1-git-send-email-kan.liang@intel.com> <1490293551-5552-3-git-send-email-kan.liang@intel.com> In-Reply-To: <1490293551-5552-3-git-send-email-kan.liang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [2601:2c3:877f:e23c:ddb1:dd70:4083:6599] x-microsoft-exchange-diagnostics: 1;DF4PR84MB0170;7:ASDJgFKN8Ics4oFLN9ysobgeo/97iTovTEYlBzTtOzZG+9R1sCZAwhW5Gtr7m9qx+9NwGDuAe2BiAIRX9FPVz9eZsgOmbU7oMqJR/5NsljbResucoTU/4yZt9ZTMwPnBkCy6jYQ/OFcX/KFi8GceeuaSarPt7NgoWjHsUMVDtcV+GwA2NNuEZ8api8+hI0z4oNMzppx42tqEoTzGnGJp7pT6PQXCARJgNjTE8zIe+O+Uk6+4mJNrKoyhYi2d2laV0kNjUOAzV2XGJeNUGD1MFcJZMRQq7dXbqGTxqXp42r2nIUd2AIaBhtbmkEYRrCjVOS6cZ+hoyqzZSWQbu1Gyog== x-ms-office365-filtering-correlation-id: 356b4342-6748-4799-cb17-08d4758be1d8 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081);SRVR:DF4PR84MB0170; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123558025)(20161123555025)(6072148);SRVR:DF4PR84MB0170;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0170; x-forefront-prvs: 0260457E99 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39410400002)(39850400002)(39860400002)(39450400003)(39840400002)(377454003)(13464003)(38730400002)(122556002)(53546009)(6246003)(76176999)(55016002)(7736002)(25786009)(4326008)(9686003)(50986999)(54356999)(54906002)(6506006)(305945005)(77096006)(6436002)(53936002)(74316002)(33656002)(5660300001)(2900100001)(2501003)(81166006)(102836003)(189998001)(2950100002)(6116002)(86362001)(3660700001)(3280700002)(7696004)(2906002)(2201001)(229853002)(8936002)(8676002);DIR:OUT;SFP:1102;SCL:1;SRVR:DF4PR84MB0170;H:DF4PR84MB0169.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Mar 2017 03:38:21.3765 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0170 X-OriginatorOrg: hpe.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id v2S3dDlG001554 Content-Length: 782 Lines: 29 > -----Original Message----- > From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel- > owner@vger.kernel.org] On Behalf Of kan.liang@intel.com > Sent: Thursday, March 23, 2017 1:26 PM > Subject: [PATCH 2/3] tools lib api fs: Add sysfs__write_int function ... > diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c ... > + > +int sysfs__write_int(const char *entry, int value) > +{ > + char path[PATH_MAX]; > + const char *sysfs = sysfs__mountpoint(); > + > + if (!sysfs) > + return -1; > + > + snprintf(path, sizeof(path), "%s/%s", sysfs, entry); > + > + return filename__write_int(path, value); In the unlikely event of an overflow, it would be safer to confirm that the string fit into the path array (by using scnprintf()?) before trying to open that path.