From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7E9122CE7E; Wed, 4 Dec 2024 17:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733331833; cv=none; b=XVTKo+X4BLDstnVHZgEoTi0isdI8RfMN75DKbH2UaJy8pHkZ2cabWHeh5iV15Rp/sQ0LNC+98JG1k2vfyoYo89xViUIoxlVY7BP+2Dh4jvNcn8D7tXfyi32/p31VYpFN+7F161Wz3OX7TvxR+Tj8U77jLeT4Xa7twRFCdeYiixg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733331833; c=relaxed/simple; bh=Dl2/6Zolvx6cRik8JD2wBSapqvoRLP8984A+EP7cDuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tNo9QmVEZvCriUkrWf+uM2Y8bz8UM9VgtwBhcXhXPEzFfltvVpvAXbk7dlxgaFaC1GD5byckBdiN4oQ1twii0LkiZeukBUe26Q/qFgMdCmtNSES93571iB8J4JYNPvY51NJmY3ugZYRRKKweXMaRfwZd8qE1jnCrzirSJ/EVabM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fOdFOy0j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fOdFOy0j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AFC4C4CECD; Wed, 4 Dec 2024 17:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733331833; bh=Dl2/6Zolvx6cRik8JD2wBSapqvoRLP8984A+EP7cDuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fOdFOy0jCRyvfgQCVlKLOOJ4HH17Bl8aqdSXchuqB1YIRTJ7gQ7O11nIEl7z5whjx Wmc03Ck0IqbF4bazEIRO73/G9fM8Raz5qfduliIozgVRijB/UctEp8FHcMlrslp8MS M5RDyJ0onnsjJrvV56iItRRYqpDvbdxjtr43fDoAVxdDXeJcl1mDoAaqso2gISA53X 6LqT1gNTB3K+wkP75TOGoEf+sYCDjoB/oB+qApIpjkKDBr7Mm0w7orvZ2r10Or/Ti0 Zq7Pv/32VqtR4Snax6vuYqGkdF0/Gq33z1F/W8tRBISLW89apM3pM6UT5eZRIBjVNX 6FxlS1iIl0klA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yi Yang , Dave Jiang , Ira Weiny , Sasha Levin , dan.j.williams@intel.com, vishal.l.verma@intel.com, nvdimm@lists.linux.dev Subject: [PATCH AUTOSEL 4.19 6/6] nvdimm: rectify the illogical code within nd_dax_probe() Date: Wed, 4 Dec 2024 10:52:25 -0500 Message-ID: <20241204155226.2215336-6-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204155226.2215336-1-sashal@kernel.org> References: <20241204155226.2215336-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.324 Content-Transfer-Encoding: 8bit From: Yi Yang [ Upstream commit b61352101470f8b68c98af674e187cfaa7c43504 ] When nd_dax is NULL, nd_pfn is consequently NULL as well. Nevertheless, it is inadvisable to perform pointer arithmetic or address-taking on a NULL pointer. Introduce the nd_dax_devinit() function to enhance the code's logic and improve its readability. Signed-off-by: Yi Yang Reviewed-by: Dave Jiang Link: https://patch.msgid.link/20241108085526.527957-1-yiyang13@huawei.com Signed-off-by: Ira Weiny Signed-off-by: Sasha Levin --- drivers/nvdimm/dax_devs.c | 4 ++-- drivers/nvdimm/nd.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c index 326f02ffca81f..5fcc9ddb795f5 100644 --- a/drivers/nvdimm/dax_devs.c +++ b/drivers/nvdimm/dax_devs.c @@ -121,12 +121,12 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) nvdimm_bus_lock(&ndns->dev); nd_dax = nd_dax_alloc(nd_region); - nd_pfn = &nd_dax->nd_pfn; - dax_dev = nd_pfn_devinit(nd_pfn, ndns); + dax_dev = nd_dax_devinit(nd_dax, ndns); nvdimm_bus_unlock(&ndns->dev); if (!dax_dev) return -ENOMEM; pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL); + nd_pfn = &nd_dax->nd_pfn; nd_pfn->pfn_sb = pfn_sb; rc = nd_pfn_validate(nd_pfn, DAX_SIG); dev_dbg(dev, "dax: %s\n", rc == 0 ? dev_name(dax_dev) : ""); diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 01e194a5824e4..c611bbc0f20fe 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -326,6 +326,13 @@ struct nd_dax *to_nd_dax(struct device *dev); int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns); bool is_nd_dax(struct device *dev); struct device *nd_dax_create(struct nd_region *nd_region); +static inline struct device *nd_dax_devinit(struct nd_dax *nd_dax, + struct nd_namespace_common *ndns) +{ + if (!nd_dax) + return NULL; + return nd_pfn_devinit(&nd_dax->nd_pfn, ndns); +} #else static inline int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) -- 2.43.0