Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4667520ybi; Mon, 3 Jun 2019 15:09:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvA4+UjVIhL1AmJ0ypT1+3Po9IBFialVYQkWZ28YxXkd2BxoSYMqN7ZBeKW6PV3qloqRgP X-Received: by 2002:a63:f957:: with SMTP id q23mr31812784pgk.326.1559599772980; Mon, 03 Jun 2019 15:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559599772; cv=none; d=google.com; s=arc-20160816; b=ORlHPGDArbpsuIW39We03l91YdoYUFI7MRA6H11SfYPQjr51OeaF5q9DFYyqVi6nIn Ux2tCDKCgfFmTrjf9JKO2sFCwrVlDzFBc120r+1WpyNlYYYRnTZXkOrt43j+FwcSq3SD LrMDElbM+2emegc8A2xS8xO72k12yExBvfkEw21qjBvEpcE0D4hugjrTK6SjwVOtXqyQ 7lOQDCfp06flu5TlBs1exniseBILQM3BXdNFWFZ+k3X0QCaZPfB3NlNLYbezydRASrWM 0wKbDhLUv3/AAGpjHQCHv6i9TpLz27gYvVaIimbgYPBmXIpbZhygGd6nxX2Tl4tqtne4 pKGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jsqt76+/tC7lNIGkBOfSxOR0w7kTsY9VRuEizjLylaM=; b=IGMY88IdgogAZJsaZsZaOx3znzqZukF73uF98vBnUemN3aTR2/m5ziPLKxmM/S1ktf 935x+hsBigsIWKSBgPiRi4Kc13EY/8o91b76hsg1Bztdn7ppYR4aTH937QD8tn/JRTPt 2Rk+RuXRv1NDqcweQ6rPvfFH6uhCp8tFS4Sd1qG8jv4Nc6u2kAlI2Rdd/NJUJcak+QW2 dHNrQPEDUth5vUpaJU24ADqlOvGiJ0XjUaJsrPbSXXaKPjlETresenROXwyg5fYUGsy4 a3pHaRwj4pZ1EdCDUYEFV6ankqd71rG58E44FM4dupAhhlxUegOWqQsBFIYv0AHV4YDo E6XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lWohiKBq; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si12582382pff.173.2019.06.03.15.09.17; Mon, 03 Jun 2019 15:09:32 -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=@google.com header.s=20161025 header.b=lWohiKBq; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfFCWH5 (ORCPT + 99 others); Mon, 3 Jun 2019 18:07:57 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36434 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbfFCWH4 (ORCPT ); Mon, 3 Jun 2019 18:07:56 -0400 Received: by mail-pf1-f193.google.com with SMTP id u22so11389069pfm.3 for ; Mon, 03 Jun 2019 15:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jsqt76+/tC7lNIGkBOfSxOR0w7kTsY9VRuEizjLylaM=; b=lWohiKBqCPBenj/eJUzVHOJpCdAi91g5TtT2pyrV0FfesO2LcED3e8srNOon8Iibg8 XtIVB4yvu8opanO7FhZdkXkw4qrcWHepKTZehjxMhdJDV96SRObFjXSOJ7rGU53BIOCP amFtVM8IVZTgsTynPUL6wWPlqXYRwRZZzxCbIY9Ee0e3Vl33p4qUyAVxj8FpxZ60liZ+ tlqBRl6mtiIkFKWFCab1uDZBalnO4+vn2OxS13m7xXU6v0FU5TV28RkCj9ovOInxVDww AAHmWcMNk0lFA89DRsCsZY4WJwkQ6CMV6qh3KnKzsG3YvEUYZUc8GLtbMBr5SeewywTj cL0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jsqt76+/tC7lNIGkBOfSxOR0w7kTsY9VRuEizjLylaM=; b=YHpf2yXBvY2JksGVu3nbOm6GQrpdPGLOuUueWFofy85vSusR7wsvYh8u/putOnxakU EChJAYWminft4osUOcDWoImGeb3Zg6kTTeqPxKnxrXHFEH7AKHFr5Po2/UIahSbXVlPo 9HSV2ssoaiBExGAUCJAeWBNSu+8JVKHNnQmGMlTrL4fU/OBDXH5ejeWanWvbmds9xbSP d3KSz2/DcAg4jUtMBqpMK8OXWltEJeK38h2v0tsElfngI/vnMeLi7fOnMDIuU7/Qt4l4 0/fj/b4JyzQHSfLN6s1W6M/ZmQDflPTmaztkAI4vZK2gl1NRcjFRgOfKjVcsKdstrMTS Es5Q== X-Gm-Message-State: APjAAAUGgK39spSddVRo1Ijh9bYe/ZGex4eCgPHBSuh2hnR/WdH7AwTF YhJ+Rocu+YJAh4h7AsDeBmXF1Za2/eXajjIoBpDiMw== X-Received: by 2002:a17:90a:bf02:: with SMTP id c2mr5763850pjs.73.1559596083400; Mon, 03 Jun 2019 14:08:03 -0700 (PDT) MIME-Version: 1.0 References: <20190603174323.48251-1-natechancellor@gmail.com> In-Reply-To: <20190603174323.48251-1-natechancellor@gmail.com> From: Nick Desaulniers Date: Mon, 3 Jun 2019 14:07:50 -0700 Message-ID: Subject: Re: [PATCH] PCI: rpaphp: Avoid a sometimes-uninitialized warning To: Nathan Chancellor Cc: Tyrel Datwyler , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Bjorn Helgaas , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 3, 2019 at 10:44 AM Nathan Chancellor wrote: > Looking at the loop in a vacuum as clang would, fndit could be > uninitialized if entries was ever zero or the if statement was > always true within the loop. Regardless of whether or not this > warning is a problem in practice, "found" variables should always > be initialized to false so that there is no possibility of > undefined behavior. Thanks for the patch Nathan. fndit isn't really being used for anything other than a print statement outside of the loop. How about: ``` diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index bcd5d357ca23..c3899ee1db99 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -230,7 +230,7 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name, struct of_drc_info drc; const __be32 *value; char cell_drc_name[MAX_DRC_NAME_LEN]; - int j, fndit; + int j; info = of_find_property(dn->parent, "ibm,drc-info", NULL); if (info == NULL) @@ -245,17 +245,13 @@ static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name, /* Should now know end of current entry */ - if (my_index > drc.last_drc_index) - continue; - - fndit = 1; - break; + /* Found it */ + if (my_index <= drc.last_drc_index) { + sprintf(cell_drc_name, "%s%d", drc.drc_name_prefix, + my_index); + break; + } } - /* Found it */ - - if (fndit) - sprintf(cell_drc_name, "%s%d", drc.drc_name_prefix, - my_index); if (((drc_name == NULL) || (drc_name && !strcmp(drc_name, cell_drc_name))) && ``` (not sure my tabs were pasted properly in the above...) -- Thanks, ~Nick Desaulniers