public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drivers: base: Warn if driver name is not present
@ 2020-06-08  9:52 matthias.bgg
  2020-06-08  9:52 ` [PATCH 2/2] drivers: base: Convert to printk alias functions matthias.bgg
  2020-06-08 10:57 ` [PATCH 1/2] drivers: base: Warn if driver name is not present Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: matthias.bgg @ 2020-06-08  9:52 UTC (permalink / raw)
  To: gregkh, rafael
  Cc: linux-kernel, gene.chen.richtek, lee.jones, matthias.bgg,
	Matthias Brugger, kernel test robot

From: Matthias Brugger <mbrugger@suse.com>

If we pass a driver without a name, we end up in a NULL pointer
derefernce. Check for the name before trying to register the driver.
As we don't have a driver name to point to in the error message, we dump
the call stack to make it easier to detect the buggy driver.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>
---
 drivers/base/driver.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 57c68769e157..40fba959c140 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -149,6 +149,12 @@ int driver_register(struct device_driver *drv)
 	int ret;
 	struct device_driver *other;
 
+	if (!drv->name) {
+		pr_err("Driver has no name.\n");
+		dump_stack();
+		return -EINVAL;
+	}
+
 	if (!drv->bus->p) {
 		pr_err("Driver '%s' was unable to register with bus_type '%s' because the bus was not initialized.\n",
 			   drv->name, drv->bus->name);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-08 12:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-08  9:52 [PATCH 1/2] drivers: base: Warn if driver name is not present matthias.bgg
2020-06-08  9:52 ` [PATCH 2/2] drivers: base: Convert to printk alias functions matthias.bgg
2020-06-08 10:57 ` [PATCH 1/2] drivers: base: Warn if driver name is not present Greg KH
2020-06-08 11:48   ` Matthias Brugger
2020-06-08 12:15     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox