All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: Dan Williams <dan.j.williams@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>
Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 1/3] device-dax: Prevent registering drivers without probe or remove callback
Date: Thu, 28 Jan 2021 00:01:22 +0100	[thread overview]
Message-ID: <20210127230124.109522-1-uwe@kleine-koenig.org> (raw)

The bus probe and remove functions (dax_bus_probe and dax_bus_remove
respectively) call these functions without checking them to be non-NULL.
Add a check to prevent a NULL pointer exception.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 drivers/dax/bus.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index 737b207c9e30..618d462975ba 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -1392,6 +1392,14 @@ int __dax_driver_register(struct dax_device_driver *dax_drv,
 	struct device_driver *drv = &dax_drv->drv;
 	int rc = 0;
 
+	/*
+	 * dax_bus_probe() calls dax_drv->probe() unconditionally and
+	 * dax_bus_remove() calls dax_drv->remove() unconditionally. So better
+	 * be safe than sorry and ensure these are provided.
+	 */
+	if (!dax_drv->probe || !dax_drv->remove)
+		return -EINVAL;
+
 	INIT_LIST_HEAD(&dax_drv->ids);
 	drv->owner = module;
 	drv->name = mod_name;

base-commit: 5c8fe583cce542aa0b84adc939ce85293de36e5e
-- 
2.29.2
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: Dan Williams <dan.j.williams@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>
Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 1/3] device-dax: Prevent registering drivers without probe or remove callback
Date: Thu, 28 Jan 2021 00:01:22 +0100	[thread overview]
Message-ID: <20210127230124.109522-1-uwe@kleine-koenig.org> (raw)

The bus probe and remove functions (dax_bus_probe and dax_bus_remove
respectively) call these functions without checking them to be non-NULL.
Add a check to prevent a NULL pointer exception.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 drivers/dax/bus.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index 737b207c9e30..618d462975ba 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -1392,6 +1392,14 @@ int __dax_driver_register(struct dax_device_driver *dax_drv,
 	struct device_driver *drv = &dax_drv->drv;
 	int rc = 0;
 
+	/*
+	 * dax_bus_probe() calls dax_drv->probe() unconditionally and
+	 * dax_bus_remove() calls dax_drv->remove() unconditionally. So better
+	 * be safe than sorry and ensure these are provided.
+	 */
+	if (!dax_drv->probe || !dax_drv->remove)
+		return -EINVAL;
+
 	INIT_LIST_HEAD(&dax_drv->ids);
 	drv->owner = module;
 	drv->name = mod_name;

base-commit: 5c8fe583cce542aa0b84adc939ce85293de36e5e
-- 
2.29.2


             reply	other threads:[~2021-01-27 23:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 23:01 Uwe Kleine-König [this message]
2021-01-27 23:01 ` [PATCH 1/3] device-dax: Prevent registering drivers without probe or remove callback Uwe Kleine-König
2021-01-27 23:01 ` [PATCH 2/3] dax-device: Fix error path in dax_driver_register Uwe Kleine-König
2021-01-27 23:01   ` Uwe Kleine-König
2021-01-27 23:01 ` [PATCH 3/3] dax-device: Make remove callback return void Uwe Kleine-König
2021-01-27 23:01   ` Uwe Kleine-König

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=20210127230124.109522-1-uwe@kleine-koenig.org \
    --to=uwe@kleine-koenig.org \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.