Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp989446imm; Wed, 25 Jul 2018 09:31:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc7+Ce53r7Mm/jAOrSZEo/CuPj0YQjdnNbc0cg/laRAw6bEcx535CY5/60XNBs6WPcI9TaY X-Received: by 2002:a17:902:20e3:: with SMTP id v32-v6mr13125826plg.232.1532536287929; Wed, 25 Jul 2018 09:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532536287; cv=none; d=google.com; s=arc-20160816; b=XBb9Fl5ac8CEMVJGpC3pspk8NrOM8790LlFY/jFpwsAwg6rQy1gf1deZrekSHIwwJ3 +iqD92dSlWcTJfPWjraLNpEMLAhrckEQswDuV9IgCQhQ5qlzCxiPJz4xeoJcleeJq2d0 hADzHXA8mTWVrCgiPY6Jg2aDOeXLzyljOhhWvRubv6SD4OPsWKM/LmbHaOafOmqfrYEb fbc/y4kBBEbVVQgkN5cdyTERccvmj4rB4QncwkFidsBfI3yfnb1eZqNmzO519GaKKyXf r5EHcuo3HOuJrjLuX6wdTE1HxUW3cbc7N1fr9b2yibVN0y6icN9DkXbWEVUbz/2hD3PL T+ZA== 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=rcVpchUiRj+UfiDXh62PfHoKn/tXsATnHdSpqK0P0iE=; b=RHB7y7U0GqZOwzoYjcsZh7F22H5JtimlGilrcOT3Z1ubTrl4uFOKlEISErQEKEY2aR irtuZR02KfmqnIQU/E0zKRHESgcLT48JYcfPrTDvlI1C1k/hivmSe/7uIe+BjNyto10X 1BDefwp4vdU8fyL/yBZW89yLi9uBvIQwv4umZGIxOqcJntrMwlaIFamCh5NEmjRHBu9o n1SFgVJ+RclofH2Qztvtj6gFYBRbR4Fj85PDnC8CnCLSlstF4SgvQlCPitrEXF55hpqi RUyX2zPwf/ubMB9h5X5PMaeFtlSJyhxA6VjORz5w0fFslcUh46tu2IU4n4a3csYpw2Yh NmqQ== 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 l14-v6si14069680pgk.562.2018.07.25.09.31.12; Wed, 25 Jul 2018 09:31:27 -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 S1729435AbeGYRm2 (ORCPT + 99 others); Wed, 25 Jul 2018 13:42:28 -0400 Received: from sender-pp-092.zoho.com ([135.84.80.237]:25309 "EHLO sender-pp-092.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728663AbeGYRm1 (ORCPT ); Wed, 25 Jul 2018 13:42:27 -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=PvBVzqOaFRyx0/aCaj6my9vH64ieet5+AuTx3Nhl5oldcUtOI1PaGHr3ZCkLLB0BMtpbck6AX0D2 rMJQTfHnmfyoBDuY+Sqppn4m3SomFbn8xqfTbv7ZlclvafRzhdd5 Received: from YEHS1XR956R00D1.lenovo.com (114.245.13.10 [114.245.13.10]) by mx.zohomail.com with SMTPS id 1532536177219161.6186001027811; Wed, 25 Jul 2018 09:29:37 -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 3/6] tools/testing/nvdimm: kaddr and pfn can be NULL to ->direct_access() Date: Thu, 26 Jul 2018 00:28:46 +0800 Message-Id: <20180725162849.8320-4-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 The mock / test version of 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 local pointer or variable that they then just throw away. Suggested-by: Dan Williams Signed-off-by: Huaisheng Ye --- tools/testing/nvdimm/pmem-dax.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/nvdimm/pmem-dax.c b/tools/testing/nvdimm/pmem-dax.c index b53596a..2e7fd82 100644 --- a/tools/testing/nvdimm/pmem-dax.c +++ b/tools/testing/nvdimm/pmem-dax.c @@ -31,17 +31,21 @@ long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, if (get_nfit_res(pmem->phys_addr + offset)) { struct page *page; - *kaddr = pmem->virt_addr + offset; + if (kaddr) + *kaddr = pmem->virt_addr + offset; page = vmalloc_to_page(pmem->virt_addr + offset); - *pfn = page_to_pfn_t(page); + if (pfn) + *pfn = page_to_pfn_t(page); pr_debug_ratelimited("%s: pmem: %p pgoff: %#lx pfn: %#lx\n", __func__, pmem, pgoff, page_to_pfn(page)); return 1; } - *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