Skip to content

Commit 269e974

Browse files
committed
driver core: make [device_]driver_attach take a const *
Change device_driver_attach() and driver_attach() to take a const * to struct device driver as neither of them modify the structure at all. Also, for some odd reason, drivers/dma/idxd/compat.c had a duplicate external reference to device_driver_attach(), so remove that to fix up the build, it should never have had that there in the first place. Cc: Rafael J. Wysocki <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Dave Jiang <[email protected]> Cc: Vinod Koul <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Petr Tesarik <[email protected]> Cc: Alexander Lobakin <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/2024061401-rasping-manger-c385@gregkh Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2f3cfd2 commit 269e974

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

drivers/base/base.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ void device_release_driver_internal(struct device *dev, const struct device_driv
161161
void driver_detach(const struct device_driver *drv);
162162
void driver_deferred_probe_del(struct device *dev);
163163
void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf);
164-
static inline int driver_match_device(struct device_driver *drv,
164+
static inline int driver_match_device(const struct device_driver *drv,
165165
struct device *dev)
166166
{
167-
return drv->bus->match ? drv->bus->match(dev, drv) : 1;
167+
/* cast will be removed in the future when match can handle a const pointer properly. */
168+
return drv->bus->match ? drv->bus->match(dev, (struct device_driver *)drv) : 1;
168169
}
169170

170171
static inline void dev_sync_state(struct device *dev)

drivers/base/dd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ static void __device_driver_unlock(struct device *dev, struct device *parent)
11181118
* Manually attach driver to a device. Will acquire both @dev lock and
11191119
* @dev->parent lock if needed. Returns 0 on success, -ERR on failure.
11201120
*/
1121-
int device_driver_attach(struct device_driver *drv, struct device *dev)
1121+
int device_driver_attach(const struct device_driver *drv, struct device *dev)
11221122
{
11231123
int ret;
11241124

@@ -1154,7 +1154,7 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
11541154

11551155
static int __driver_attach(struct device *dev, void *data)
11561156
{
1157-
struct device_driver *drv = data;
1157+
const struct device_driver *drv = data;
11581158
bool async = false;
11591159
int ret;
11601160

@@ -1227,9 +1227,10 @@ static int __driver_attach(struct device *dev, void *data)
12271227
* returns 0 and the @dev->driver is set, we've found a
12281228
* compatible pair.
12291229
*/
1230-
int driver_attach(struct device_driver *drv)
1230+
int driver_attach(const struct device_driver *drv)
12311231
{
1232-
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
1232+
/* The (void *) will be put back to const * in __driver_attach() */
1233+
return bus_for_each_dev(drv->bus, NULL, (void *)drv, __driver_attach);
12331234
}
12341235
EXPORT_SYMBOL_GPL(driver_attach);
12351236

drivers/dma/idxd/compat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <linux/device/bus.h>
88
#include "idxd.h"
99

10-
extern int device_driver_attach(struct device_driver *drv, struct device *dev);
1110
extern void device_driver_detach(struct device *dev);
1211

1312
#define DRIVER_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \

include/linux/device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,12 +1177,12 @@ static inline void *dev_get_platdata(const struct device *dev)
11771177
* Manual binding of a device to driver. See drivers/base/bus.c
11781178
* for information on use.
11791179
*/
1180-
int __must_check device_driver_attach(struct device_driver *drv,
1180+
int __must_check device_driver_attach(const struct device_driver *drv,
11811181
struct device *dev);
11821182
int __must_check device_bind_driver(struct device *dev);
11831183
void device_release_driver(struct device *dev);
11841184
int __must_check device_attach(struct device *dev);
1185-
int __must_check driver_attach(struct device_driver *drv);
1185+
int __must_check driver_attach(const struct device_driver *drv);
11861186
void device_initial_probe(struct device *dev);
11871187
int __must_check device_reprobe(struct device *dev);
11881188

0 commit comments

Comments
 (0)