Re: [PATCH 23/36] driver core: bus: mark the struct bus_type for sysfs callbacks as constant

From: Ira Weiny
Date: Mon Mar 13 2023 - 19:04:07 EST


Greg Kroah-Hartman wrote:
> 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@xxxxxxxxxxxxx>
> Cc: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>
> Cc: "K. Y. Srinivasan" <kys@xxxxxxxxxxxxx>
> Cc: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
> Cc: Alex Shi <alexs@xxxxxxxxxx>
> Cc: Alexander Gordeev <agordeev@xxxxxxxxxxxxx>
> Cc: Alexandre Bounine <alex.bou9@xxxxxxxxx>
> Cc: Alison Schofield <alison.schofield@xxxxxxxxx>
> Cc: Ben Widawsky <bwidawsk@xxxxxxxxxx>
> Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
> Cc: Dexuan Cui <decui@xxxxxxxxxxxxx>
> Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
> Cc: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>
> Cc: Hannes Reinecke <hare@xxxxxxx>
> Cc: Harald Freudenberger <freude@xxxxxxxxxxxxx>
> Cc: Heiko Carstens <hca@xxxxxxxxxxxxx>
> Cc: Hu Haowen <src.res@xxxxxxxx>
> Cc: Ilya Dryomov <idryomov@xxxxxxxxx>
> Cc: Ira Weiny <ira.weiny@xxxxxxxxx>
> Cc: Iwona Winiarska <iwona.winiarska@xxxxxxxxx>
> Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
> Cc: Jens Axboe <axboe@xxxxxxxxx>
> Cc: Jonathan Corbet <corbet@xxxxxxx>
> Cc: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>
> Cc: Matt Porter <mporter@xxxxxxxxxxxxxxxxxxx>
> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
> Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
> Cc: Stuart Yoder <stuyoder@xxxxxxxxx>
> Cc: Vasily Gorbik <gor@xxxxxxxxxxxxx>
> Cc: Vishal Verma <vishal.l.verma@xxxxxxxxx>
> Cc: Wei Liu <wei.liu@xxxxxxxxxx>
> Cc: Yanteng Si <siyanteng@xxxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

Acked-by: Ira Weiny <ira.weiny@xxxxxxxxx> # cxl

> ---
> Note, this is a patch that is a prepatory cleanup as part of a larger
> series of patches that is working on resolving some old driver core
> design mistakes. It will build and apply cleanly on top of 6.3-rc2 on
> its own, but I'd prefer if I could take it through my driver-core tree
> so that the driver core changes can be taken through there for 6.4-rc1.
>
> Documentation/driver-api/driver-model/bus.rst | 4 +-
> Documentation/filesystems/sysfs.rst | 4 +-
> .../translations/zh_CN/filesystems/sysfs.txt | 4 +-
> .../translations/zh_TW/filesystems/sysfs.txt | 4 +-
> arch/powerpc/platforms/pseries/ibmebus.c | 4 +-
> arch/powerpc/platforms/pseries/vio.c | 8 ++--
> drivers/ata/pata_parport/pata_parport.c | 6 +--
> drivers/base/bus.c | 8 ++--
> drivers/block/rbd.c | 34 +++++++--------
> drivers/bus/fsl-mc/fsl-mc-bus.c | 6 +--
> drivers/cxl/core/port.c | 2 +-
> drivers/hv/vmbus_drv.c | 2 +-
> drivers/net/netdevsim/bus.c | 4 +-
> drivers/pci/pci-sysfs.c | 2 +-
> drivers/pci/pci.c | 4 +-
> drivers/peci/sysfs.c | 2 +-
> drivers/rapidio/rio-sysfs.c | 2 +-
> drivers/s390/crypto/ap_bus.c | 42 +++++++++----------
> drivers/scsi/fcoe/fcoe_sysfs.c | 8 ++--
> drivers/scsi/fcoe/fcoe_transport.c | 6 +--
> include/linux/device/bus.h | 4 +-
> include/scsi/libfcoe.h | 6 +--
> 22 files changed, 78 insertions(+), 88 deletions(-)
>

[...]

> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index 8ee6b6e2e2a4..66333cd6248e 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -1927,7 +1927,7 @@ bool schedule_cxl_memdev_detach(struct cxl_memdev *cxlmd)
> EXPORT_SYMBOL_NS_GPL(schedule_cxl_memdev_detach, CXL);
>
> /* for user tooling to ensure port disable work has completed */
> -static ssize_t flush_store(struct bus_type *bus, const char *buf, size_t count)
> +static ssize_t flush_store(const struct bus_type *bus, const char *buf, size_t count)
> {
> if (sysfs_streq(buf, "1")) {
> flush_workqueue(cxl_bus_wq);