From patchwork Wed Aug 23 16:03:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 9917713 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D99F860327 for ; Wed, 23 Aug 2017 16:03:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB17A289BF for ; Wed, 23 Aug 2017 16:03:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFF09289D1; Wed, 23 Aug 2017 16:03:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E2AC289BF for ; Wed, 23 Aug 2017 16:03:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932120AbdHWQDF (ORCPT ); Wed, 23 Aug 2017 12:03:05 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53523 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932118AbdHWQDF (ORCPT ); Wed, 23 Aug 2017 12:03:05 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1dkY7T-0002IP-Gw; Wed, 23 Aug 2017 16:03:03 +0000 From: Colin King To: Kishon Vijay Abraham I , Bjorn Helgaas , linux-pci@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][pci-next] PCI: endpoint: fix incorrect end of table check in while loop Date: Wed, 23 Aug 2017 17:03:03 +0100 Message-Id: <20170823160303.23366-1-colin.king@canonical.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King Currently, the while loop will iterate until a matching name is found or until the id pointer wraps around to NULL (the latter is incorrect). The end of a pci_epf_device_id table is terminated with zero'd entries for name and driver_data, so can change the while loop to iterate while the first character in the name is a non-zero character. Detected by CoverityScan, CID#1454557 ("Logically dead code") Fixes: 9e9d6eb48623 ("PCI: endpoint: Add an API to get matching "pci_epf_device_id") Signed-off-by: Colin Ian King Acked-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epf-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index ae6fac5995e3..70eccc04ee7f 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -273,7 +273,7 @@ pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf) if (!id || !epf) return NULL; - while (id) { + while (*id->name) { if (strcmp(epf->name, id->name) == 0) return id; id++;