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

From: Wei Liu
Date: Mon Mar 13 2023 - 18:42:01 EST


On Mon, Mar 13, 2023 at 07:29:05PM +0100, 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.
[...]
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index d24dd65b33d4..513adba09f56 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -684,7 +684,7 @@ static const struct attribute_group vmbus_dev_group = {
> __ATTRIBUTE_GROUPS(vmbus_dev);
>
> /* Set up the attribute for /sys/bus/vmbus/hibernation */
> -static ssize_t hibernation_show(struct bus_type *bus, char *buf)
> +static ssize_t hibernation_show(const struct bus_type *bus, char *buf)
> {
> return sprintf(buf, "%d\n", !!hv_is_hibernation_supported());
> }

Acked-by: Wei Liu <wei.liu@xxxxxxxxxx>