mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
driver core: have match() callback in struct bus_type take a const *
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>
This commit is contained in:
@@ -816,10 +816,10 @@ EXPORT_SYMBOL(locomo_frontlight_set);
|
||||
* We model this as a regular bus type, and hang devices directly
|
||||
* off this.
|
||||
*/
|
||||
static int locomo_match(struct device *_dev, struct device_driver *_drv)
|
||||
static int locomo_match(struct device *_dev, const struct device_driver *_drv)
|
||||
{
|
||||
struct locomo_dev *dev = LOCOMO_DEV(_dev);
|
||||
struct locomo_driver *drv = LOCOMO_DRV(_drv);
|
||||
const struct locomo_driver *drv = LOCOMO_DRV(_drv);
|
||||
|
||||
return dev->devid == drv->devid;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ struct locomo_driver {
|
||||
void (*remove)(struct locomo_dev *);
|
||||
};
|
||||
|
||||
#define LOCOMO_DRV(_d) container_of((_d), struct locomo_driver, drv)
|
||||
#define LOCOMO_DRV(_d) container_of_const((_d), struct locomo_driver, drv)
|
||||
|
||||
#define LOCOMO_DRIVER_NAME(_ldev) ((_ldev)->dev.driver->name)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ struct parisc_driver {
|
||||
|
||||
|
||||
#define to_parisc_device(d) container_of(d, struct parisc_device, dev)
|
||||
#define to_parisc_driver(d) container_of(d, struct parisc_driver, drv)
|
||||
#define to_parisc_driver(d) container_of_const(d, struct parisc_driver, drv)
|
||||
#define parisc_parent(d) to_parisc_device(d->dev.parent)
|
||||
|
||||
static inline const char *parisc_pathname(struct parisc_device *d)
|
||||
|
||||
@@ -97,7 +97,7 @@ static int for_each_padev(int (*fn)(struct device *, void *), void * data)
|
||||
* @driver: the PA-RISC driver to try
|
||||
* @dev: the PA-RISC device to try
|
||||
*/
|
||||
static int match_device(struct parisc_driver *driver, struct parisc_device *dev)
|
||||
static int match_device(const struct parisc_driver *driver, struct parisc_device *dev)
|
||||
{
|
||||
const struct parisc_device_id *ids;
|
||||
|
||||
@@ -548,7 +548,7 @@ alloc_pa_dev(unsigned long hpa, struct hardware_path *mod_path)
|
||||
return dev;
|
||||
}
|
||||
|
||||
static int parisc_generic_match(struct device *dev, struct device_driver *drv)
|
||||
static int parisc_generic_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
return match_device(to_parisc_driver(drv), to_parisc_device(dev));
|
||||
}
|
||||
|
||||
@@ -390,11 +390,7 @@ int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
|
||||
int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
|
||||
void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
|
||||
|
||||
static inline struct ps3_system_bus_driver *ps3_drv_to_system_bus_drv(
|
||||
struct device_driver *_drv)
|
||||
{
|
||||
return container_of(_drv, struct ps3_system_bus_driver, core);
|
||||
}
|
||||
#define ps3_drv_to_system_bus_drv(_drv) container_of_const(_drv, struct ps3_system_bus_driver, core)
|
||||
static inline struct ps3_system_bus_device *ps3_dev_to_system_bus_dev(
|
||||
const struct device *_dev)
|
||||
{
|
||||
|
||||
@@ -156,11 +156,7 @@ static inline int vio_enable_interrupts(struct vio_dev *dev)
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
|
||||
{
|
||||
return container_of(drv, struct vio_driver, driver);
|
||||
}
|
||||
|
||||
#define to_vio_driver(__drv) container_of_const(__drv, struct vio_driver, driver)
|
||||
#define to_vio_dev(__dev) container_of_const(__dev, struct vio_dev, dev)
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
@@ -333,10 +333,10 @@ int ps3_mmio_region_init(struct ps3_system_bus_device *dev,
|
||||
EXPORT_SYMBOL_GPL(ps3_mmio_region_init);
|
||||
|
||||
static int ps3_system_bus_match(struct device *_dev,
|
||||
struct device_driver *_drv)
|
||||
const struct device_driver *_drv)
|
||||
{
|
||||
int result;
|
||||
struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv);
|
||||
const struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv);
|
||||
struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
|
||||
|
||||
if (!dev->match_sub_id)
|
||||
|
||||
@@ -339,7 +339,7 @@ static struct attribute *ibmbus_bus_attrs[] = {
|
||||
};
|
||||
ATTRIBUTE_GROUPS(ibmbus_bus);
|
||||
|
||||
static int ibmebus_bus_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int ibmebus_bus_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
const struct of_device_id *matches = drv->of_match_table;
|
||||
|
||||
|
||||
@@ -1576,10 +1576,10 @@ void vio_unregister_device(struct vio_dev *viodev)
|
||||
}
|
||||
EXPORT_SYMBOL(vio_unregister_device);
|
||||
|
||||
static int vio_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int vio_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
const struct vio_dev *vio_dev = to_vio_dev(dev);
|
||||
struct vio_driver *vio_drv = to_vio_driver(drv);
|
||||
const struct vio_driver *vio_drv = to_vio_driver(drv);
|
||||
const struct vio_device_id *ids = vio_drv->id_table;
|
||||
|
||||
return (ids != NULL) && (vio_match_device(ids, vio_dev) != NULL);
|
||||
@@ -1689,7 +1689,7 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
|
||||
/* construct the kobject name from the device node */
|
||||
if (of_node_is_type(vnode_parent, "vdevice")) {
|
||||
const __be32 *prop;
|
||||
|
||||
|
||||
prop = of_get_property(vnode, "reg", NULL);
|
||||
if (!prop)
|
||||
goto out;
|
||||
|
||||
@@ -210,7 +210,7 @@ extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
|
||||
#define get_ccwdev_lock(x) (x)->ccwlock
|
||||
|
||||
#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
|
||||
#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
|
||||
#define to_ccwdrv(n) container_of_const(n, struct ccw_driver, driver)
|
||||
|
||||
extern struct ccw_device *ccw_device_create_console(struct ccw_driver *);
|
||||
extern void ccw_device_destroy_console(struct ccw_device *);
|
||||
|
||||
@@ -483,11 +483,7 @@ int __vio_register_driver(struct vio_driver *drv, struct module *owner,
|
||||
__vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
|
||||
void vio_unregister_driver(struct vio_driver *drv);
|
||||
|
||||
static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
|
||||
{
|
||||
return container_of(drv, struct vio_driver, driver);
|
||||
}
|
||||
|
||||
#define to_vio_driver(__drv) container_of_const(__drv, struct vio_driver, driver)
|
||||
#define to_vio_dev(__dev) container_of_const(__dev, struct vio_dev, dev)
|
||||
|
||||
int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
|
||||
|
||||
@@ -54,10 +54,10 @@ static int vio_hotplug(const struct device *dev, struct kobj_uevent_env *env)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vio_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int vio_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct vio_dev *vio_dev = to_vio_dev(dev);
|
||||
struct vio_driver *vio_drv = to_vio_driver(drv);
|
||||
const struct vio_driver *vio_drv = to_vio_driver(drv);
|
||||
const struct vio_device_id *matches = vio_drv->id_table;
|
||||
|
||||
if (!matches)
|
||||
|
||||
@@ -1045,10 +1045,10 @@ EXPORT_SYMBOL(acpi_bus_unregister_driver);
|
||||
ACPI Bus operations
|
||||
-------------------------------------------------------------------------- */
|
||||
|
||||
static int acpi_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int acpi_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct acpi_device *acpi_dev = to_acpi_device(dev);
|
||||
struct acpi_driver *acpi_drv = to_acpi_driver(drv);
|
||||
const struct acpi_driver *acpi_drv = to_acpi_driver(drv);
|
||||
|
||||
return acpi_dev->flags.match_driver
|
||||
&& !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <linux/iommu.h>
|
||||
#include <linux/dma-map-ops.h>
|
||||
|
||||
#define to_amba_driver(d) container_of(d, struct amba_driver, drv)
|
||||
#define to_amba_driver(d) container_of_const(d, struct amba_driver, drv)
|
||||
|
||||
/* called on periphid match and class 0x9 coresight device. */
|
||||
static int
|
||||
@@ -205,10 +205,10 @@ err_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int amba_match(struct device *dev, struct device_driver *drv)
|
||||
static int amba_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct amba_device *pcdev = to_amba_device(dev);
|
||||
struct amba_driver *pcdrv = to_amba_driver(drv);
|
||||
const struct amba_driver *pcdrv = to_amba_driver(drv);
|
||||
|
||||
mutex_lock(&pcdev->periphid_lock);
|
||||
if (!pcdev->periphid) {
|
||||
|
||||
@@ -177,7 +177,7 @@ static const struct auxiliary_device_id *auxiliary_match_id(const struct auxilia
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int auxiliary_match(struct device *dev, struct device_driver *drv)
|
||||
static int auxiliary_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
|
||||
const struct auxiliary_driver *auxdrv = to_auxiliary_drv(drv);
|
||||
|
||||
@@ -164,8 +164,7 @@ void device_set_deferred_probe_reason(const struct device *dev, struct va_format
|
||||
static inline int driver_match_device(const struct device_driver *drv,
|
||||
struct device *dev)
|
||||
{
|
||||
/* cast will be removed in the future when match can handle a const pointer properly. */
|
||||
return drv->bus->match ? drv->bus->match(dev, (struct device_driver *)drv) : 1;
|
||||
return drv->bus->match ? drv->bus->match(dev, drv) : 1;
|
||||
}
|
||||
|
||||
static inline void dev_sync_state(struct device *dev)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
static DEFINE_PER_CPU(struct device *, cpu_sys_devices);
|
||||
|
||||
static int cpu_subsys_match(struct device *dev, struct device_driver *drv)
|
||||
static int cpu_subsys_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
/* ACPI style match is the only one that may succeed. */
|
||||
if (acpi_driver_match_device(dev, drv))
|
||||
|
||||
@@ -23,7 +23,7 @@ struct isa_dev {
|
||||
|
||||
#define to_isa_dev(x) container_of((x), struct isa_dev, dev)
|
||||
|
||||
static int isa_bus_match(struct device *dev, struct device_driver *driver)
|
||||
static int isa_bus_match(struct device *dev, const struct device_driver *driver)
|
||||
{
|
||||
struct isa_driver *isa_driver = to_isa_driver(driver);
|
||||
|
||||
|
||||
@@ -1332,7 +1332,7 @@ __ATTRIBUTE_GROUPS(platform_dev);
|
||||
* and compare it against the name of the driver. Return whether they match
|
||||
* or not.
|
||||
*/
|
||||
static int platform_match(struct device *dev, struct device_driver *drv)
|
||||
static int platform_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct platform_driver *pdrv = to_platform_driver(drv);
|
||||
|
||||
@@ -26,7 +26,7 @@ static unsigned int bcma_bus_next_num;
|
||||
/* bcma_buses_mutex locks the bcma_bus_next_num */
|
||||
static DEFINE_MUTEX(bcma_buses_mutex);
|
||||
|
||||
static int bcma_bus_match(struct device *dev, struct device_driver *drv);
|
||||
static int bcma_bus_match(struct device *dev, const struct device_driver *drv);
|
||||
static int bcma_device_probe(struct device *dev);
|
||||
static void bcma_device_remove(struct device *dev);
|
||||
static int bcma_device_uevent(const struct device *dev, struct kobj_uevent_env *env);
|
||||
@@ -584,10 +584,10 @@ void bcma_driver_unregister(struct bcma_driver *drv)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(bcma_driver_unregister);
|
||||
|
||||
static int bcma_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int bcma_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct bcma_device *core = container_of(dev, struct bcma_device, dev);
|
||||
struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
|
||||
const struct bcma_driver *adrv = container_of_const(drv, struct bcma_driver, drv);
|
||||
const struct bcma_device_id *cid = &core->id;
|
||||
const struct bcma_device_id *did;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user