Skip to content

Commit

Permalink
FROMGIT: drivers: base: Reduce device link removal code duplication
Browse files Browse the repository at this point in the history
Reduce device link removal code duplication between the cases when
SRCU is enabled and when it is disabled by moving the only differing
piece of it (which is the removal of the link from the consumer and
supplier lists) into a separate wrapper function (defined differently
for each of the cases in question).

No intentional functional impact.

Reviewed-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/4326215.LvFx2qVVIh@kreacher
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0c87131
 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
 driver-core-linus)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I0946e6bfa011e765551903683a4a11e87398273c
  • Loading branch information
rafaeljw authored and toddkjos committed Jun 4, 2021
1 parent cead466 commit 60ea20e
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ static void device_link_synchronize_removal(void)
{
synchronize_srcu(&device_links_srcu);
}

static void device_link_remove_from_lists(struct device_link *link)
{
list_del_rcu(&link->s_node);
list_del_rcu(&link->c_node);
}
#else /* !CONFIG_SRCU */
static DECLARE_RWSEM(device_links_lock);

Expand Down Expand Up @@ -230,6 +236,12 @@ int device_links_read_lock_held(void)
static inline void device_link_synchronize_removal(void)
{
}

static void device_link_remove_from_lists(struct device_link *link)
{
list_del(&link->s_node);
list_del(&link->c_node);
}
#endif /* !CONFIG_SRCU */

static bool device_is_ancestor(struct device *dev, struct device *target)
Expand Down Expand Up @@ -852,7 +864,6 @@ struct device_link *device_link_add(struct device *consumer,
}
EXPORT_SYMBOL_GPL(device_link_add);

#ifdef CONFIG_SRCU
static void __device_link_del(struct kref *kref)
{
struct device_link *link = container_of(kref, struct device_link, kref);
Expand All @@ -862,25 +873,9 @@ static void __device_link_del(struct kref *kref)

pm_runtime_drop_link(link);

list_del_rcu(&link->s_node);
list_del_rcu(&link->c_node);
device_unregister(&link->link_dev);
}
#else /* !CONFIG_SRCU */
static void __device_link_del(struct kref *kref)
{
struct device_link *link = container_of(kref, struct device_link, kref);

dev_info(link->consumer, "Dropping the link to %s\n",
dev_name(link->supplier));

pm_runtime_drop_link(link);

list_del(&link->s_node);
list_del(&link->c_node);
device_link_remove_from_lists(link);
device_unregister(&link->link_dev);
}
#endif /* !CONFIG_SRCU */

static void device_link_put_kref(struct device_link *link)
{
Expand Down

0 comments on commit 60ea20e

Please sign in to comment.