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

usb: typec: constify the struct device_type usage

Since commit aed65af1cc2f ("drivers: make device_type const"), the driver
core can properly handle constant struct device_type. Move all the
device_type variables in use by the driver to be constant structures as
well, placing it into read-only memory which can not be modified at
runtime.

Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240218-device_cleanup-usb-v1-1-77423c4da262@marliere.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ricardo B. Marliere and committed by
Greg Kroah-Hartman
146bb64e a09ebb32

+15 -15
+15 -15
drivers/usb/typec/pd.c
··· 157 157 }; 158 158 __ATTRIBUTE_GROUPS(source_fixed_supply); 159 159 160 - static struct device_type source_fixed_supply_type = { 160 + static const struct device_type source_fixed_supply_type = { 161 161 .name = "pdo", 162 162 .release = pdo_release, 163 163 .groups = source_fixed_supply_groups, ··· 182 182 }; 183 183 __ATTRIBUTE_GROUPS(sink_fixed_supply); 184 184 185 - static struct device_type sink_fixed_supply_type = { 185 + static const struct device_type sink_fixed_supply_type = { 186 186 .name = "pdo", 187 187 .release = pdo_release, 188 188 .groups = sink_fixed_supply_groups, ··· 213 213 }; 214 214 ATTRIBUTE_GROUPS(source_variable_supply); 215 215 216 - static struct device_type source_variable_supply_type = { 216 + static const struct device_type source_variable_supply_type = { 217 217 .name = "pdo", 218 218 .release = pdo_release, 219 219 .groups = source_variable_supply_groups, ··· 227 227 }; 228 228 ATTRIBUTE_GROUPS(sink_variable_supply); 229 229 230 - static struct device_type sink_variable_supply_type = { 230 + static const struct device_type sink_variable_supply_type = { 231 231 .name = "pdo", 232 232 .release = pdo_release, 233 233 .groups = sink_variable_supply_groups, ··· 258 258 }; 259 259 ATTRIBUTE_GROUPS(source_battery); 260 260 261 - static struct device_type source_battery_type = { 261 + static const struct device_type source_battery_type = { 262 262 .name = "pdo", 263 263 .release = pdo_release, 264 264 .groups = source_battery_groups, ··· 272 272 }; 273 273 ATTRIBUTE_GROUPS(sink_battery); 274 274 275 - static struct device_type sink_battery_type = { 275 + static const struct device_type sink_battery_type = { 276 276 .name = "pdo", 277 277 .release = pdo_release, 278 278 .groups = sink_battery_groups, ··· 339 339 }; 340 340 ATTRIBUTE_GROUPS(source_pps); 341 341 342 - static struct device_type source_pps_type = { 342 + static const struct device_type source_pps_type = { 343 343 .name = "pdo", 344 344 .release = pdo_release, 345 345 .groups = source_pps_groups, ··· 353 353 }; 354 354 ATTRIBUTE_GROUPS(sink_pps); 355 355 356 - static struct device_type sink_pps_type = { 356 + static const struct device_type sink_pps_type = { 357 357 .name = "pdo", 358 358 .release = pdo_release, 359 359 .groups = sink_pps_groups, ··· 371 371 [APDO_TYPE_PPS] = "programmable_supply", 372 372 }; 373 373 374 - static struct device_type *source_type[] = { 374 + static const struct device_type *source_type[] = { 375 375 [PDO_TYPE_FIXED] = &source_fixed_supply_type, 376 376 [PDO_TYPE_BATT] = &source_battery_type, 377 377 [PDO_TYPE_VAR] = &source_variable_supply_type, 378 378 }; 379 379 380 - static struct device_type *source_apdo_type[] = { 380 + static const struct device_type *source_apdo_type[] = { 381 381 [APDO_TYPE_PPS] = &source_pps_type, 382 382 }; 383 383 384 - static struct device_type *sink_type[] = { 384 + static const struct device_type *sink_type[] = { 385 385 [PDO_TYPE_FIXED] = &sink_fixed_supply_type, 386 386 [PDO_TYPE_BATT] = &sink_battery_type, 387 387 [PDO_TYPE_VAR] = &sink_variable_supply_type, 388 388 }; 389 389 390 - static struct device_type *sink_apdo_type[] = { 390 + static const struct device_type *sink_apdo_type[] = { 391 391 [APDO_TYPE_PPS] = &sink_pps_type, 392 392 }; 393 393 394 394 /* REVISIT: Export when EPR_*_Capabilities need to be supported. */ 395 395 static int add_pdo(struct usb_power_delivery_capabilities *cap, u32 pdo, int position) 396 396 { 397 - struct device_type *type; 397 + const struct device_type *type; 398 398 const char *name; 399 399 struct pdo *p; 400 400 int ret; ··· 460 460 kfree(to_usb_power_delivery_capabilities(dev)); 461 461 } 462 462 463 - static struct device_type pd_capabilities_type = { 463 + static const struct device_type pd_capabilities_type = { 464 464 .name = "capabilities", 465 465 .release = pd_capabilities_release, 466 466 }; ··· 575 575 kfree(pd); 576 576 } 577 577 578 - static struct device_type pd_type = { 578 + static const struct device_type pd_type = { 579 579 .name = "usb_power_delivery", 580 580 .release = pd_release, 581 581 .groups = pd_groups,