Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3548409imc; Wed, 13 Mar 2019 22:57:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVjiIFb2ZTa1al+fFSaRDvBqtMxCuoTr7R2kR8vqyaoQuVmJy3mYWYrrVAKgJUuMTIaQQD X-Received: by 2002:a17:902:bd97:: with SMTP id q23mr48336666pls.94.1552543043717; Wed, 13 Mar 2019 22:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552543043; cv=none; d=google.com; s=arc-20160816; b=LRUzU93UMnwaXHkO+9cAAYjZpQ28yt6C0Sf6vSPF3ycXKrzDR9xQjPnX/e52gmc5Pp DNIFu5sxrRdg0LhIAj/k3czikBKfHZ58r1Kgt2/If6HnSACy6R8R7EuhTJ4N5+bNu8nq m35TY6eAxfjAYk9/I/kiTJ+ikH1g2nvKxv+S7CBPYTvJ6EeR8PjM/biiPhWNvlqchAmw yVpSCiYIA0hkFYMtp1uXncyMtICRJ/UQcCzdpSPjFB/n8+4F6ZTJiXJbnHI6LfKgNK76 VlI3U9zwog+RcKFj72CHKXDA8N4Ff4Neq1DdVtK2l0ys8zz+rk+0q1rAewUp1plkCXRQ pJRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Vj7JUBFBQJgDkJLGGi30nUL/l9PLQpcWCHPhW8ZQBEY=; b=LHD4l8yr0UM3K+XNr8+HtsgExkOcErfxu9u/0mfHxlB7RupXzxA9IL/rlAg8/21KdC pSwPuLKK5UEhyczXwDOgAo4KL6qb89NPyUSo5f40GKJw6xs9XNx/sIhd8C6hDnL8095K vO2Na8IPz9Ajbxp3jYS60+qZ5biiaOjY/s3j+enz2+Zgk8/a2Bj4hP8sOISYz/OhDUL1 xymn5+qFHDWyBtphT5mpkWI3GF6Q8HklgUf9fn1TzbI/XZWHxMa+I28FlyLRYb/64oLI SESPmyT6dYtSeS7jXbcqZTB1mcyCmbE5kRguLZjBBrTGqLjmP18gf8DBE7IM/fYK4fh0 UV6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b="d999WUb/"; 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=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si2746405pgj.217.2019.03.13.22.57.08; Wed, 13 Mar 2019 22:57:23 -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=@umn.edu header.s=google header.b="d999WUb/"; 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=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726805AbfCNF4R (ORCPT + 99 others); Thu, 14 Mar 2019 01:56:17 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:38148 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726582AbfCNF4Q (ORCPT ); Thu, 14 Mar 2019 01:56:16 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 01B58B2E for ; Thu, 14 Mar 2019 05:56:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HbE5nPCAkHKd for ; Thu, 14 Mar 2019 00:56:14 -0500 (CDT) Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id C2827B21 for ; Thu, 14 Mar 2019 00:56:14 -0500 (CDT) Received: by mail-it1-f200.google.com with SMTP id y6so1145077itj.5 for ; Wed, 13 Mar 2019 22:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=Vj7JUBFBQJgDkJLGGi30nUL/l9PLQpcWCHPhW8ZQBEY=; b=d999WUb/V0XB5zh5a3Np2+6r7LculZvCpvxiJY/tbfY+Eba4LUZQfwMUBWhQeBZ+Ij wRpS+cLHZLbqD+Fgk+WGgRf4rbKbi/aA2jjLJirgpjHCq4zC335tJgEoCf44IPyK9Kcy JmYtvgKxhcd4JtTTy+VJ0logWXDQnuFMgBywFL0H3IOvA87m19eLa+OfKTbmfnOnmoS3 SkW339vWxhH5Qg4gWj8wliqu+D9wb0MGtFxGryjBDu+JzHfMniRjd39HTXsEhVngMI8Y NxS2lEteOJLXngoQk3o0aI1neAjsi2j3MKZD+2LMxxnuAOwa5+MQQPpy2Eh8EQw5OPSg 5mDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Vj7JUBFBQJgDkJLGGi30nUL/l9PLQpcWCHPhW8ZQBEY=; b=Lxq8r48LW4pGsoBDRCIxB3yI1M2X1khmCBDmojjunm3U9CsLLzmGrDq5TrFP+S0UHu Cdxd1sLk57TggxiNA5ms8rko9QtJnibzalxjYYX72V/dPbIVJGugXeVqQbWPnUZP5vi6 AbNfOxxenOjglGujQVRMSTe9qBbVQ+rvQrbk9a+JHWfFbBkAsaLeGCtf68wp9OYh4Xns 0sAwNMGWT9gmLgAFlwhXDPqiGX0i+peMipsD3UIeLl5R4TwWJ9zy393WKRzOXKo7Swaw OmtGa7BxNeTI9sdBwDttLAEPvQ3CQPFdtdG7do0xha5Ir9gCbY5QhDxANus1XjZEG8lQ VuGA== X-Gm-Message-State: APjAAAWALC7E6Zcc0WzlUknnuPrMWbix3vUrz273a/zVn1b9c02REf0Y ZU6JO4stXT3tG5kO5LeoRHWpQEsYIpGTWYh6o0CPCww9HOZuKDacU4WvQtStHaGCTdGOqgnQSK6 fYYXS7plPEuODUWbJA6PexAi5cqT4 X-Received: by 2002:a24:628a:: with SMTP id d132mr1039443itc.164.1552542974437; Wed, 13 Mar 2019 22:56:14 -0700 (PDT) X-Received: by 2002:a24:628a:: with SMTP id d132mr1039433itc.164.1552542974229; Wed, 13 Mar 2019 22:56:14 -0700 (PDT) Received: from bee.dtc.umn.edu (cs-bee-u.cs.umn.edu. [128.101.106.63]) by smtp.gmail.com with ESMTPSA id s142sm645936itb.37.2019.03.13.22.56.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 22:56:13 -0700 (PDT) From: Kangjie Lu To: kjlu@umn.edu Cc: pakki001@umn.edu, Simon Horman , Lorenzo Pieralisi , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pci: pcie-rcar: fix a potential NULL pointer dereference Date: Thu, 14 Mar 2019 00:56:08 -0500 Message-Id: <20190314055608.5209-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case __get_free_pages fails and returns NULL, the fix returns -ENOMEM and releases resources to avoid NULL pointer dereference. Signed-off-by: Kangjie Lu --- drivers/pci/controller/pcie-rcar.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c index c8febb009454..0ba26c31d928 100644 --- a/drivers/pci/controller/pcie-rcar.c +++ b/drivers/pci/controller/pcie-rcar.c @@ -929,6 +929,12 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) /* setup MSI data target */ msi->pages = __get_free_pages(GFP_KERNEL, 0); + if (!msi->pages) { + dev_err(dev, "failed to get free pages\n"); + err = -ENOMEM; + goto err; + } + base = virt_to_phys((void *)msi->pages); rcar_pci_write_reg(pcie, base | MSIFE, PCIEMSIALR); -- 2.17.1