From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539AbcADQlr (ORCPT ); Mon, 4 Jan 2016 11:41:47 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:60286 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751704AbcADQln (ORCPT ); Mon, 4 Jan 2016 11:41:43 -0500 From: Arnd Bergmann To: Russell King - ARM Linux Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Brian Austin , Liam Girdwood , Paul Handrigan , linux-kernel@vger.kernel.org, Mark Brown Subject: Re: [PATCH] ASoC: cs35l32: avoid uninitialized variable access Date: Mon, 04 Jan 2016 17:41:05 +0100 Message-ID: <3088017.xkc6Hgo0y2@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <20160104152058.GH19062@n2100.arm.linux.org.uk> References: <2884997.s8B8BuE04L@wuerfel> <9222694.IRNnfpj6Tn@wuerfel> <20160104152058.GH19062@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:xQkuAXVaehuZI+ksttiNXpzfQ6YzGcqwfbPhfHVJiJk7DAjpTl4 7o9643AZ4MszaTNuurefUDpFVgLAFF0LYbFiLA1r6eDk4gZ2mIdA+xkGznHiu/c10H9q3uJ LFmlfq0LQa4/5vj+o2LiVrbFA348PMx3b0dWg80fq4wSrs4vqscql14vuBAn6Xf6P9CK3ov SpGjsRnINsaB7YGV71IXQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:oaNVw2AvTew=:AyoYdIsxXB/ztAmsp+NCoq eB5aDCjIOIQPBv0ktZgl9pdGnktmFrtC5Hx8Ejqho0zomgnpR/1Fxs5H52ap4Z0udXKN+csBB JqP3P0JlzyopGvD9y4NenPrWyUD9aHWdiviE6QkIaKqGTRE93gwr8g3hD8UZkWDzPKv8iEuRM FgRfBUdrn30F1xVByN+gpM6U+DtJp+oVeXAMWoNp3KazkvG0RpSBRLOELpPA/Ak75XDt0/8QP khuumcPl82N+M4cF+nJZEgIH57sDufxkcodhve6S5e/TmJcayDBCCSakUkvzB9rcXzwWJ69n/ s14SWIlY8MZm+tRHoM0adeGC6qtjKzFMIaxhJGj1n5EmGXYT/Xyr7FBEZP/NcDt9WNIAfFhkp Tikzb6lEC9yLspUCI8QLBmMkWFz6biK83/zYhTww0MSkjUUk8OXhwQXW0Dbpi4ADurv9Xr49H 1wHP36KsAEA/LJbgNwnP2+kzMPMOZzLi/aiF+B0H7MmG4Xz1kTBPDsgjyBC1YHGbf6gaHgVek Fne7yj2u4Wu+u0RfuFQihyar2tQB9nlb7KK0ZWqf6+eL6OtISeo4JbjWDUFCOKRoBHnvWmvoW MwibYb6uZ2VbdYCfXIZu6Nttjl0d2YIvtj4wmiR7ljFQbxTCTL5j8kVO4+isPCM1wZuVB31Tr 0hzusEiYl7CV45YbJk/M3glpA80euh/EhAM3mPlURZKrJ9EiFIcsDydhjQJZotOky1rqpKNCY 3J5IfggeLLEzyza6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 04 January 2016 15:20:58 Russell King - ARM Linux wrote: > On Mon, Jan 04, 2016 at 04:17:47PM +0100, Arnd Bergmann wrote: > > On Saturday 02 January 2016 14:17:46 Mark Brown wrote: > > > On Sat, Jan 02, 2016 at 12:19:52AM +0100, Arnd Bergmann wrote: > > > > > > > - if (i2c_client->dev.of_node) { > > > > + if (IS_ENABLED(CONFIG_OF) && i2c_client->dev.of_node) { > > > > > > This would be a lot nicer if there was an __always_null annotation we > > > could put on of_node for !OF configurations, that'd Just Work and this > > > can't be the only case where we have this idiom. > > > > > > > How about an inline helper like > > > > static inline struct device_node *dev_of_node(struct device *dev) > > { > > if (IS_ENABLED(CONFIG_OF)) > > return dev->of_node; > > ITYM: > > return IS_ENABLED(CONFIG_OF) ? dev->of_node : NULL; > > or > > if (IS_ENABLED(CONFIG_OF)) > return dev->of_node; > else > return NULL; > Right, yes. That reminds of a different problem that has been bugging me for a while: We frequently have a pattern like #ifdef CONFIG_FOO static int function(void) { ... } #endif struct operations = { ... #ifdef CONFIG_FOO .function = function; #endif ... }; Except that people constantly get it wrong, e.g. by using the wrong ifdef, forgetting one of the two ifdefs, or by leaving unused static functions that only get called indirectly from the other one that is built conditionally. We could add a macro like #define COND_PTR(config, ptr) (IS_ENABLED(config) ? (ptr) : NULL) and then let the compiler figure out that "function" is unused even without an explicit __maybe_unused annotation. The function above can be simplied to static inline struct device_node *dev_of_node(struct device *dev) { return COND_PTR(CONFIG_OF, dev->of_node); } with that, which is another benefit. Arnd