Greg Kroah-Hartman
ddaf098ea7
driver core: class: properly reference count class_dev_iter()
...
When class_dev_iter is initialized, the reference count for the subsys
private structure is incremented, but never decremented, causing a
memory leak over time. To resolve this, save off a pointer to the
internal structure into the class_dev_iter structure and then when the
iterator is finished, drop the reference count.
Reported-and-tested-by: syzbot+e7afd76ad060fa0d2605@syzkaller.appspotmail.com
Fixes: 7b884b7f24 ("driver core: class.c: convert to only use class_to_subsys")
Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr >
Cc: Alan Stern <stern@rowland.harvard.edu >
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Tested-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr >
Link: https://lore.kernel.org/r/2023051610-stove-condense-9a77@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-05-19 11:03:36 +01:00
Greg Kroah-Hartman
2243acd50a
driver core: class: remove struct class_interface * from callbacks
...
The add_dev and remove_dev callbacks in struct class_interface currently
pass in a pointer back to the class_interface structure that is calling
them, but none of the callback implementations actually use this pointer
as it is pointless (the structure is known, the driver passed it in in
the first place if it is really needed again.)
So clean this up and just remove the pointer from the callbacks and fix
up all callback functions.
Cc: Jean Delvare <jdelvare@suse.com >
Cc: Guenter Roeck <linux@roeck-us.net >
Cc: "David S. Miller" <davem@davemloft.net >
Cc: Eric Dumazet <edumazet@google.com >
Cc: Jakub Kicinski <kuba@kernel.org >
Cc: Paolo Abeni <pabeni@redhat.com >
Cc: Kurt Schwemmer <kurt.schwemmer@microsemi.com >
Cc: Jon Mason <jdmason@kudzu.us >
Cc: Dave Jiang <dave.jiang@intel.com >
Cc: Allen Hubbe <allenbh@gmail.com >
Cc: Dominik Brodowski <linux@dominikbrodowski.net >
Cc: Matt Porter <mporter@kernel.crashing.org >
Cc: Alexandre Bounine <alex.bou9@gmail.com >
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com >
Cc: "Martin K. Petersen" <martin.petersen@oracle.com >
Cc: Doug Gilbert <dgilbert@interlog.com >
Cc: John Stultz <jstultz@google.com >
Cc: Thomas Gleixner <tglx@linutronix.de >
Cc: Stephen Boyd <sboyd@kernel.org >
Cc: Hans de Goede <hdegoede@redhat.com >
Cc: Andrew Morton <akpm@linux-foundation.org >
Cc: Wang Weiyang <wangweiyang2@huawei.com >
Cc: Yang Yingliang <yangyingliang@huawei.com >
Cc: Jakob Koschel <jakobkoschel@gmail.com >
Cc: Cai Xinchen <caixinchen1@huawei.com >
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Acked-by: Logan Gunthorpe <logang@deltatee.com >
Link: https://lore.kernel.org/r/2023040250-pushover-platter-509c@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-04-03 21:42:52 +02:00
Greg Kroah-Hartman
6b0d49be81
driver core: class: mark the struct class in struct class_interface constant
...
The struct class pointer in struct class_interface is never modified, so
mark it as const so that no one accidentally tries to modify it in the
future.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/2023040249-handball-gruffly-5da7@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-04-03 21:42:48 +02:00
Greg Kroah-Hartman
43a7206b09
driver core: class: make class_register() take a const *
...
Now that the class code is cleaned up to not modify the class pointer
registered with it, change class_register() to take a const * to allow
the structure to be placed into read-only memory.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/2023040248-customary-release-4aec@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-04-03 21:42:46 +02:00
Greg Kroah-Hartman
979207cac5
driver core: class: mark class_release() as taking a const *
...
The struct class callback, class_release(), is only called in 2 places,
the pcmcia cardservices code, and in the class driver core code. Both
places it is safe to mark the structure as a const *, to allow us to
in the future mark all struct class usages as constant and move into
read-only memory.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/2023040248-outrage-obsolete-5a9a@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-04-03 21:42:43 +02:00
Greg Kroah-Hartman
575ab414c9
driver core: make sysfs_dev_block_kobj static
...
Nothing outside of drivers/base/core.c uses sysfs_dev_block_kobj, so
make it static and document what it is used for so we remember it the
next time we touch it 15 years from now.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230331093318.82288-6-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-31 17:45:15 +02:00
Greg Kroah-Hartman
e78195d529
driver core: class: remove dev_kobj from struct class
...
The dev_kobj field in struct class is now only written to, but never
read from, so it can be removed as it is useless.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230331093318.82288-5-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-31 17:45:11 +02:00
Greg Kroah-Hartman
2df418cf4b
driver core: class: remove subsystem private pointer from struct class
...
Now that the last users of the subsystem private pointer in struct class
are gone, the pointer can be removed, as no one is using it. One step
closer to allowing struct class to be const and moved into read-only
memory.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230331093318.82288-3-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-31 17:45:03 +02:00
Greg Kroah-Hartman
6f14c02220
driver core: create class_is_registered()
...
Some classes (i.e. gpio), want to know if they have been registered or
not, and poke around in the class's internal structures to try to figure
this out. Because this is not really a good idea, provide a function
for classes to call to try to figure this out.
Note, this is racy as the state of the class could change at any moment
in time after the call is made, but as usually a class only wants to
know if it has been registered yet or not, it should be fairly safe to
use, and is just as safe as the previous "poke at the class internals"
check was.
Move the gpiolib code to use this function as proof that it works
properly.
Cc: Bartosz Golaszewski <brgl@bgdev.pl >
Cc: Sebastian Reichel <sre@kernel.org >
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com >
Cc: linux-gpio@vger.kernel.org
Reviewed-by: Linus Walleij <linus.walleij@linaro.org >
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230331093318.82288-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-31 17:44:54 +02:00
Greg Kroah-Hartman
75a2d4226b
driver core: class: mark the struct class for sysfs callbacks as constant
...
struct class should never be modified in a sysfs callback as there is
nothing in the structure to modify, and frankly, the structure is almost
never used in a sysfs callback, so mark it as constant to allow struct
class to be moved to read-only memory.
While we are touching all class sysfs callbacks also mark the attribute
as constant as it can not be modified. The bonding code still uses this
structure so it can not be removed from the function callbacks.
Cc: "David S. Miller" <davem@davemloft.net >
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Cc: Bartosz Golaszewski <brgl@bgdev.pl >
Cc: Eric Dumazet <edumazet@google.com >
Cc: Jakub Kicinski <kuba@kernel.org >
Cc: Jens Axboe <axboe@kernel.dk >
Cc: Johannes Berg <johannes@sipsolutions.net >
Cc: Linus Walleij <linus.walleij@linaro.org >
Cc: Minchan Kim <minchan@kernel.org >
Cc: Miquel Raynal <miquel.raynal@bootlin.com >
Cc: Namjae Jeon <linkinjeon@kernel.org >
Cc: Paolo Abeni <pabeni@redhat.com >
Cc: Russ Weight <russell.h.weight@intel.com >
Cc: Sergey Senozhatsky <senozhatsky@chromium.org >
Cc: Steve French <sfrench@samba.org >
Cc: Vignesh Raghavendra <vigneshr@ti.com >
Cc: linux-cifs@vger.kernel.org
Cc: linux-gpio@vger.kernel.org
Cc: linux-mtd@lists.infradead.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: netdev@vger.kernel.org
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org >
Link: https://lore.kernel.org/r/20230325084537.3622280-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-29 07:54:58 +02:00
Greg Kroah-Hartman
517d4927aa
driver core: bus: constify class_unregister/destroy()
...
The class_unregister() and class_destroy() function should be taking a
const * to struct class, not just a *, so fix that up.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230325084526.3622123-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-28 08:27:48 +02:00
Greg Kroah-Hartman
5c9a27df4e
driver core: move sysfs_dev_char_kobj out of class.h
...
The structure sysfs_dev_char_kobj is local only to the driver core code,
so move it out of the global class.h file and into the internal base.h
file as no one else should be touching this symbol.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230327160319.513974-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-27 18:24:29 +02:00
Greg Kroah-Hartman
009455205e
driver core: bus: move documentation for lock_key to proper location.
...
In commit 37e98d9bed ("driver core: bus: move lock_class_key into
dynamic structure"), the lock_key variable moved out of struct bus_type
and into struct subsys_private, yet the documentation for it did not
move. Fix that up and place the documentation comment in the correct
location.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Fixes: 37e98d9bed ("driver core: bus: move lock_class_key into dynamic structure")
Link: https://lore.kernel.org/r/20230324090814.386654-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-25 09:38:08 +01:00
Greg Kroah-Hartman
8a2b9c84c7
driver core: driver.h: remove extern from function prototypes
...
The kernel coding style does not require 'extern' in function prototypes
in .h files, so remove them from include/linux/device/driver.h as they
are not needed.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230324122711.2664537-3-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-24 15:35:42 +01:00
Greg Kroah-Hartman
0d62b79fd8
driver core: bus.h: remove extern from function prototypes
...
The kernel coding style does not require 'extern' in function prototypes
in .h files, so remove them from include/linux/device/bus.h as they are
not needed.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230324122711.2664537-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-24 15:35:38 +01:00
Greg Kroah-Hartman
43718dca48
driver core: class.h: remove extern from function prototypes
...
The kernel coding style does not require 'extern' in function prototypes
in .h files, so remove them from include/linux/device/class.h as they
are not needed.
Acked-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230324100132.1633647-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-24 15:34:24 +01:00
Greg Kroah-Hartman
dcfbb67e48
driver core: class: use lock_class_key already present in struct subsys_private
...
In commit 37e98d9bed ("driver core: bus: move lock_class_key into
dynamic structure"), we moved the lock_class_key into the internal
structure shared by busses and classes, but only used it for buses.
Move the class code to use this structure as it is already present and
being allocated, instead of the statically allocated on-the-stack
variable that class_create() was using as part of a macro wrapper around
the core function call.
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230324100132.1633647-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-24 15:34:18 +01:00
Greg Kroah-Hartman
c28dd08ef7
driver core: make the bus_type in struct device_driver constant
...
The pointer to struct bus_type in struct device_driver should only be
pointing to something that can never change now that the driver core has
fixed up the previously writable fields. So mark it as a constant
pointer to enforce this and move forward with the goal of moving
bus_type into read-only memory.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313182918.1312597-28-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-23 13:21:26 +01:00
Greg Kroah-Hartman
7c06be0425
driver core: bus: constify driver_find()
...
The driver_find() function can now take a const * to bus_type, not just
a * so fix that up.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313182918.1312597-26-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-23 13:21:22 +01:00
Greg Kroah-Hartman
9622b9f282
driver core: bus: constify bus_rescan_devices()
...
The bus_rescan_devices() function was missed in the previous change of
the bus_for_each* constant pointer changes, so fix it up now to take a
const * to struct bus_type.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313182918.1312597-25-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-23 13:21:20 +01:00
Greg Kroah-Hartman
00c4a3c47d
driver core: bus: constantify bus_register()
...
bus_register() is now safe to take a constant * to bus_type, so make
that change and mark the subsys_private bus_type * constant as well.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313182918.1312597-24-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-23 13:21:17 +01:00
Greg Kroah-Hartman
75cff725d9
driver core: bus: mark the struct bus_type for sysfs callbacks as constant
...
struct bus_type should never be modified in a sysfs callback as there is
nothing in the structure to modify, and frankly, the structure is almost
never used in a sysfs callback, so mark it as constant to allow struct
bus_type to be moved to read-only memory.
Cc: "David S. Miller" <davem@davemloft.net >
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com >
Cc: "K. Y. Srinivasan" <kys@microsoft.com >
Cc: Alexander Gordeev <agordeev@linux.ibm.com >
Cc: Alexandre Bounine <alex.bou9@gmail.com >
Cc: Alison Schofield <alison.schofield@intel.com >
Cc: Ben Widawsky <bwidawsk@kernel.org >
Cc: Dexuan Cui <decui@microsoft.com >
Cc: Eric Dumazet <edumazet@google.com >
Cc: Haiyang Zhang <haiyangz@microsoft.com >
Cc: Hannes Reinecke <hare@suse.de >
Cc: Harald Freudenberger <freude@linux.ibm.com >
Cc: Heiko Carstens <hca@linux.ibm.com >
Cc: Hu Haowen <src.res@email.cn >
Cc: Jakub Kicinski <kuba@kernel.org >
Cc: Jens Axboe <axboe@kernel.dk >
Cc: Jonathan Corbet <corbet@lwn.net >
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com >
Cc: Matt Porter <mporter@kernel.crashing.org >
Cc: Michael Ellerman <mpe@ellerman.id.au >
Cc: Paolo Abeni <pabeni@redhat.com >
Cc: Stuart Yoder <stuyoder@gmail.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Vishal Verma <vishal.l.verma@intel.com >
Cc: Yanteng Si <siyanteng@loongson.cn >
Acked-by: Ilya Dryomov <idryomov@gmail.com > # rbd
Acked-by: Ira Weiny <ira.weiny@intel.com > # cxl
Reviewed-by: Alex Shi <alexs@kernel.org >
Acked-by: Iwona Winiarska <iwona.winiarska@intel.com >
Acked-by: Dan Williams <dan.j.williams@intel.com >
Acked-by: Bjorn Helgaas <bhelgaas@google.com > # pci
Acked-by: Wei Liu <wei.liu@kernel.org >
Acked-by: Martin K. Petersen <martin.petersen@oracle.com > # scsi
Link: https://lore.kernel.org/r/20230313182918.1312597-23-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-23 13:20:40 +01:00
Greg Kroah-Hartman
9cc61e5fbd
driver core: bus: move dev_root out of struct bus_type
...
Now that all accesses of dev_root is through the bus_get_dev_root()
call, move the pointer out of struct bus_type and into the private
dynamic structure, subsys_private.
With this change, there is no modifiable portions of struct bus_type so
it can be marked as a constant structure and moved to read-only memory.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313182918.1312597-22-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-23 13:20:36 +01:00
Greg Kroah-Hartman
80842a9290
driver core: class: make class_create/remove_file*() options const
...
The class_create_file*() and class_remove_file*() functions do not
modify the struct class at all, so mark them as const * to enforce that.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313181843.1207845-8-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-17 15:16:41 +01:00
Greg Kroah-Hartman
cf41015ea8
driver core: class: make class_find_device*() options const
...
The class_find_device*() functions do not modify the struct class or the
struct device passed into it, so mark them as const * to enforce that.
Cc: "Rafael J. Wysocki" <rafael@kernel.org >
Link: https://lore.kernel.org/r/20230313181843.1207845-7-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
2023-03-17 15:16:39 +01:00