nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: oceanhe@zoho.com.cn
To: dan.j.williams@intel.com, zwisler@kernel.org,
	vishal.l.verma@intel.com, dave.jiang@intel.com
Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org,
	Ocean He <hehy1@lenovo.com>
Subject: [PATCH] libnvdimm, bus: check if type of nd_device_driver within valid scope
Date: Tue, 31 Jul 2018 08:02:32 -0400	[thread overview]
Message-ID: <1533038552-6195-1-git-send-email-oceanhe@zoho.com.cn> (raw)

From: Ocean He <hehy1@lenovo.com>

According to enum nd_driver_flags, the valid type of nd_device_driver
start from 0x02 and end up with 0x80. Both 0x00 and 0x01 are invalid, and
the value larger than 0x80 is invalid.

To filter valid type, ND_DRIVER_FLAGS_MASK is defined as
(((ND_DRIVER_FLAGS_MAX) << 1) - 2). For example, when ND_DRIVER_FLAGS_MAX
equals to ND_DRIVER_DAX_PMEM(0x80), then ND_DRIVER_FLAGS_MASK equals
to 0xFE.

Signed-off-by: Ocean He <hehy1@lenovo.com>
---
 drivers/nvdimm/bus.c       | 2 +-
 include/uapi/linux/ndctl.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 27902a8..ec8cf4b 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -546,7 +546,7 @@ int __nd_driver_register(struct nd_device_driver *nd_drv, struct module *owner,
 {
 	struct device_driver *drv = &nd_drv->drv;
 
-	if (!nd_drv->type) {
+	if (!(nd_drv->type & ND_DRIVER_FLAGS_MASK)) {
 		pr_debug("driver type bitmask not set (%pf)\n",
 				__builtin_return_address(0));
 		return -EINVAL;
diff --git a/include/uapi/linux/ndctl.h b/include/uapi/linux/ndctl.h
index 7e27070..2a1ce06 100644
--- a/include/uapi/linux/ndctl.h
+++ b/include/uapi/linux/ndctl.h
@@ -207,6 +207,8 @@ enum nd_driver_flags {
 	ND_DRIVER_NAMESPACE_BLK   = 1 << ND_DEVICE_NAMESPACE_BLK,
 	ND_DRIVER_DAX_PMEM	  = 1 << ND_DEVICE_DAX_PMEM,
 };
+#define ND_DRIVER_FLAGS_MAX	ND_DRIVER_DAX_PMEM
+#define ND_DRIVER_FLAGS_MASK	(((ND_DRIVER_FLAGS_MAX) << 1) - 2)
 
 enum {
 	ND_MIN_NAMESPACE_SIZE = PAGE_SIZE,
-- 
1.8.3.1

                 reply	other threads:[~2018-07-31 12:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1533038552-6195-1-git-send-email-oceanhe@zoho.com.cn \
    --to=oceanhe@zoho.com.cn \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=hehy1@lenovo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    --cc=zwisler@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).