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

USB: Use str_enable_disable-like helpers

Replace ternary (condition ? "enable" : "disable") syntax with helpers
from string_choices.h because:
1. Simple function call with one argument is easier to read. Ternary
operator has three arguments and with wrapping might lead to quite
long code.
2. Is slightly shorter thus also easier to read.
3. It brings uniformity in the text - same string.
4. Allows deduping by the linker, which results in a smaller binary
file.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20250114-str-enable-disable-usb-v1-6-c8405df47c19@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
f386bfad 5b6dc50e

+41 -27
+7 -6
drivers/usb/cdns3/cdnsp-gadget.c
··· 15 15 #include <linux/delay.h> 16 16 #include <linux/log2.h> 17 17 #include <linux/slab.h> 18 + #include <linux/string_choices.h> 18 19 #include <linux/pci.h> 19 20 #include <linux/irq.h> 20 21 #include <linux/dmi.h> ··· 1672 1671 "CTRL: %s, INT: %s, BULK: %s, ISOC %s, " 1673 1672 "SupDir IN: %s, OUT: %s\n", 1674 1673 pep->name, 1024, 1675 - (pep->endpoint.caps.type_control) ? "yes" : "no", 1676 - (pep->endpoint.caps.type_int) ? "yes" : "no", 1677 - (pep->endpoint.caps.type_bulk) ? "yes" : "no", 1678 - (pep->endpoint.caps.type_iso) ? "yes" : "no", 1679 - (pep->endpoint.caps.dir_in) ? "yes" : "no", 1680 - (pep->endpoint.caps.dir_out) ? "yes" : "no"); 1674 + str_yes_no(pep->endpoint.caps.type_control), 1675 + str_yes_no(pep->endpoint.caps.type_int), 1676 + str_yes_no(pep->endpoint.caps.type_bulk), 1677 + str_yes_no(pep->endpoint.caps.type_iso), 1678 + str_yes_no(pep->endpoint.caps.dir_in), 1679 + str_yes_no(pep->endpoint.caps.dir_out)); 1681 1680 1682 1681 INIT_LIST_HEAD(&pep->pending_list); 1683 1682 }
+2 -1
drivers/usb/chipidea/host.c
··· 13 13 #include <linux/usb/hcd.h> 14 14 #include <linux/usb/chipidea.h> 15 15 #include <linux/regulator/consumer.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/pinctrl/consumer.h> 17 18 18 19 #include "../host/ehci.h" ··· 57 56 if (ret) { 58 57 dev_err(dev, 59 58 "Failed to %s vbus regulator, ret=%d\n", 60 - enable ? "enable" : "disable", ret); 59 + str_enable_disable(enable), ret); 61 60 return ret; 62 61 } 63 62 priv->enabled = enable;
+2 -1
drivers/usb/common/usb-conn-gpio.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/power_supply.h> 21 21 #include <linux/regulator/consumer.h> 22 + #include <linux/string_choices.h> 22 23 #include <linux/usb/role.h> 23 24 24 25 #define USB_GPIO_DEB_MS 20 /* ms */ ··· 112 111 113 112 if (info->vbus) 114 113 dev_dbg(info->dev, "vbus regulator is %s\n", 115 - regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); 114 + str_enabled_disabled(regulator_is_enabled(info->vbus))); 116 115 117 116 power_supply_changed(info->charger); 118 117 }
+5 -5
drivers/usb/core/hub.c
··· 18 18 #include <linux/sched/mm.h> 19 19 #include <linux/list.h> 20 20 #include <linux/slab.h> 21 + #include <linux/string_choices.h> 21 22 #include <linux/kcov.h> 22 23 #include <linux/ioctl.h> 23 24 #include <linux/usb.h> ··· 1497 1496 1498 1497 maxchild = hub->descriptor->bNbrPorts; 1499 1498 dev_info(hub_dev, "%d port%s detected\n", maxchild, 1500 - (maxchild == 1) ? "" : "s"); 1499 + str_plural(maxchild)); 1501 1500 1502 1501 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); 1503 1502 if (!hub->ports) { ··· 4140 4139 break; 4141 4140 default: 4142 4141 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", 4143 - __func__, enable ? "enable" : "disable"); 4142 + __func__, str_enable_disable(enable)); 4144 4143 return -EINVAL; 4145 4144 } 4146 4145 4147 4146 if (udev->state != USB_STATE_CONFIGURED) { 4148 4147 dev_dbg(&udev->dev, "%s: Can't %s %s state " 4149 4148 "for unconfigured device.\n", 4150 - __func__, enable ? "enable" : "disable", 4149 + __func__, str_enable_disable(enable), 4151 4150 usb3_lpm_names[state]); 4152 4151 return 0; 4153 4152 } ··· 4173 4172 } 4174 4173 if (ret < 0) { 4175 4174 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", 4176 - enable ? "Enable" : "Disable", 4177 - usb3_lpm_names[state]); 4175 + str_enable_disable(enable), usb3_lpm_names[state]); 4178 4176 return -EBUSY; 4179 4177 } 4180 4178 return 0;
+2 -1
drivers/usb/core/port.c
··· 9 9 10 10 #include <linux/kstrtox.h> 11 11 #include <linux/slab.h> 12 + #include <linux/string_choices.h> 12 13 #include <linux/sysfs.h> 13 14 #include <linux/pm_qos.h> 14 15 #include <linux/component.h> ··· 26 25 { 27 26 struct usb_port *port_dev = to_usb_port(dev); 28 27 29 - return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no"); 28 + return sysfs_emit(buf, "%s\n", str_yes_no(port_dev->early_stop)); 30 29 } 31 30 32 31 static ssize_t early_stop_store(struct device *dev, struct device_attribute *attr,
+3 -2
drivers/usb/fotg210/fotg210-core.c
··· 13 13 #include <linux/of.h> 14 14 #include <linux/platform_device.h> 15 15 #include <linux/regmap.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/usb.h> 17 18 #include <linux/usb/otg.h> 18 19 ··· 120 119 ret = regmap_update_bits(fotg->map, GEMINI_GLOBAL_MISC_CTRL, mask, val); 121 120 if (ret) 122 121 dev_err(fotg->dev, "failed to %s VBUS\n", 123 - enable ? "enable" : "disable"); 124 - dev_info(fotg->dev, "%s: %s VBUS\n", __func__, enable ? "enable" : "disable"); 122 + str_enable_disable(enable)); 123 + dev_info(fotg->dev, "%s: %s VBUS\n", __func__, str_enable_disable(enable)); 125 124 } 126 125 127 126 static int fotg210_probe(struct platform_device *pdev)
+2 -1
drivers/usb/mtu3/mtu3_debugfs.c
··· 7 7 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 8 8 */ 9 9 10 + #include <linux/string_choices.h> 10 11 #include <linux/uaccess.h> 11 12 12 13 #include "mtu3.h" ··· 480 479 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; 481 480 482 481 seq_printf(sf, "vbus state: %s\n(echo on/off)\n", 483 - regulator_is_enabled(otg_sx->vbus) ? "on" : "off"); 482 + str_on_off(regulator_is_enabled(otg_sx->vbus))); 484 483 485 484 return 0; 486 485 }
+2 -1
drivers/usb/mtu3/mtu3_dr.c
··· 7 7 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 8 8 */ 9 9 10 + #include <linux/string_choices.h> 10 11 #include "mtu3.h" 11 12 #include "mtu3_dr.h" 12 13 #include "mtu3_debug.h" ··· 110 109 if (!vbus) 111 110 return 0; 112 111 113 - dev_dbg(ssusb->dev, "%s: turn %s\n", __func__, is_on ? "on" : "off"); 112 + dev_dbg(ssusb->dev, "%s: turn %s\n", __func__, str_on_off(is_on)); 114 113 115 114 if (is_on) { 116 115 ret = regulator_enable(vbus);
+2 -1
drivers/usb/mtu3/mtu3_gadget.c
··· 7 7 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 8 8 */ 9 9 10 + #include <linux/string_choices.h> 10 11 #include "mtu3.h" 11 12 #include "mtu3_trace.h" 12 13 ··· 491 490 unsigned long flags; 492 491 493 492 dev_dbg(mtu->dev, "%s (%s) for %sactive device\n", __func__, 494 - is_on ? "on" : "off", mtu->is_active ? "" : "in"); 493 + str_on_off(is_on), mtu->is_active ? "" : "in"); 495 494 496 495 pm_runtime_get_sync(mtu->dev); 497 496
+2 -1
drivers/usb/musb/da8xx.c
··· 21 21 #include <linux/of_platform.h> 22 22 #include <linux/phy/phy.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/string_choices.h> 24 25 #include <linux/dma-mapping.h> 25 26 #include <linux/usb/usb_phy_generic.h> 26 27 ··· 307 306 } 308 307 309 308 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 310 - drvvbus ? "on" : "off", 309 + str_on_off(drvvbus), 311 310 usb_otg_state_string(musb->xceiv->otg->state), 312 311 err ? " ERROR" : "", 313 312 devctl);
+2 -1
drivers/usb/musb/musb_core.c
··· 72 72 #include <linux/kobject.h> 73 73 #include <linux/prefetch.h> 74 74 #include <linux/platform_device.h> 75 + #include <linux/string_choices.h> 75 76 #include <linux/io.h> 76 77 #include <linux/iopoll.h> 77 78 #include <linux/dma-mapping.h> ··· 1938 1937 pm_runtime_put_sync(dev); 1939 1938 1940 1939 return sprintf(buf, "Vbus %s, timeout %lu msec\n", 1941 - vbus ? "on" : "off", val); 1940 + str_on_off(vbus), val); 1942 1941 } 1943 1942 static DEVICE_ATTR_RW(vbus); 1944 1943
+2 -1
drivers/usb/musb/musb_dsps.c
··· 24 24 #include <linux/usb/usb_phy_generic.h> 25 25 #include <linux/platform_data/usb-omap.h> 26 26 #include <linux/sizes.h> 27 + #include <linux/string_choices.h> 27 28 28 29 #include <linux/of.h> 29 30 #include <linux/of_address.h> ··· 379 378 380 379 /* NOTE: this must complete power-on within 100 ms. */ 381 380 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 382 - drvvbus ? "on" : "off", 381 + str_on_off(drvvbus), 383 382 usb_otg_state_string(musb->xceiv->otg->state), 384 383 err ? " ERROR" : "", 385 384 devctl);
+2 -1
drivers/usb/musb/musb_gadget.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/smp.h> 16 16 #include <linux/spinlock.h> 17 + #include <linux/string_choices.h> 17 18 #include <linux/delay.h> 18 19 #include <linux/dma-mapping.h> 19 20 #include <linux/slab.h> ··· 1607 1606 /* FIXME if on, HdrcStart; if off, HdrcStop */ 1608 1607 1609 1608 musb_dbg(musb, "gadget D+ pullup %s", 1610 - is_on ? "on" : "off"); 1609 + str_on_off(is_on)); 1611 1610 musb_writeb(musb->mregs, MUSB_POWER, power); 1612 1611 } 1613 1612
+2 -1
drivers/usb/musb/musb_host.c
··· 13 13 #include <linux/delay.h> 14 14 #include <linux/sched.h> 15 15 #include <linux/slab.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/errno.h> 17 18 #include <linux/list.h> 18 19 #include <linux/dma-mapping.h> ··· 1029 1028 + urb->actual_length); 1030 1029 musb_dbg(musb, "Sending %d byte%s to ep0 fifo %p", 1031 1030 fifo_count, 1032 - (fifo_count == 1) ? "" : "s", 1031 + str_plural(fifo_count), 1033 1032 fifo_dest); 1034 1033 musb_write_fifo(hw_ep, fifo_count, fifo_dest); 1035 1034
+2 -2
drivers/usb/storage/shuttle_usbat.c
··· 32 32 #include <linux/errno.h> 33 33 #include <linux/module.h> 34 34 #include <linux/slab.h> 35 + #include <linux/string_choices.h> 35 36 #include <linux/cdrom.h> 36 37 37 38 #include <scsi/scsi.h> ··· 652 651 return USB_STOR_TRANSPORT_FAILED; 653 652 654 653 usb_stor_dbg(us, "Redoing %s\n", 655 - direction == DMA_TO_DEVICE 656 - ? "write" : "read"); 654 + str_write_read(direction == DMA_TO_DEVICE)); 657 655 658 656 } else if (result != USB_STOR_XFER_GOOD) 659 657 return USB_STOR_TRANSPORT_ERROR;
+2 -1
drivers/usb/usbip/vhci_hcd.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/platform_device.h> 13 13 #include <linux/slab.h> 14 + #include <linux/string_choices.h> 14 15 15 16 #include "usbip_common.h" 16 17 #include "vhci.h" ··· 1450 1449 if (connected > 0) { 1451 1450 dev_info(&pdev->dev, 1452 1451 "We have %d active connection%s. Do not suspend.\n", 1453 - connected, (connected == 1 ? "" : "s")); 1452 + connected, str_plural(connected)); 1454 1453 ret = -EBUSY; 1455 1454 } else { 1456 1455 dev_info(&pdev->dev, "suspend vhci_hcd");