Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760399AbbEEQLr (ORCPT ); Tue, 5 May 2015 12:11:47 -0400 Received: from mail-bl2on0101.outbound.protection.outlook.com ([65.55.169.101]:12261 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759525AbbEEQIw convert rfc822-to-8bit (ORCPT ); Tue, 5 May 2015 12:08:52 -0400 X-Greylist: delayed 58236 seconds by postgrey-1.27 at vger.kernel.org; Tue, 05 May 2015 12:08:52 EDT From: Jose Rivera To: Dan Carpenter CC: "devel@driverdev.osuosl.org" , "agraf@suse.de" , "arnd@arndb.de" , "bhupesh.sharma@freescale.com" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , Stuart Yoder , Scott Wood , "nir.erez@freescale.com" , "itai.katz@freescale.com" , "bhamciu1@freescale.com" , "R89243@freescale.com" , Richard Schmitt Subject: RE: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support Thread-Topic: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support Thread-Index: AQHQgdtcWmwch7II+U+VbnIIkniD+51lc9iAgAbl/LCAAML6AIAAYJLA Date: Tue, 5 May 2015 16:08:49 +0000 Message-ID: References: <1430242750-17745-1-git-send-email-German.Rivera@freescale.com> <1430242750-17745-2-git-send-email-German.Rivera@freescale.com> <20150430114957.GW14154@mwanda> <20150505084830.GL16501@mwanda> In-Reply-To: <20150505084830.GL16501@mwanda> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: oracle.com; dkim=none (message not signed) header.d=none; x-originating-ip: [192.88.168.49] x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1245; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:DM2PR0301MB1245;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1245; x-forefront-prvs: 0567A15835 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(24454002)(51704005)(377454003)(13464003)(106116001)(99286002)(122556002)(54356999)(40100003)(50986999)(76176999)(5890100001)(102836002)(76576001)(92566002)(62966003)(93886004)(77156002)(2656002)(87936001)(86362001)(66066001)(110136002)(107886002)(5001960100002)(46102003)(2950100001)(2900100001)(19580395003)(33656002)(19580405001)(74316001)(4001430100001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1245;H:DM2PR0301MB1309.namprd03.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 May 2015 16:08:49.4250 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1245 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4025 Lines: 104 > -----Original Message----- > From: Dan Carpenter [mailto:dan.carpenter@oracle.com] > Sent: Tuesday, May 05, 2015 3:49 AM > To: Rivera Jose-B46482 > Cc: devel@driverdev.osuosl.org; agraf@suse.de; arnd@arndb.de; Sharma > Bhupesh-B45370; gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org; > Yoder Stuart-B08248; Wood Scott-B07421; Erez Nir-RM30794; katz Itai- > RM05202; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Schmitt > Richard-B43082 > Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support > > On Mon, May 04, 2015 at 10:09:08PM +0000, Jose Rivera wrote: > > > > + WARN_ON((int16_t)irq_count < 0); > > > > > > This code is doing "WARN_ON(test_bit(15, (unsigned long > *)&irq_count));". > > > That seems like nonsense. Anyway, just delete the WARN_ON(). > > > > > I disagree. This WARN_ON is checking that irq_count is in the expected > > range (it fits in int16_t as a positive number). The > > dprc_scan_objects() function expects irq_count to be of type "unsigned > > int" (which is 32-bit unsigned) > > > > You're not allowed to disagree because it's a testable thing and not an > opinion about style or something. :P What you want is: > > WARN_ON(irq_count > SHRT_MAX); > I see your point now. The check "(int16_t)irq_count < 0)" will not be able to catch 0x10000 > 0x7fff, but "irq_count > SHRT_MAX) will. So I'll make the suggested change, but I would prefer to use S16_MAX rather than SHRT_MAX. > > > > + > > > > + if ((int16_t)irq_count > > > > > + mc_bus- > >resource_pools[FSL_MC_POOL_IRQ].max_count) { > > > > > > Why are we casting this? Also can you align it like: > > > > > This casting is done for safety, to prevent the comparison to be done > > in "unsigned int" due to integer promotion rules. > > We are truncating away the top bytes but then we use them later. > Fortunately we use them only to print out a warning, but if we used them > for anything else it would be a serious bug. > > Are you expecting .max_count to be negative? > No. > If not then both sides are positive and type promotion is fine. We can > delete the first (buggy) warning, like I said and just leave the second > warning. It will now complain if any of bits 16 to 31 are set where > before it wouldn't. > Agreed. I'll remove the (int16_t) type cast from the "if". So, I'll change this code snippet to be like this: WARN_ON(irq_count > S16_MAX); if (irq_count > mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) dev_warn(...); Although the WARN_ON seems redundant with the "if", it catches a different problem. The WARN_ON() catches irq_count to be out of range, the "if" tells when we run out of IRQ resources fro a valid irq_count. > > > to read what "goto error;" does. The error handling here calls > > > devm_kfree() which is not needed... devm_ functions automatically > > > clean up after themselves. This seems a pattern throughout. Do a > > > search for > > > devm_free() and see which ones are really needed or not. > > > > > I know that memory allocated with devm_kzalloc() is freed at the end > > of the lifetime of the device it is attached to. However, in error > > paths, why wait until the device is destroyed? Why not free the memory > > earlier so that it can be used for other purposes? > Why then do the devm_kfree() function exist? I will not remove the devm_free() calls unless the upstream maintainer requires me to do so. > My understanding is that devm_ functions are supposed to be used in the > probe() functions to simplify the error handling. So hopefully the > device lifetime ends as soon as this function returns a failure. > > devm_ function are not a use them everywhere because now the kernel has > garbage collection type thing. > > regards, > dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/