From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnd Bergmann Subject: Re: [PATCH 2/3] mmc: dw_mmc: add dw_mmc-k3 for k3 platform Date: Mon, 30 Dec 2013 21:27:41 +0100 Message-ID: <201312302127.41690.arnd@arndb.de> References: <1388241295-20051-1-git-send-email-zhangfei.gao@linaro.org> <52C1AB34.3010402@linaro.org> Mime-Version: 1.0 Content-Type: Text/Plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Return-path: Received: from moutng.kundenserver.de ([212.227.126.171]:62762 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932117Ab3L3U2O (ORCPT ); Mon, 30 Dec 2013 15:28:14 -0500 In-Reply-To: <52C1AB34.3010402@linaro.org> Sender: linux-mmc-owner@vger.kernel.org List-Id: linux-mmc@vger.kernel.org To: zhangfei Cc: Zhangfei Gao , Jaehoon Chung , "devicetree@vger.kernel.org" , Mike Turquette , patches@linaro.org, Seungwon Jeon , "linux-mmc@vger.kernel.org" , Haojian Zhuang , cpgs@samsung.com, Kumar Gala , Chris Ball , Zhigang Wang , linux-arm-kernel On Monday 30 December 2013, zhangfei wrote: > >>>> +static int dw_mci_k3_suspend(struct device *dev) > >>>> +{ > >>>> + struct dw_mci *host = dev_get_drvdata(dev); > >>>> + int ret = 0; > >>>> + > >>>> + ret = dw_mci_suspend(host); > >>> > >>> You should never initialize local variables when they are set later in the > >>> function (the ret = 0 part above). For more complex functions, this prevents > >>> gcc from warning you about accidentally uninitialized uses. > > I am sorry I may fall into the dead end, but still quite not understand > this rule. > I alwayes thought it would be a good habit to init local variables before. > Do you mean it should NOT init local variable as much as possible and > only init on demand, like solving the gcc warning. > Why not init the them at start in case random value cause unpredicted error? The gcc warnings are 100% correct, we can use them as a tool to write better code. If you write code that has no warnings with a modern compiler, you will never use random values, but if you always initialize the local variables, you can end up accidentally using '0' where you shouldn't have. See http://rusty.ozlabs.org/?p=232 for an excellent article on the topic by former Linaro assignee Rusty Russell. Arnd