Skip to content

Commit d69d804

Browse files
committed
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 <[email protected]> Reviewed-by: Alex Elder <[email protected]> Acked-by: Sumit Garg <[email protected]> Link: https://lore.kernel.org/r/2024070136-wrongdoer-busily-01e8@gregkh Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6b521fc commit d69d804

File tree

163 files changed

+268
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+268
-338
lines changed

arch/arm/common/locomo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,10 @@ EXPORT_SYMBOL(locomo_frontlight_set);
816816
* We model this as a regular bus type, and hang devices directly
817817
* off this.
818818
*/
819-
static int locomo_match(struct device *_dev, struct device_driver *_drv)
819+
static int locomo_match(struct device *_dev, const struct device_driver *_drv)
820820
{
821821
struct locomo_dev *dev = LOCOMO_DEV(_dev);
822-
struct locomo_driver *drv = LOCOMO_DRV(_drv);
822+
const struct locomo_driver *drv = LOCOMO_DRV(_drv);
823823

824824
return dev->devid == drv->devid;
825825
}

arch/arm/include/asm/hardware/locomo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct locomo_driver {
189189
void (*remove)(struct locomo_dev *);
190190
};
191191

192-
#define LOCOMO_DRV(_d) container_of((_d), struct locomo_driver, drv)
192+
#define LOCOMO_DRV(_d) container_of_const((_d), struct locomo_driver, drv)
193193

194194
#define LOCOMO_DRIVER_NAME(_ldev) ((_ldev)->dev.driver->name)
195195

arch/parisc/include/asm/parisc-device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct parisc_driver {
4141

4242

4343
#define to_parisc_device(d) container_of(d, struct parisc_device, dev)
44-
#define to_parisc_driver(d) container_of(d, struct parisc_driver, drv)
44+
#define to_parisc_driver(d) container_of_const(d, struct parisc_driver, drv)
4545
#define parisc_parent(d) to_parisc_device(d->dev.parent)
4646

4747
static inline const char *parisc_pathname(struct parisc_device *d)

arch/parisc/kernel/drivers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int for_each_padev(int (*fn)(struct device *, void *), void * data)
9797
* @driver: the PA-RISC driver to try
9898
* @dev: the PA-RISC device to try
9999
*/
100-
static int match_device(struct parisc_driver *driver, struct parisc_device *dev)
100+
static int match_device(const struct parisc_driver *driver, struct parisc_device *dev)
101101
{
102102
const struct parisc_device_id *ids;
103103

@@ -548,7 +548,7 @@ alloc_pa_dev(unsigned long hpa, struct hardware_path *mod_path)
548548
return dev;
549549
}
550550

551-
static int parisc_generic_match(struct device *dev, struct device_driver *drv)
551+
static int parisc_generic_match(struct device *dev, const struct device_driver *drv)
552552
{
553553
return match_device(to_parisc_driver(drv), to_parisc_device(dev));
554554
}

arch/powerpc/include/asm/ps3.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,7 @@ int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
390390
int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
391391
void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
392392

393-
static inline struct ps3_system_bus_driver *ps3_drv_to_system_bus_drv(
394-
struct device_driver *_drv)
395-
{
396-
return container_of(_drv, struct ps3_system_bus_driver, core);
397-
}
393+
#define ps3_drv_to_system_bus_drv(_drv) container_of_const(_drv, struct ps3_system_bus_driver, core)
398394
static inline struct ps3_system_bus_device *ps3_dev_to_system_bus_dev(
399395
const struct device *_dev)
400396
{

arch/powerpc/include/asm/vio.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,7 @@ static inline int vio_enable_interrupts(struct vio_dev *dev)
156156
}
157157
#endif
158158

159-
static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
160-
{
161-
return container_of(drv, struct vio_driver, driver);
162-
}
163-
159+
#define to_vio_driver(__drv) container_of_const(__drv, struct vio_driver, driver)
164160
#define to_vio_dev(__dev) container_of_const(__dev, struct vio_dev, dev)
165161

166162
#endif /* __KERNEL__ */

arch/powerpc/platforms/ps3/system-bus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ int ps3_mmio_region_init(struct ps3_system_bus_device *dev,
333333
EXPORT_SYMBOL_GPL(ps3_mmio_region_init);
334334

335335
static int ps3_system_bus_match(struct device *_dev,
336-
struct device_driver *_drv)
336+
const struct device_driver *_drv)
337337
{
338338
int result;
339-
struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv);
339+
const struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv);
340340
struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
341341

342342
if (!dev->match_sub_id)

arch/powerpc/platforms/pseries/ibmebus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static struct attribute *ibmbus_bus_attrs[] = {
339339
};
340340
ATTRIBUTE_GROUPS(ibmbus_bus);
341341

342-
static int ibmebus_bus_bus_match(struct device *dev, struct device_driver *drv)
342+
static int ibmebus_bus_bus_match(struct device *dev, const struct device_driver *drv)
343343
{
344344
const struct of_device_id *matches = drv->of_match_table;
345345

arch/powerpc/platforms/pseries/vio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,10 +1576,10 @@ void vio_unregister_device(struct vio_dev *viodev)
15761576
}
15771577
EXPORT_SYMBOL(vio_unregister_device);
15781578

1579-
static int vio_bus_match(struct device *dev, struct device_driver *drv)
1579+
static int vio_bus_match(struct device *dev, const struct device_driver *drv)
15801580
{
15811581
const struct vio_dev *vio_dev = to_vio_dev(dev);
1582-
struct vio_driver *vio_drv = to_vio_driver(drv);
1582+
const struct vio_driver *vio_drv = to_vio_driver(drv);
15831583
const struct vio_device_id *ids = vio_drv->id_table;
15841584

15851585
return (ids != NULL) && (vio_match_device(ids, vio_dev) != NULL);
@@ -1689,7 +1689,7 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
16891689
/* construct the kobject name from the device node */
16901690
if (of_node_is_type(vnode_parent, "vdevice")) {
16911691
const __be32 *prop;
1692-
1692+
16931693
prop = of_get_property(vnode, "reg", NULL);
16941694
if (!prop)
16951695
goto out;

arch/s390/include/asm/ccwdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extern void ccw_device_get_id(struct ccw_device *, struct ccw_dev_id *);
210210
#define get_ccwdev_lock(x) (x)->ccwlock
211211

212212
#define to_ccwdev(n) container_of(n, struct ccw_device, dev)
213-
#define to_ccwdrv(n) container_of(n, struct ccw_driver, driver)
213+
#define to_ccwdrv(n) container_of_const(n, struct ccw_driver, driver)
214214

215215
extern struct ccw_device *ccw_device_create_console(struct ccw_driver *);
216216
extern void ccw_device_destroy_console(struct ccw_device *);

0 commit comments

Comments
 (0)