driver core: class: implement class_get/put without the private pointer.
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Mar 2023 19:42:33 +0000 (20:42 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Mar 2023 05:55:07 +0000 (07:55 +0200)
commit884f8ce42ccec9d0bf11d8bf9f111e5961ca1c82
treeb5aa06b6038676d53c88be5efc210a676df9932a
parent75a2d4226b53710380d1017b3f4c88f937ddba78
driver core: class: implement class_get/put without the private pointer.

Much like what was done in commit 273afac615ad ("driver core: bus:
implement bus_get/put() without the private pointer"), it is time to
move the driver core away from using the internal private pointer in
struct class in order to enable it to be always a constant and be placed
in read-only memory in the future.

First step in doing this is to create a helper function that turns a
'struct class' into 'struct subsys_private' called class_to_subsys().

class_to_subsys() walks the list of registered busses in the system and
finds the matching one based on the pointer to the class itself.  As
this is a short list, and this function is not on any fast path, it
should not be noticable.

Implement class_get() and class_put() using this new helper function.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230325194234.46588-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/class.c