Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp805627img; Fri, 22 Mar 2019 08:58:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEKmw9oGeAbR0SecnznlcifTePlOzjCTlFSnZhHR1HOy44wt5nyM4rQG6LnZidE8SxbVeM X-Received: by 2002:a63:8142:: with SMTP id t63mr4510859pgd.63.1553270292515; Fri, 22 Mar 2019 08:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553270292; cv=none; d=google.com; s=arc-20160816; b=gw8/VTJe0EbwVZrrBrjdWlYRxm4uloJOf7hlFx+yEWXgNkWnZbihXDTbyezYMfe/ve MDPa1DVURns41rr8zYoLYRAqUzE0zcZ+WEnWsRHmHG4qoqyivIiTKPxqvudiDlh7ieCD U0ztSHxmOXdQkNUV7mJZmrUdXMAIU9xffaR+RkfhfltvwaSH4YdjNjp/3CJsuYNAKoDK LMny0s25kCEW3mYJCCL6a+Pyv0QDczTjndUbv3P7UU/4U6QAXe+j8ampHIDmI0d0Cjf5 ggwIc7xH86HZYZFaafvtbLDeAep1HO07m9dnRRoESPil+W2JXqNoIC91fgbJS/T0glt1 GW4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=z0B/Cv0OnhJkmn5yNu2Lngwyw6MsW1iAP//0V/4H8MA=; b=LJGy1TcGQ68Xg0A7FOdzZVoBC3sR0yzPDN6TLKsysUlphZRxjsWX6N9RBqT0NIESce iisrUxl1tSumnre+FiSiy7S4sHK1prODeEX/spdVSybFu2OSuiUmKpToUKqiFQ38X4H7 BhggLmwnYGW/HinRbEXV3TnJpfhATmv0VvDXZFveC2IARfo4Xh2C7o9nAAqZoLqbyOEZ C995Ef4sWtQeb7pvAkVCX9vCT4ROaH/GdXqIfKAw+oU8l0+WZU5UkGt/oaG4k2Xaffuh Z8NAb7XgX1EGyb6rHmsZixSioY+LdxoK/04D8/MfOeDfaHiVq+RRzritIsOZCQjA6/M2 PIPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fWdhwFmB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c22si7080504pls.17.2019.03.22.08.57.54; Fri, 22 Mar 2019 08:58:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fWdhwFmB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728081AbfCVP5J (ORCPT + 99 others); Fri, 22 Mar 2019 11:57:09 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:34217 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727169AbfCVP5J (ORCPT ); Fri, 22 Mar 2019 11:57:09 -0400 Received: by mail-ed1-f68.google.com with SMTP id a16so2114076edn.1 for ; Fri, 22 Mar 2019 08:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=z0B/Cv0OnhJkmn5yNu2Lngwyw6MsW1iAP//0V/4H8MA=; b=fWdhwFmBzai3h75T33BkPtxtkUojOIqMf1qW+uTibrnf9acvxZ1DE9mDth643oDWYm Rmo65LQzLme41zkKyzHT5PQm+J1rcNDHcOKLzWrOhC6APh7SkJirsolV+FlG8PRXeXy/ d18BbvSZZo9vEpakiPlbgTUP+s3IP/Ty6NKmaopDRrgEVzbrdmKgeJvcLogwdfGwQ2zA QJ13zxQZ4Ec6IcVGxhPvWq1Jekyw0PesbSjFXpNHyJcpfyGVk+Dgbf4B3z510/lgMK2b ariAKcIY3PSpic91DF1nQSmqzYscupH0Ao++VtROvhrGD/VmrjbWugy3C5kG3WzYQ6Pg l8zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=z0B/Cv0OnhJkmn5yNu2Lngwyw6MsW1iAP//0V/4H8MA=; b=UW8UHmpYLisfpdDPvlMgICizDRTNoV1JARLS67/fLIS6LqfDyMPluxEaNYxuSNsEBh 6e1+wDsv6Q9/Z+L6BtatUutC8xJYzj37Dk/H/gVn7DskygoC+eSlWw8gO+zsNHrgvo6s eAQ1FuSqWs2fsLZkDTxDe3VKxl1D0M5lsectUGGMzDf6eKaiyO1hzmdMZq8lw8Fy8W6S JIcbZg82QHPSwsm/1hH5M4W2jrCe7voFvPMGZ2E5HlQjNPYX1Es4FLWvHjGLapdpyu5c 4w3E+3WywqWk1CD6oWG7V+28A6ftAhtzjJOKRs1RsuZqg3nU3ZlVeNfpjdsgZkrIzfE5 woEQ== X-Gm-Message-State: APjAAAUnWEIkUG73dMyTSKyj1A/tOrYFcZyiJWW9p83lgv3vb7Io6UZK kW5Kemq+eRCWfDMoMzbE0Ow= X-Received: by 2002:a17:906:6a82:: with SMTP id p2mr5987790ejr.212.1553270227287; Fri, 22 Mar 2019 08:57:07 -0700 (PDT) Received: from archlinux-ryzen ([2a01:4f9:2a:1fae::2]) by smtp.gmail.com with ESMTPSA id w24sm2645564edb.72.2019.03.22.08.57.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 22 Mar 2019 08:57:06 -0700 (PDT) Date: Fri, 22 Mar 2019 08:57:04 -0700 From: Nathan Chancellor To: Arnd Bergmann Cc: Lee Jones , clang-built-linux@googlegroups.com, Nick Desaulniers , Charles Keepax , Linus Walleij , Sapthagiri Baratam , Colin Ian King , patches@opensource.cirrus.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mfd: arizona: fix undefined behavior Message-ID: <20190322155704.GC21978@archlinux-ryzen> References: <20190322143345.1208144-1-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190322143345.1208144-1-arnd@arndb.de> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 22, 2019 at 03:33:37PM +0100, Arnd Bergmann wrote: > When the driver is used with a subdevice that is disabled in the > kernel configuration, clang gets a little confused about the > control flow and fails to notice that n_subdevs is only > uninitialized when subdevs is NULL, and we check for that, > leading to a false-positive warning: > > drivers/mfd/arizona-core.c:1423:19: error: variable 'n_subdevs' is uninitialized when used here > [-Werror,-Wuninitialized] > subdevs, n_subdevs, NULL, 0, NULL); > ^~~~~~~~~ > drivers/mfd/arizona-core.c:999:15: note: initialize the variable 'n_subdevs' to silence this warning > int n_subdevs, ret, i; > ^ > = 0 > > Ideally, we would rearrange the code to avoid all those early > initializations and have an explicit exit in each disabled case, > but it's much easier to chicken out and add one more initialization > here to shut up the warning. > > Signed-off-by: Arnd Bergmann Took me a bit to follow the flow of this function. I agree that without restructuring it, zero initializing this variable to shut up the warning is the path of least resistance (clang must evaluate variables in isolation like I did until I fully read the commit message *facepalm*). Reviewed-by: Nathan Chancellor > --- > drivers/mfd/arizona-core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c > index 27b61639cdc7..0ca0fc9a67fd 100644 > --- a/drivers/mfd/arizona-core.c > +++ b/drivers/mfd/arizona-core.c > @@ -996,7 +996,7 @@ int arizona_dev_init(struct arizona *arizona) > unsigned int reg, val; > int (*apply_patch)(struct arizona *) = NULL; > const struct mfd_cell *subdevs = NULL; > - int n_subdevs, ret, i; > + int n_subdevs = 0, ret, i; > > dev_set_drvdata(arizona->dev, arizona); > mutex_init(&arizona->clk_lock); > -- > 2.20.0 >