Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752152AbdHDVfX (ORCPT ); Fri, 4 Aug 2017 17:35:23 -0400 Received: from g9t5008.houston.hpe.com ([15.241.48.72]:33272 "EHLO g9t5008.houston.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbdHDVfV (ORCPT ); Fri, 4 Aug 2017 17:35:21 -0400 From: "Kani, Toshimitsu" To: "bp@alien8.de" CC: "linux-edac@vger.kernel.org" , "lenb@kernel.org" , "mchehab@kernel.org" , "tony.luck@intel.com" , "linux-kernel@vger.kernel.org" , "rjw@rjwysocki.net" , "linux-acpi@vger.kernel.org" Subject: Re: [PATCH v2 6/7] EDAC: add edac_check_mc_owner() to check MC owner Thread-Topic: [PATCH v2 6/7] EDAC: add edac_check_mc_owner() to check MC owner Thread-Index: AQHTDKTtKmj3ue76BkSL9ZHZV2c/aqJz3neAgADYpgA= Date: Fri, 4 Aug 2017 21:35:05 +0000 Message-ID: <1501881932.2042.121.camel@hpe.com> References: <20170803215753.30553-1-toshi.kani@hpe.com> <20170803215753.30553-7-toshi.kani@hpe.com> <20170804083007.GA15617@nazgul.tnic> In-Reply-To: <20170804083007.GA15617@nazgul.tnic> 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=toshi.kani@hpe.com; x-originating-ip: [15.219.147.8] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DF4PR84MB0185;6:5OTqmVUqPBjNrgChDrr1xGiIAYR3+kv7ljUxTKXiDrSGfOVUZFH6/G7NggnivASNpwK33iCIYf3Y3bFEdpMFXriu6zBOBSsVrhB+qBaR20xpY0i758Iv7dooMd6B/qc+0db6n5WRZqiw0xqOVlrdn0hIibPLg0YquoPxT+zxTRFAS1+skaR4L5Ziu3kQ+kxKCZvqH6E+xXHOLFjW6PAWMXKarCgr0wHhPX41tPfQ1WzAq2uFJyO8ZEq1OhBn8jMO/Rhm0/0iScekuQZ44u9D69Vbu1dE7v7Gqr7zyaWAi3Cex0nqWtTVN68Eu3SbNj05lSOK+Cvz8y9k+I6oSAPb6Q==;5:EWLhPYpfccGULVSDNHuL02zd8u8qL0jbY5K6TwUCCncG07Wc7B9iJHelXaG3+qW1ZoXpjKmIe4AzphLHBhIbtkpWoYRZzltcW9bpcsv0xs0dXsr9H2PpDIFfSpIEPz4DS/pfjsecPlQ8AeOxOsCIww==;24:WUUQGTbFkuwTBJJtqw2auDNInKhrgjbRQ9YKkKn6m/NibXb1py/YDALxgZRU12viyk1ry4FVQ8OdjNJ5437kj/+AqhNWMzffkwbswSIxeY0=;7:XBbXhw6ME+7W9QeDLfIyrfRn7UgUqQ73/8eo/CMFoXSpqGcR/AgNjYXsqaxyjduupoz4NpUSRdeKuruYz2EpBZZti8jVVup+mmXqWXwq6C3OOReL6yx/Rbupv8RRrY3W6Xm6FR5pTaVvtD3HYOyOZgO6pDhUbYQUTQckfUj/H8SvHXPRPTFlAiwXXepbcytz2LZ5PVfz08FixaUuGwN0gEfAvFq7Hn8ECZAXjT+NlA0= x-ms-office365-filtering-correlation-id: 1916a17e-f3da-428f-486f-08d4db80ac21 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DF4PR84MB0185; x-ms-traffictypediagnostic: DF4PR84MB0185: x-exchange-antispam-report-test: UriScan:(227479698468861)(228905959029699); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123558100)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DF4PR84MB0185;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DF4PR84MB0185; x-forefront-prvs: 0389EDA07F x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39860400002)(39450400003)(39400400002)(39850400002)(39410400002)(39840400002)(24454002)(377424004)(189002)(199003)(36756003)(5640700003)(106356001)(6436002)(6512007)(54906002)(6246003)(81166006)(81156014)(1730700003)(8676002)(5660300001)(8936002)(33646002)(305945005)(3660700001)(7736002)(103116003)(25786009)(2351001)(3280700002)(2501003)(2906002)(105586002)(478600001)(189998001)(6916009)(229853002)(86362001)(14454004)(6506006)(101416001)(66066001)(97736004)(2950100002)(4326008)(68736007)(2900100001)(76176999)(54356999)(38730400002)(53936002)(102836003)(3846002)(110136004)(50986999)(6116002)(77096006)(6486002);DIR:OUT;SFP:1102;SCL:1;SRVR:DF4PR84MB0185;H:DF4PR84MB0187.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <9210780E64964D409DE4B12D5E88565D@NAMPRD84.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Aug 2017 21:35:05.4366 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0185 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 base64 to 8bit by nfs id v74LZeZK004535 Content-Length: 3642 Lines: 114 On Fri, 2017-08-04 at 10:30 +0200, Borislav Petkov wrote: > On Thu, Aug 03, 2017 at 03:57:52PM -0600, Toshi Kani wrote: > > Only a single edac driver can be enabled for EDAC MC.  When > > ghes_edac is enabled, a regular edac driver for the CPU type / > > platform still attempts to register itself and fails in > > edac_mc_add_mc(). > > > > Add edac_check_mc_owner() so that regular edac drivers can check > > the owner of EDAC MC at the beginning of initialization. > > > > Also change the owner check to string comparison from address > > check. > > > > Signed-off-by: Toshi Kani > > Cc: Borislav Petkov > > Cc: Mauro Carvalho Chehab > > Cc: Tony Luck > > --- > >  drivers/edac/edac_mc.c |   15 ++++++++++++++- > >  drivers/edac/edac_mc.h |   12 ++++++++++++ > >  2 files changed, 26 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c > > index 4800721..52d8d5e 100644 > > --- a/drivers/edac/edac_mc.c > > +++ b/drivers/edac/edac_mc.c > > @@ -701,6 +701,19 @@ struct mem_ctl_info *edac_mc_find(int idx) > >  } > >  EXPORT_SYMBOL(edac_mc_find); > >   > > +/* > > + * Returns: > > + * 1 when EDAC MC is free or owned by the module name > > 1 for free OR owned?!? WTF? 1 means the caller's init function can continue its initialization -- such conditions are free or owned by itself. > > + * 0 when EDAC MC is owned by other module > > + */ > > +int edac_check_mc_owner(const char *mod_name) > > +{ > > + if (edac_mc_owner && strcmp(edac_mc_owner, mod_name)) > > strncmp() of course, with sensible maximal string length. strcmp() breaks when either edac_mc_owner or mod_name string ends. strncmp() assumes mod_name string is valid for a given length. Hence, the caller needs to supply the length to this function by adding a new arg 'length', which does not make it any safer. I think using strncmp() would require all edac drivers to declare a pre-defined length of module name... > > + return 0; > > + > > + return 1; > > +} > > +EXPORT_SYMBOL(edac_check_mc_owner); > > EXPORT_SYMBOL_GPL Will do. > >   > >  /* FIXME - should a warning be printed if no error detection? > > correction? */ > >  int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, > > @@ -742,7 +755,7 @@ int edac_mc_add_mc_with_groups(struct > > mem_ctl_info *mci, > >  #endif > >   mutex_lock(&mem_ctls_mutex); > >   > > - if (edac_mc_owner && edac_mc_owner != mci->mod_name) { > > + if (!edac_check_mc_owner(mci->mod_name)) { > >   ret = -EPERM; > >   goto fail0; > >   } > > diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h > > index 5357800..0e95eba 100644 > > --- a/drivers/edac/edac_mc.h > > +++ b/drivers/edac/edac_mc.h > > @@ -128,6 +128,18 @@ struct mem_ctl_info *edac_mc_alloc(unsigned > > mc_num, > >      unsigned sz_pvt); > >   > >  /** > > + * > > + * edac_check_mc_owner - Check the owner of EDAC MC > > + * > > + * @mod_name: pointer to the module name > > + * > > + * Returns: > > + * 1 when EDAC MC is free or owned by the module name > > + * 0 when EDAC MC is owned by other module > > + */ > > Documenting that function only once is enough. I personally prefer to document in .c, but since other funcs documented in dac_mc.h, I will keep the same style. Will remove the document in edac_mc.c. > > +extern int edac_check_mc_owner(const char *mod_name); > > + > > +/* > >   * edac_mc_add_mc_with_groups() - Insert the @mci structure into > > the mci > >   * global list and create sysfs entries associated with > > @mci structure. > >   * Thanks, -Toshi