mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-16 12:10:38 -04: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:
@@ -806,9 +806,9 @@ void gameport_unregister_driver(struct gameport_driver *drv)
|
||||
}
|
||||
EXPORT_SYMBOL(gameport_unregister_driver);
|
||||
|
||||
static int gameport_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int gameport_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct gameport_driver *gameport_drv = to_gameport_driver(drv);
|
||||
const struct gameport_driver *gameport_drv = to_gameport_driver(drv);
|
||||
|
||||
return !gameport_drv->ignore;
|
||||
}
|
||||
|
||||
@@ -144,9 +144,9 @@ bool rmi_is_function_device(struct device *dev)
|
||||
return dev->type == &rmi_function_type;
|
||||
}
|
||||
|
||||
static int rmi_function_match(struct device *dev, struct device_driver *drv)
|
||||
static int rmi_function_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct rmi_function_handler *handler = to_rmi_function_handler(drv);
|
||||
const struct rmi_function_handler *handler = to_rmi_function_handler(drv);
|
||||
struct rmi_function *fn = to_rmi_function(dev);
|
||||
|
||||
return fn->fd.function_number == handler->func;
|
||||
@@ -333,7 +333,7 @@ EXPORT_SYMBOL_GPL(rmi_unregister_function_handler);
|
||||
|
||||
/* Bus specific stuff */
|
||||
|
||||
static int rmi_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int rmi_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
bool physical = rmi_is_physical_device(dev);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ struct rmi_function_handler {
|
||||
};
|
||||
|
||||
#define to_rmi_function_handler(d) \
|
||||
container_of(d, struct rmi_function_handler, driver)
|
||||
container_of_const(d, struct rmi_function_handler, driver)
|
||||
|
||||
int __must_check __rmi_register_function_handler(struct rmi_function_handler *,
|
||||
struct module *, const char *);
|
||||
|
||||
@@ -1258,7 +1258,7 @@ static struct rmi_driver rmi_physical_driver = {
|
||||
.set_input_params = rmi_driver_set_input_params,
|
||||
};
|
||||
|
||||
bool rmi_is_physical_driver(struct device_driver *drv)
|
||||
bool rmi_is_physical_driver(const struct device_driver *drv)
|
||||
{
|
||||
return drv == &rmi_physical_driver.driver;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ int rmi_register_desc_calc_reg_offset(
|
||||
bool rmi_register_desc_has_subpacket(const struct rmi_register_desc_item *item,
|
||||
u8 subpacket);
|
||||
|
||||
bool rmi_is_physical_driver(struct device_driver *);
|
||||
bool rmi_is_physical_driver(const struct device_driver *);
|
||||
int rmi_register_physical_driver(void);
|
||||
void rmi_unregister_physical_driver(void);
|
||||
void rmi_free_function_list(struct rmi_device *rmi_dev);
|
||||
|
||||
@@ -877,10 +877,10 @@ static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
|
||||
serio_continue_rx(serio);
|
||||
}
|
||||
|
||||
static int serio_bus_match(struct device *dev, struct device_driver *drv)
|
||||
static int serio_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
struct serio *serio = to_serio_port(dev);
|
||||
struct serio_driver *serio_drv = to_serio_driver(drv);
|
||||
const struct serio_driver *serio_drv = to_serio_driver(drv);
|
||||
|
||||
if (serio->manual_bind || serio_drv->manual_bind)
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user