Skip to content

Commit 69d4ca0

Browse files
ukleinekgregkh
authored andcommitted
fsi: Create bus specific probe and remove functions
Introduce a bus specific probe and remove function. For now this only allows to get rid of a cast of the generic device to an fsi device in the drivers and changes the remove prototype to return void---a non-zero return value is ignored anyhow. The objective is to get rid of users of struct device callbacks .probe(), .remove() and .shutdown() to eventually remove these. Until all fsi drivers are converted this results in a runtime warning about the drivers needing an update because there is a bus probe function and a driver probe function. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Acked-by: Eddie James <eajames@linux.ibm.com> Link: https://patch.msgid.link/3b53adb75a5ae7894736d46cb6eb85f5ef36520e.1765279318.git.u.kleine-koenig@baylibre.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 68cc658 commit 69d4ca0

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

drivers/fsi/fsi-core.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,31 @@ static int fsi_bus_match(struct device *dev, const struct device_driver *drv)
128128
return 0;
129129
}
130130

131+
static int fsi_probe(struct device *dev)
132+
{
133+
struct fsi_device *fsidev = to_fsi_dev(dev);
134+
struct fsi_driver *fsidrv = to_fsi_drv(dev->driver);
135+
136+
if (fsidrv->probe)
137+
return fsidrv->probe(fsidev);
138+
else
139+
return 0;
140+
}
141+
142+
static void fsi_remove(struct device *dev)
143+
{
144+
struct fsi_device *fsidev = to_fsi_dev(dev);
145+
struct fsi_driver *fsidrv = to_fsi_drv(dev->driver);
146+
147+
if (fsidrv->remove)
148+
fsidrv->remove(fsidev);
149+
}
150+
131151
static const struct bus_type fsi_bus_type = {
132152
.name = "fsi",
133153
.match = fsi_bus_match,
154+
.probe = fsi_probe,
155+
.remove = fsi_remove,
134156
};
135157

136158
/*
@@ -1392,6 +1414,25 @@ void fsi_master_unregister(struct fsi_master *master)
13921414
}
13931415
EXPORT_SYMBOL_GPL(fsi_master_unregister);
13941416

1417+
static int fsi_legacy_probe(struct fsi_device *fsidev)
1418+
{
1419+
struct device *dev = &fsidev->dev;
1420+
struct device_driver *driver = dev->driver;
1421+
1422+
return driver->probe(dev);
1423+
}
1424+
1425+
static void fsi_legacy_remove(struct fsi_device *fsidev)
1426+
{
1427+
struct device *dev = &fsidev->dev;
1428+
struct device_driver *driver = dev->driver;
1429+
int ret;
1430+
1431+
ret = driver->remove(dev);
1432+
if (unlikely(ret))
1433+
dev_warn(dev, "Ignoring return value of remove callback (%pe)\n", ERR_PTR(ret));
1434+
}
1435+
13951436
int fsi_driver_register(struct fsi_driver *fsi_drv)
13961437
{
13971438
if (!fsi_drv)
@@ -1401,6 +1442,15 @@ int fsi_driver_register(struct fsi_driver *fsi_drv)
14011442

14021443
fsi_drv->drv.bus = &fsi_bus_type;
14031444

1445+
/*
1446+
* This driver needs updating. Note that driver_register() warns about
1447+
* this, so we're not adding another warning here.
1448+
*/
1449+
if (!fsi_drv->probe && fsi_drv->drv.probe)
1450+
fsi_drv->probe = fsi_legacy_probe;
1451+
if (!fsi_drv->remove && fsi_drv->drv.remove)
1452+
fsi_drv->remove = fsi_legacy_remove;
1453+
14041454
return driver_register(&fsi_drv->drv);
14051455
}
14061456
EXPORT_SYMBOL_GPL(fsi_driver_register);

include/linux/fsi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct fsi_device_id {
4949
.engine_type = (t), .version = (v),
5050

5151
struct fsi_driver {
52+
int (*probe)(struct fsi_device *fsidev);
53+
void (*remove)(struct fsi_device *fsidev);
5254
struct device_driver drv;
5355
const struct fsi_device_id *id_table;
5456
};

0 commit comments

Comments
 (0)