From patchwork Thu Aug 2 08:19:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ocean He X-Patchwork-Id: 10553355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2CCA13B4 for ; Thu, 2 Aug 2018 08:19:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B20B92B7CA for ; Thu, 2 Aug 2018 08:19:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4C432B7D7; Thu, 2 Aug 2018 08:19:47 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 598402B7CA for ; Thu, 2 Aug 2018 08:19:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 022F1210D6CE5; Thu, 2 Aug 2018 01:19:47 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400d:c0d::242; helo=mail-qt0-x242.google.com; envelope-from=oceanhehy@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C1B6C210C2D81 for ; Thu, 2 Aug 2018 01:19:45 -0700 (PDT) Received: by mail-qt0-x242.google.com with SMTP id m13-v6so1403382qth.1 for ; Thu, 02 Aug 2018 01:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=iSHmmsrP2UzF9IriGZ+wHxpwzZjGFujQLxtf7uuAt8Y=; b=q+E6o4tp6TEA8kghz4/Ry4GwC+DH+9+xvbP94P9xJM0PSzePCLRMqcvUDrwkgqMros 1xU9mWt2x8sc6tXz+xIU0hxUcjwhcJi6tjOApSu0zsHKYmC6JZi7xQaBGGNv9QyOiMrq fICJoqcQXrICaNrfIGOtbyZCoaOIL5O7o82Iuhns83TIH+5vwpLCo9nG5t3kcs3vNG4E x85NkM3Yh2SyPoCICX8Z8Q6RHiRkGi4KXVgqIhmYxVPMnNMkqPVebMMhHqvQrA0LA6g5 JkUxXGgovb4UjtKhIN31JZ/en1oDpTocCv5eOxtJGz9eyM1dl2Tzh43qqIA2E6v8pERy howw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iSHmmsrP2UzF9IriGZ+wHxpwzZjGFujQLxtf7uuAt8Y=; b=HddxuhWd9O3gKoesM9gJfnW7PtBLIMsEYmaGft9la9w2RoEX1/QOOHH8QCuaiIiyHv VshvM36zZ6BJY54L6D4GaZ4JdMpxsC1Nnx/yvI/TegB8gBiosZPwlVhedU3+uLYllV3Q AKnh2AdR4qDxVkRLrvacMKB4z7fKsTewzReoN9jA/DkS+FkcXSFKur22CxamQ0UE6Gl5 1oTeu4zFmcbCIwmXKcyUueTD+MHkgny+7Bhdm6aADTHF8mop4Digm3WBGod01cv4N8qd h3QeQ94B4B2I0jhc+E7Y/Eo4ROq5OwJxyK9mZJhaWstHH11pJZxxjqwBD20xl73HEXIG MLtA== X-Gm-Message-State: AOUpUlEK/+9dkJ+PbA8P7TKFnWgEg/WPMb801SXB7rR7Q/bKn3/PwCwy GGT3BaLA8aVDLmpeoagC1Mg= X-Google-Smtp-Source: AAOMgpdWm9YSeewMck1zipN7SJQ7ibfm+W+GSSwfbnvvUlyE6YqKYvJuF+6qUrWKcXNnbV+08/mBig== X-Received: by 2002:ac8:1a46:: with SMTP id q6-v6mr1637498qtk.5.1533197984770; Thu, 02 Aug 2018 01:19:44 -0700 (PDT) Received: from localhost.localdomain ([104.237.86.58]) by smtp.gmail.com with ESMTPSA id c93-v6sm1441078qkh.90.2018.08.02.01.19.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 01:19:44 -0700 (PDT) From: oceanhehy@gmail.com To: dan.j.williams@intel.com, zwisler@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com Subject: [PATCH v2] libnvdimm, bus: check if type of nd_device_driver within valid scope Date: Thu, 2 Aug 2018 04:19:36 -0400 Message-Id: <1533197976-27391-1-git-send-email-oceanhehy@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ocean He , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Ocean He 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 --- v1: https://www.spinics.net/lists/kernel/msg2869760.html v2: Sorry for noise. I got an email problem, so I have to resend to loop linux-nvdimm@lists.01.org. 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,