From patchwork Tue Aug 14 15:49:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 177351 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 10BBC2C0192 for ; Wed, 15 Aug 2012 01:50:26 +1000 (EST) Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.inria.fr", Issuer "TERENA SSL CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A2BF62C009D for ; Wed, 15 Aug 2012 01:49:58 +1000 (EST) X-IronPort-AV: E=Sophos;i="4.77,766,1336341600"; d="scan'208";a="153065917" Received: from palace.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Aug 2012 17:49:52 +0200 From: Julia Lawall To: Benjamin Herrenschmidt Subject: [PATCH 5/5] arch/powerpc/platforms/powernv/pci.c: Remove potential NULL dereferences Date: Tue, 14 Aug 2012 17:49:48 +0200 Message-Id: <1344959388-19719-6-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1344959388-19719-1-git-send-email-Julia.Lawall@lip6.fr> References: <1344959388-19719-1-git-send-email-Julia.Lawall@lip6.fr> Cc: Paul Mackerras , kernel-janitors@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Julia Lawall If the NULL test is necessary, the initialization involving a dereference of the tested value should be moved after the NULL test. The sematic patch that fixes this problem is as follows: (http://coccinelle.lip6.fr/) // @@ type T; expression E; identifier i,fld; statement S; @@ - T i = E->fld; + T i; ... when != E when != i if (E == NULL) S + i = E->fld; // Signed-off-by: Julia Lawall --- arch/powerpc/platforms/powernv/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c index be3cfc5..928e97b 100644 --- a/arch/powerpc/platforms/powernv/pci.c +++ b/arch/powerpc/platforms/powernv/pci.c @@ -287,12 +287,13 @@ static int pnv_pci_read_config(struct pci_bus *bus, int where, int size, u32 *val) { struct pci_controller *hose = pci_bus_to_host(bus); - struct pnv_phb *phb = hose->private_data; + struct pnv_phb *phb; u32 bdfn = (((uint64_t)bus->number) << 8) | devfn; s64 rc; if (hose == NULL) return PCIBIOS_DEVICE_NOT_FOUND; + phb = hose->private_data; switch (size) { case 1: { @@ -331,11 +332,12 @@ static int pnv_pci_write_config(struct pci_bus *bus, int where, int size, u32 val) { struct pci_controller *hose = pci_bus_to_host(bus); - struct pnv_phb *phb = hose->private_data; + struct pnv_phb *phb; u32 bdfn = (((uint64_t)bus->number) << 8) | devfn; if (hose == NULL) return PCIBIOS_DEVICE_NOT_FOUND; + phb = hose->private_data; cfg_dbg("pnv_pci_write_config bus: %x devfn: %x +%x/%x -> %08x\n", bus->number, devfn, where, size, val);