Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754310AbcKNPLH (ORCPT ); Mon, 14 Nov 2016 10:11:07 -0500 Received: from mail-db5eur01on0056.outbound.protection.outlook.com ([104.47.2.56]:25408 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753532AbcKNPLB (ORCPT ); Mon, 14 Nov 2016 10:11:01 -0500 From: Stuart Yoder To: Dan Carpenter , Shiva Kerdel CC: "devel@driverdev.osuosl.org" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , Nipun Gupta , "treding@nvidia.com" , "Laurentiu Tudor" Subject: RE: [PATCH 1/2] Staging: fsl-mc: include: mc: Kernel type 's16' preferred over 'int16_t' Thread-Topic: [PATCH 1/2] Staging: fsl-mc: include: mc: Kernel type 's16' preferred over 'int16_t' Thread-Index: AQHSPAvfdnmnRhb0FUi9htvgspyz2aDTo/IAgAA0wlCABGyFAIAATIMw Date: Mon, 14 Nov 2016 14:55:06 +0000 Message-ID: References: <20161111110740.1926-1-shiva@exdev.nl> <20161111112326.GG28701@mwanda> <20161114100447.GJ28701@mwanda> In-Reply-To: <20161114100447.GJ28701@mwanda> 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=stuart.yoder@nxp.com; x-originating-ip: [192.88.168.49] x-microsoft-exchange-diagnostics: 1;VI1PR0401MB1856;7:rH3mOkawebR4EoAPsolaoae4pWTAHrFGEUoqT360WEB1S17Y/MmNNEI6vDSgTkCD91/0VuxCXxSN+C/uH7ZJN76QGRvTkHcRWCVJ3EUwzn3uqeXsvbtvE6L50vML4b8WI6ZphXch2KWe0K1qa1ZTBFZ8Tsdu/XEWt/OkBZa+4VKB3oiux60/TLdwakByWVXIJAaWUNO5aMETMvkkYiCf4rs429zzPOtBtVqD74VD+8QIVP9fxYmoXZjdKwTIk/T4qfL5aQ3D9rUTZr+jhBm2M0YZko/a0kfekranYLo2ZMbrRQbD0uzW3PHn16v/HfGjTAb0AjwRhQz/5TLc3i6L2p2TJGsXoGiMkDBdJQnUb7A= x-ms-office365-filtering-correlation-id: ce743b9c-c829-45af-0290-08d40c9e38b5 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0401MB1856; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6045074)(6060326)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6046074)(6061321);SRVR:VI1PR0401MB1856;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0401MB1856; x-forefront-prvs: 0126A32F74 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(336003)(377454003)(13464003)(189002)(24454002)(199003)(7846002)(305945005)(102836003)(7736002)(50986999)(54356999)(76176999)(68736007)(33656002)(3280700002)(9686002)(7696004)(3846002)(74316002)(5660300001)(8676002)(106356001)(66066001)(8936002)(81156014)(106116001)(3660700001)(101416001)(105586002)(81166006)(6116002)(229853002)(189998001)(93886004)(122556002)(87936001)(586003)(92566002)(5001770100001)(77096005)(4326007)(76576001)(97736004)(2906002)(2900100001)(86362001)(2950100002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB1856;H:VI1PR0401MB2638.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Nov 2016 14:55:06.0897 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB1856 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 uAEFBBLv020439 Content-Length: 3005 Lines: 77 > -----Original Message----- > From: Dan Carpenter [mailto:dan.carpenter@oracle.com] > Sent: Monday, November 14, 2016 4:06 AM > To: Stuart Yoder > Cc: Shiva Kerdel ; devel@driverdev.osuosl.org; gregkh@linuxfoundation.org; linux- > kernel@vger.kernel.org; Nipun Gupta ; treding@nvidia.com; Laurentiu Tudor > > Subject: Re: [PATCH 1/2] Staging: fsl-mc: include: mc: Kernel type 's16' preferred over 'int16_t' > > On Fri, Nov 11, 2016 at 02:52:31PM +0000, Stuart Yoder wrote: > > > > diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h > > > > index e915574..c7cad87 100644 > > > > --- a/drivers/staging/fsl-mc/include/mc-bus.h > > > > +++ b/drivers/staging/fsl-mc/include/mc-bus.h > > > > @@ -42,8 +42,8 @@ struct msi_domain_info; > > > > */ > > > > struct fsl_mc_resource_pool { > > > > enum fsl_mc_pool_type type; > > > > - int16_t max_count; > > > > - int16_t free_count; > > > > + s16 max_count; > > > > > > My understanding is that this has to be signed because the design of > > > this driver is that we keep adding devices until the the counter > > > overflows. After that there are a couple tests for > > > "if (WARN_ON(res_pool->max_count < 0)) " which prevent the driver from > > > working again. > > > > > > This all seems pretty horrible. > > > > Can you elaborate? > > > > The resource pools managed by this driver are populated by hardware objects > > discovered when the fsl-mc bus probes a DPRC/container. > > > > The number of potential objects discovered of a given type is in the hundreds, > > so a signed 16-bit number is order of magnitudes larger than anything we will > > ever encounter. > > > > Would you feel better about this if max_count was an int? > > Yeah. > > > > > The max_count reflects the total number of objects discovered. If that is > > exceeded we display a warning, because something is horribly wrong. Nothing > > stops working, the allocator simply refuses to add anything else to the > > free list. > > I didn't look at this carefully... Anyway we can't remove devices > either. If we just had an upper bound instead of overflowing the s16 > then we could still remove devices. > > > > > The only reason max_count is there at all is as an internal check against > > bugs and resource leaks. If the driver is being removed and a resource > > pool is being freed, max_count must be zero...i.e. all objects should have > > been removed. If not, there is a leak somewhere. So, it's a sanity check. > > > > Just use a normal upper bound with a #define instead of an magic number > hidden and then disguised as an integer overflow. Ok, agree that it would be clearer like that. Shiva, can you respin this patch and just make both max_count and free_count to be of type "int". I will get Dan's suggestion sent as a separate patch...to #define the upper bound instead of relying on integer overflow. Thanks, Stuart