Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp990581imm; Wed, 25 Jul 2018 09:32:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdi5+nON7nt94Mc+Mp4qAU8X6SzW1PpW1s6FoAddjbjTH91p2OhF4h/UqARo5aZJSvuC1h4 X-Received: by 2002:a62:843:: with SMTP id c64-v6mr22952873pfd.14.1532536351102; Wed, 25 Jul 2018 09:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532536351; cv=none; d=google.com; s=arc-20160816; b=SK6Erwt3wqrJkEMvIt/wDk/Hr46GzrOP4ihtmhCY2LPKPvGDNthYIQvguAwZ3b/rzC dsG7MCUcNIOVQDKIceUjV3ng2Gh1DnXUy7FM6JdVjWMWiCz6AuI9FSefhwzPGNzXpL1b FdsvpUPJkZuAjvLFFYWgCcvz+Vrsu7NeoXw+wctgd/X4/lhaM3id1IrUYOjn81a0zc0z YgiNaGvvrCHNSjd+VWK13/z3Qm6gxiA5O5LUIxgWyyrqHtFTNXxaaHUwKGzJwAoM8gu6 0/BSi2Myc21dSGcrwISrr4tyGXbwJmQV8ZYjq+3hNlEzZWHr8J26SibgleE6oss4oSIL fWAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:domainkey-signature:arc-authentication-results; bh=mF2fO/+ElmOSSXJd/DCFKTn5TA47aQojtaPdSICCPQY=; b=q3KOvbo/R7d21uMG6uDreiaJJnxEgSWIa3zEyhORn+e4T6TcQEl9l4XznYVdCm+OHs dXru0j4AwBcs4go2X05yNMB+RVRlNWACC6PNM5LM3RyKqGRQ16ao1+/AqpmTXp8QSvOg flYFCqM0LlTlV4ogurk9qb6tnAAzzOWdGTnaQaX1WqjBnDFAkl9k77doAmioAgEeCWDW eSYhq5qm0cADjVX9fzJe3LGTmBDXgjR/pf/N4+uH8dhVPfMRvRr8MUGnI0ii2aOuI3K8 6QUt+ZpQYIEnLVTfcyyn7Hgp09mxvBur0eiS5pl0MS/Telwrxf/GubkG3fz/RBXXE3v9 bffg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14-v6si12223937pgj.413.2018.07.25.09.32.16; Wed, 25 Jul 2018 09:32:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729247AbeGYRmH (ORCPT + 99 others); Wed, 25 Jul 2018 13:42:07 -0400 Received: from sender-pp-092.zoho.com ([135.84.80.237]:25483 "EHLO sender-pp-092.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728542AbeGYRmG (ORCPT ); Wed, 25 Jul 2018 13:42:06 -0400 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=from:to:cc:subject:date:message-id:in-reply-to:references; b=Yyc1MuJFSQQWt6la8ragJmwNjL65oV2ifK/PKGYVGwcZs96g2junpXCZOE5Tx9edw19WysAX1N36 fasZv03Pv3/ZAMCC+VW7UeRyWGgQi6XYG9tBKq5mjLI3/bVtWQX7 Received: from YEHS1XR956R00D1.lenovo.com (114.245.13.10 [114.245.13.10]) by mx.zohomail.com with SMTPS id 153253615674099.54070859484; Wed, 25 Jul 2018 09:29:16 -0700 (PDT) From: Huaisheng Ye To: linux-nvdimm@lists.01.org, dan.j.williams@intel.com Cc: ross.zwisler@linux.intel.com, willy@infradead.org, vishal.l.verma@intel.com, dave.jiang@intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, viro@zeniv.linux.org.uk, martin.petersen@oracle.com, axboe@kernel.dk, gregkh@linuxfoundation.org, bart.vanassche@wdc.com, jack@suse.cz, agk@redhat.com, snitzer@redhat.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, chengnt@lenovo.com, colyli@suse.de, Huaisheng Ye Subject: [PATCH v2 1/6] libnvdimm, pmem: kaddr and pfn can be NULL to ->direct_access() Date: Thu, 26 Jul 2018 00:28:44 +0800 Message-Id: <20180725162849.8320-2-yehs2007@zoho.com> X-Mailer: git-send-email 2.17.0.windows.1 In-Reply-To: <20180725162849.8320-1-yehs2007@zoho.com> References: <20180725162849.8320-1-yehs2007@zoho.com> X-ZohoMailClient: External Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huaisheng Ye pmem_direct_access() needs to check the validity of pointers kaddr and pfn for NULL assignment. If anyone equals to NULL, it doesn't need to calculate the value. If pointer equals to NULL, that is to say callers may have no need for kaddr or pfn, so this patch is prepared for allowing them to pass in NULL instead of having to pass in a pointer or local variable that they then just throw away. Signed-off-by: Huaisheng Ye --- drivers/nvdimm/pmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 8b1fd7f..ecf9024 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -227,8 +227,11 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, if (unlikely(is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, PFN_PHYS(nr_pages)))) return -EIO; - *kaddr = pmem->virt_addr + offset; - *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); + + if (kaddr) + *kaddr = pmem->virt_addr + offset; + if (pfn) + *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); /* * If badblocks are present, limit known good range to the -- 1.8.3.1