Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751298AbcCFUoY (ORCPT ); Sun, 6 Mar 2016 15:44:24 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:54178 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750718AbcCFUoU (ORCPT ); Sun, 6 Mar 2016 15:44:20 -0500 From: Arnd Bergmann To: "Russell King - ARM Linux" Subject: Re: [PATCH 1/2] ASoC: cs35l32: avoid uninitialized variable access Date: Sun, 6 Mar 2016 21:43:25 +0100 User-Agent: KMail/1.12.2 (Linux/3.19.0-54-generic; KDE/4.3.2; x86_64; ; ) Cc: Mark Brown , Brian Austin , Kuninori Morimoto , Liam Girdwood , Paul Handrigan , linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org References: <1453741678-1988125-1-git-send-email-arnd@arndb.de> <20160305145400.GF19428@n2100.arm.linux.org.uk> In-Reply-To: <20160305145400.GF19428@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201603062143.25158.arnd@arndb.de> X-Provags-ID: V03:K0:oiOcT9oeCLbUbiXTuiA88thGZ6Syw9GFc/etlMW6SGNlsrUObDA QP8ow0n2UGnKlPMYyz6/WFZHj7BdzW84b9MeIix3xSMfNpOoGtlhXiKM1/roA8ZhLHNNGLG B1fscA1XGIpEzyxVnVc1o65kQkQadyEnGCMiikg8REQBRS/oPECRBuh9FM37/KPgpHovMAV QmLD98MHkNc+74yavaNyw== X-UI-Out-Filterresults: notjunk:1;V01:K0:oRMyq3iaYsE=:+e4gM0LTf7iNqLB7DPtQLi xk8wl+CzEEge82hpjCsQH5onNyyhvKpAKYjmHWcYjLyY1jgZLsSKZOZ6lZtt3KKVPiiConaq2 qrJd7mCZZWcphaFVe+z01Zf2B1Kg7FuoxldS7k3VVbsvqJfZnvEBr6v4TcN+AWK93WB7cW+64 sM0xX5yv7rtV2a3Y9FBOZIEseVW22a2yCQVmKTu2ZwbJzHRwUwTlbnzl4ev4Y0DLkk8FXcm8X 874kjI7Jd2BGYIIkKlwz8HLnqUciSdwBPnS5X5LxhsNzZi5hEF7BfpjkaL2H6bAQRGUyoCDqn 0909VM5YiYRJSwxiVK68JJo2es5XkCysmPTNWLwmOakafczgwJIbiWFfUVEZXZagkC7b0/UFE Rwj/me3nWxsGZ11dqdPg9AhWhzGpDVj2Oymde3deooSn9qdkTPFPYDRp4sjtuhIXgeSlfrYly pfCiyBnQJ2njQdsMofbXenoOcHpUa0/sEVN+nRbhi6b9iSFEIBQm86YSBxwaOtPXbQ0z9cZj4 +V8CtI3B3jI4jS7Bu+M69mPGabbaWcPwjJQ14dzHGelAoPDYr+2zJbxEpZRe9TCIOOA1t3HcF grdkQD4ulJhsm2I1yAw4kul8O2RMePjNDY4x34gkNRXU082rdOEmxe/1nMKR1Vrnyj8I6+Ggd R1HKVCCm02eCTvUvokqJ+9ms5/Q+4ePo14MhdjvDfuf4cjidt+bXG4yvot4qboDB1942FFz54 ai105mRQuATm1F8d Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1605 Lines: 35 On Saturday 05 March 2016, Russell King - ARM Linux wrote: > On Mon, Jan 25, 2016 at 06:07:32PM +0100, Arnd Bergmann wrote: > > gcc warns about the possibilty of accessing a property read from > > devicetree in cs35l32_i2c_probe() when it has not been initialized > > because CONFIG_OF is disabled: > > > > sound/soc/codecs/cs35l32.c: In function 'cs35l32_i2c_probe': > > sound/soc/codecs/cs35l32.c:278:2: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized] > > > > The code is actually correct because it checks the dev->of_node > > variable first and we know this is NULL here, but by adding a > > check for IS_ENABLED(CONFIG_OF), we can let the compiler know > > as well, and also generate smaller object code. > > No, the code is buggy, and the compiler is very correct in warning about > it. ... > > Note that 'out_values' is not written to if of_find_property_value_of_size() > returns an error. Therefore, if cirrus,boost-manager is missing, the > resulting value of 'val' is left uninitialised. You are right, this is an actual bug in the driver, and my patch just hides it. Interestingly, this is not the case that the warning was about, as we get the warning only when CONFIG_OF is disabled and the code is correct (because dev->of_node is guaranteed to be NULL), but we don't get the warning when CONFIG_OF is enabled and we can actually run into the problem. Fixing the driver to have correct error handling on the property functions will make the warning go away and fix the bug you pointed out, so we should definitely do that and drop my patch. Arnd