diff mbox series

[1/2] i3c: Handle drivers without probe or remove callback

Message ID 20210128091048.17006-1-u.kleine-koenig@pengutronix.de (mailing list archive)
State Superseded
Headers show
Series [1/2] i3c: Handle drivers without probe or remove callback | expand

Commit Message

Uwe Kleine-König Jan. 28, 2021, 9:10 a.m. UTC
A registered driver without a probe callback doesn't make sense, so
refuse to register such a driver. (Otherwise i3c_device_probe() yields a
NULL pointer exception.)

A driver without remove is possible, e.g. when all resources are freed
using devm callbacks. So guard the call to driver->remove by a check
for being non-NULL.

Note that the only in-tree i3c driver
(drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c) doesn't have a remove
callback.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/i3c/device.c |  5 +++++
 drivers/i3c/master.c | 10 ++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

Comments

Alexandre Belloni Feb. 1, 2021, 11:17 p.m. UTC | #1
On Thu, 28 Jan 2021 10:10:47 +0100, Uwe Kleine-König wrote:
> A registered driver without a probe callback doesn't make sense, so
> refuse to register such a driver. (Otherwise i3c_device_probe() yields a
> NULL pointer exception.)
> 
> A driver without remove is possible, e.g. when all resources are freed
> using devm callbacks. So guard the call to driver->remove by a check
> for being non-NULL.
> 
> [...]

Applied, thanks!

[1/2] i3c: Handle drivers without probe or remove callback
      commit: 7456fea589c6ad3422b0c188871ae80e1d307737
[2/2] i3c: Make remove callback return void
      commit: dd9267034c0e364b49261c3e0070b863286d1242

Best regards,
diff mbox series

Patch

diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c
index bb8e60dff988..e92d3e9a52bd 100644
--- a/drivers/i3c/device.c
+++ b/drivers/i3c/device.c
@@ -262,6 +262,11 @@  int i3c_driver_register_with_owner(struct i3c_driver *drv, struct module *owner)
 	drv->driver.owner = owner;
 	drv->driver.bus = &i3c_bus_type;
 
+	if (!drv->probe) {
+		pr_err("Trying to register an i3c driver without probe callback\n");
+		return -EINVAL;
+	}
+
 	return driver_register(&drv->driver);
 }
 EXPORT_SYMBOL_GPL(i3c_driver_register_with_owner);
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index b61bf53ec07a..57a4f699eb8d 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -326,11 +326,13 @@  static int i3c_device_remove(struct device *dev)
 {
 	struct i3c_device *i3cdev = dev_to_i3cdev(dev);
 	struct i3c_driver *driver = drv_to_i3cdrv(dev->driver);
-	int ret;
+	int ret = 0;
 
-	ret = driver->remove(i3cdev);
-	if (ret)
-		return ret;
+	if (driver->remove) {
+		ret = driver->remove(i3cdev);
+		if (ret)
+			return ret;
+	}
 
 	i3c_device_free_ibi(i3cdev);