From patchwork Thu Jun 23 19:59:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Moyer X-Patchwork-Id: 9195925 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 9E3B06075A for ; Thu, 23 Jun 2016 19:59:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DB9A28472 for ; Thu, 23 Jun 2016 19:59:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82AAD28474; Thu, 23 Jun 2016 19:59:56 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 54E8328472 for ; Thu, 23 Jun 2016 19:59:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2C5651A1E1D; Thu, 23 Jun 2016 13:00:26 -0700 (PDT) X-Original-To: linux-nvdimm@ml01.01.org Delivered-To: linux-nvdimm@ml01.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EBDCD1A1E12 for ; Thu, 23 Jun 2016 13:00:24 -0700 (PDT) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06D1B811A2; Thu, 23 Jun 2016 19:59:53 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5NJxqV1024123; Thu, 23 Jun 2016 15:59:52 -0400 Received: by segfault.boston.devel.redhat.com (Postfix, from userid 3734) id 3D4CB303FD654; Thu, 23 Jun 2016 15:59:52 -0400 (EDT) From: Jeff Moyer To: dan.j.williams@intel.com Subject: [PATCH 2/3] daxctl_region_unref: fix a potential null pointer dereference Date: Thu, 23 Jun 2016 15:59:49 -0400 Message-Id: <20160623195950.30968-3-jmoyer@redhat.com> In-Reply-To: <20160623195950.30968-1-jmoyer@redhat.com> References: <20160623195950.30968-1-jmoyer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 23 Jun 2016 19:59:53 +0000 (UTC) X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@ml01.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Move the assignment of ctx to after the NULL check. Signed-off-by: Jeff Moyer --- daxctl/lib/libdaxctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index a8ad58d..9d71a29 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -181,7 +181,7 @@ static void free_dev(struct daxctl_dev *dev, struct list_head *head) DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region) { - struct daxctl_ctx *ctx = region->ctx; + struct daxctl_ctx *ctx; struct daxctl_dev *dev, *_d; if (!region) @@ -190,6 +190,7 @@ DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region) if (region->refcount) return; + ctx = region->ctx; info(ctx, "region%d released\n", region->id); list_for_each_safe(®ion->devices, dev, _d, list) free_dev(dev, ®ion->devices);