mirror of
https://github.com/torvalds/linux.git
synced 2024-11-01 13:03:25 +01:00
d69d804845
In the match() callback, the struct device_driver * should not be changed, so change the function callback to be a const *. This is one step of many towards making the driver core safe to have struct device_driver in read-only memory. Because the match() callback is in all busses, all busses are modified to handle this properly. This does entail switching some container_of() calls to container_of_const() to properly handle the constant *. For some busses, like PCI and USB and HV, the const * is cast away in the match callback as those busses do want to modify those structures at this point in time (they have a local lock in the driver structure.) That will have to be changed in the future if they wish to have their struct device * in read-only-memory. Cc: Rafael J. Wysocki <rafael@kernel.org> Reviewed-by: Alex Elder <elder@kernel.org> Acked-by: Sumit Garg <sumit.garg@linaro.org> Link: https://lore.kernel.org/r/2024070136-wrongdoer-busily-01e8@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
97 lines
2.3 KiB
C
97 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/device.h>
|
|
#include "idxd.h"
|
|
|
|
|
|
int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,
|
|
const char *mod_name)
|
|
{
|
|
struct device_driver *drv = &idxd_drv->drv;
|
|
|
|
if (!idxd_drv->type) {
|
|
pr_debug("driver type not set (%ps)\n", __builtin_return_address(0));
|
|
return -EINVAL;
|
|
}
|
|
|
|
drv->name = idxd_drv->name;
|
|
drv->bus = &dsa_bus_type;
|
|
drv->owner = owner;
|
|
drv->mod_name = mod_name;
|
|
|
|
return driver_register(drv);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__idxd_driver_register);
|
|
|
|
void idxd_driver_unregister(struct idxd_device_driver *idxd_drv)
|
|
{
|
|
driver_unregister(&idxd_drv->drv);
|
|
}
|
|
EXPORT_SYMBOL_GPL(idxd_driver_unregister);
|
|
|
|
static int idxd_config_bus_match(struct device *dev,
|
|
const struct device_driver *drv)
|
|
{
|
|
const struct idxd_device_driver *idxd_drv =
|
|
container_of_const(drv, struct idxd_device_driver, drv);
|
|
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
|
|
int i = 0;
|
|
|
|
while (idxd_drv->type[i] != IDXD_DEV_NONE) {
|
|
if (idxd_dev->type == idxd_drv->type[i])
|
|
return 1;
|
|
i++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int idxd_config_bus_probe(struct device *dev)
|
|
{
|
|
struct idxd_device_driver *idxd_drv =
|
|
container_of(dev->driver, struct idxd_device_driver, drv);
|
|
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
|
|
|
|
return idxd_drv->probe(idxd_dev);
|
|
}
|
|
|
|
static void idxd_config_bus_remove(struct device *dev)
|
|
{
|
|
struct idxd_device_driver *idxd_drv =
|
|
container_of(dev->driver, struct idxd_device_driver, drv);
|
|
struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
|
|
|
|
idxd_drv->remove(idxd_dev);
|
|
}
|
|
|
|
static int idxd_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)
|
|
{
|
|
return add_uevent_var(env, "MODALIAS=" IDXD_DEVICES_MODALIAS_FMT, 0);
|
|
}
|
|
|
|
const struct bus_type dsa_bus_type = {
|
|
.name = "dsa",
|
|
.match = idxd_config_bus_match,
|
|
.probe = idxd_config_bus_probe,
|
|
.remove = idxd_config_bus_remove,
|
|
.uevent = idxd_bus_uevent,
|
|
};
|
|
EXPORT_SYMBOL_GPL(dsa_bus_type);
|
|
|
|
static int __init dsa_bus_init(void)
|
|
{
|
|
return bus_register(&dsa_bus_type);
|
|
}
|
|
module_init(dsa_bus_init);
|
|
|
|
static void __exit dsa_bus_exit(void)
|
|
{
|
|
bus_unregister(&dsa_bus_type);
|
|
}
|
|
module_exit(dsa_bus_exit);
|
|
|
|
MODULE_DESCRIPTION("IDXD driver dsa_bus_type driver");
|
|
MODULE_LICENSE("GPL v2");
|