Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: constify struct class usage

Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the structures typec_mux_class, retimer_class and
typec_class to be declared at build time placing them into read-only
memory, instead of having to be dynamically allocated at boot time.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240301-class_cleanup-usb-v1-1-50309e325095@marliere.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ricardo B. Marliere and committed by
Greg Kroah-Hartman
c40b51b3 a74c0c9c

+6 -6
+1 -1
drivers/usb/typec/class.c
··· 21 21 22 22 static DEFINE_IDA(typec_index_ida); 23 23 24 - struct class typec_class = { 24 + const struct class typec_class = { 25 25 .name = "typec", 26 26 }; 27 27
+3 -3
drivers/usb/typec/class.h
··· 93 93 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type) 94 94 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type) 95 95 96 - extern struct class typec_mux_class; 97 - extern struct class retimer_class; 98 - extern struct class typec_class; 96 + extern const struct class typec_mux_class; 97 + extern const struct class retimer_class; 98 + extern const struct class typec_class; 99 99 100 100 #if defined(CONFIG_ACPI) 101 101 int typec_link_ports(struct typec_port *connector);
+1 -1
drivers/usb/typec/mux.c
··· 469 469 } 470 470 EXPORT_SYMBOL_GPL(typec_mux_get_drvdata); 471 471 472 - struct class typec_mux_class = { 472 + const struct class typec_mux_class = { 473 473 .name = "typec_mux", 474 474 };
+1 -1
drivers/usb/typec/retimer.c
··· 155 155 } 156 156 EXPORT_SYMBOL_GPL(typec_retimer_get_drvdata); 157 157 158 - struct class retimer_class = { 158 + const struct class retimer_class = { 159 159 .name = "retimer", 160 160 };