Commit d69d8048 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

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: default avatarAlex Elder <elder@kernel.org>
Acked-by: default avatarSumit Garg <sumit.garg@linaro.org>
Link: https://lore.kernel.org/r/2024070136-wrongdoer-busily-01e8@gregkh


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6b521fc1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
}
+1 −1
Original line number Diff line number Diff line
@@ -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)

+1 −1
Original line number Diff line number Diff line
@@ -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)
+2 −2
Original line number Diff line number Diff line
@@ -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));
}
+1 −5
Original line number Diff line number Diff line
@@ -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)
{
Loading