Skip to content

Commit

Permalink
driver core: mark async_driver as a const *
Browse files Browse the repository at this point in the history
Within struct device_private, mark the async_driver * as const as it is
never modified.  This requires some internal-to-the-driver-core
functions to also have their parameters marked as constant, and there is
one place where we cast _back_ from the const pointer to a real one, as
the driver core still wants to modify the structure in a number of
remaining places.

Cc: Rafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20240611130103.3262749-12-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Greg Kroah-Hartman committed Jun 13, 2024
1 parent f6e98ef commit c6c631d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion drivers/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct device_private {
struct klist_node knode_bus;
struct klist_node knode_class;
struct list_head deferred_probe;
struct device_driver *async_driver;
const struct device_driver *async_driver;
char *deferred_probe_reason;
struct device *device;
u8 dead:1;
Expand Down
15 changes: 8 additions & 7 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ static void device_remove(struct device *dev)
dev->driver->remove(dev);
}

static int call_driver_probe(struct device *dev, struct device_driver *drv)
static int call_driver_probe(struct device *dev, const struct device_driver *drv)
{
int ret = 0;

Expand Down Expand Up @@ -599,7 +599,7 @@ static int call_driver_probe(struct device *dev, struct device_driver *drv)
return ret;
}

static int really_probe(struct device *dev, struct device_driver *drv)
static int really_probe(struct device *dev, const struct device_driver *drv)
{
bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
!drv->suppress_bind_attrs;
Expand Down Expand Up @@ -628,7 +628,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
}

re_probe:
dev->driver = drv;
// FIXME - this cast should not be needed "soon"
dev->driver = (struct device_driver *)drv;

/* If using pinctrl, bind pins now before probing */
ret = pinctrl_bind_pins(dev);
Expand Down Expand Up @@ -727,7 +728,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
/*
* For initcall_debug, show the driver probe time.
*/
static int really_probe_debug(struct device *dev, struct device_driver *drv)
static int really_probe_debug(struct device *dev, const struct device_driver *drv)
{
ktime_t calltime, rettime;
int ret;
Expand Down Expand Up @@ -774,7 +775,7 @@ void wait_for_device_probe(void)
}
EXPORT_SYMBOL_GPL(wait_for_device_probe);

static int __driver_probe_device(struct device_driver *drv, struct device *dev)
static int __driver_probe_device(const struct device_driver *drv, struct device *dev)
{
int ret = 0;

Expand Down Expand Up @@ -819,7 +820,7 @@ static int __driver_probe_device(struct device_driver *drv, struct device *dev)
*
* If the device has a parent, runtime-resume the parent before driver probing.
*/
static int driver_probe_device(struct device_driver *drv, struct device *dev)
static int driver_probe_device(const struct device_driver *drv, struct device *dev)
{
int trigger_count = atomic_read(&deferred_trigger_count);
int ret;
Expand Down Expand Up @@ -1137,7 +1138,7 @@ EXPORT_SYMBOL_GPL(device_driver_attach);
static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
{
struct device *dev = _dev;
struct device_driver *drv;
const struct device_driver *drv;
int ret;

__device_driver_lock(dev, dev->parent);
Expand Down

0 comments on commit c6c631d

Please sign in to comment.