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

USB: gadget: 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-5-c8405df47c19@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
5b6dc50e 2d913c1b

+27 -17
+2 -2
drivers/usb/gadget/function/f_ecm.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/device.h> 15 15 #include <linux/etherdevice.h> 16 + #include <linux/string_choices.h> 16 17 17 18 #include "u_ether.h" 18 19 #include "u_ether_configfs.h" ··· 388 387 event->wLength = 0; 389 388 req->length = sizeof *event; 390 389 391 - DBG(cdev, "notify connect %s\n", 392 - ecm->is_open ? "true" : "false"); 390 + DBG(cdev, "notify connect %s\n", str_true_false(ecm->is_open)); 393 391 ecm->notify_state = ECM_NOTIFY_SPEED; 394 392 break; 395 393
+2 -1
drivers/usb/gadget/function/f_ncm.c
··· 17 17 #include <linux/device.h> 18 18 #include <linux/etherdevice.h> 19 19 #include <linux/crc32.h> 20 + #include <linux/string_choices.h> 20 21 21 22 #include <linux/usb/cdc.h> 22 23 ··· 559 558 req->length = sizeof *event; 560 559 561 560 DBG(cdev, "notify connect %s\n", 562 - ncm->is_open ? "true" : "false"); 561 + str_true_false(ncm->is_open)); 563 562 ncm->notify_state = NCM_NOTIFY_NONE; 564 563 break; 565 564
+2 -1
drivers/usb/gadget/function/u_serial.c
··· 21 21 #include <linux/tty.h> 22 22 #include <linux/tty_flip.h> 23 23 #include <linux/slab.h> 24 + #include <linux/string_choices.h> 24 25 #include <linux/export.h> 25 26 #include <linux/module.h> 26 27 #include <linux/console.h> ··· 1546 1545 1547 1546 pr_debug("%s: registered %d ttyGS* device%s\n", __func__, 1548 1547 MAX_U_SERIAL_PORTS, 1549 - (MAX_U_SERIAL_PORTS == 1) ? "" : "s"); 1548 + str_plural(MAX_U_SERIAL_PORTS)); 1550 1549 1551 1550 return status; 1552 1551 fail:
+2 -1
drivers/usb/gadget/legacy/inode.c
··· 20 20 #include <linux/uaccess.h> 21 21 #include <linux/sched.h> 22 22 #include <linux/slab.h> 23 + #include <linux/string_choices.h> 23 24 #include <linux/poll.h> 24 25 #include <linux/kthread.h> 25 26 #include <linux/aio.h> ··· 1183 1182 { 1184 1183 struct dev_data *dev = fd->private_data; 1185 1184 // caller must F_SETOWN before signal delivery happens 1186 - VDEBUG (dev, "%s %s\n", __func__, on ? "on" : "off"); 1185 + VDEBUG(dev, "%s %s\n", __func__, str_on_off(on)); 1187 1186 return fasync_helper (f, fd, on, &dev->fasync); 1188 1187 } 1189 1188
+2 -1
drivers/usb/gadget/udc/aspeed-vhub/hub.c
··· 22 22 #include <linux/usb/gadget.h> 23 23 #include <linux/of.h> 24 24 #include <linux/regmap.h> 25 + #include <linux/string_choices.h> 25 26 #include <linux/dma-mapping.h> 26 27 #include <linux/bcd.h> 27 28 #include <linux/version.h> ··· 220 219 if (wValue == USB_DEVICE_REMOTE_WAKEUP) { 221 220 ep->vhub->wakeup_en = is_set; 222 221 EPDBG(ep, "Hub remote wakeup %s\n", 223 - is_set ? "enabled" : "disabled"); 222 + str_enabled_disabled(is_set)); 224 223 return std_req_complete; 225 224 } 226 225
+2 -1
drivers/usb/gadget/udc/at91_udc.c
··· 16 16 #include <linux/delay.h> 17 17 #include <linux/ioport.h> 18 18 #include <linux/slab.h> 19 + #include <linux/string_choices.h> 19 20 #include <linux/errno.h> 20 21 #include <linux/list.h> 21 22 #include <linux/interrupt.h> ··· 132 131 seq_printf(s, "csr %08x rxbytes=%d %s %s %s" EIGHTBITS "\n", 133 132 csr, 134 133 (csr & 0x07ff0000) >> 16, 135 - (csr & (1 << 15)) ? "enabled" : "disabled", 134 + str_enabled_disabled(csr & (1 << 15)), 136 135 (csr & (1 << 11)) ? "DATA1" : "DATA0", 137 136 types[(csr & 0x700) >> 8], 138 137
+7 -6
drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
··· 29 29 #include <linux/pm_runtime.h> 30 30 #include <linux/interrupt.h> 31 31 #include <linux/property.h> 32 + #include <linux/string_choices.h> 32 33 #include <linux/dmapool.h> 33 34 #include <linux/iopoll.h> 34 35 ··· 2234 2233 dev_dbg(pdev->dev, "Init %s, SupType: CTRL: %s, INT: %s, " 2235 2234 "BULK: %s, ISOC %s, SupDir IN: %s, OUT: %s\n", 2236 2235 pep->name, 2237 - (pep->endpoint.caps.type_control) ? "yes" : "no", 2238 - (pep->endpoint.caps.type_int) ? "yes" : "no", 2239 - (pep->endpoint.caps.type_bulk) ? "yes" : "no", 2240 - (pep->endpoint.caps.type_iso) ? "yes" : "no", 2241 - (pep->endpoint.caps.dir_in) ? "yes" : "no", 2242 - (pep->endpoint.caps.dir_out) ? "yes" : "no"); 2236 + str_yes_no(pep->endpoint.caps.type_control), 2237 + str_yes_no(pep->endpoint.caps.type_int), 2238 + str_yes_no(pep->endpoint.caps.type_bulk), 2239 + str_yes_no(pep->endpoint.caps.type_iso), 2240 + str_yes_no(pep->endpoint.caps.dir_in), 2241 + str_yes_no(pep->endpoint.caps.dir_out)); 2243 2242 2244 2243 INIT_LIST_HEAD(&pep->pending_list); 2245 2244 INIT_LIST_HEAD(&pep->deferred_list);
+2 -1
drivers/usb/gadget/udc/dummy_hcd.c
··· 28 28 #include <linux/delay.h> 29 29 #include <linux/ioport.h> 30 30 #include <linux/slab.h> 31 + #include <linux/string_choices.h> 31 32 #include <linux/errno.h> 32 33 #include <linux/init.h> 33 34 #include <linux/hrtimer.h> ··· 626 625 desc->bEndpointAddress & 0x0f, 627 626 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 628 627 usb_ep_type_string(usb_endpoint_type(desc)), 629 - max, ep->stream_en ? "enabled" : "disabled"); 628 + max, str_enabled_disabled(ep->stream_en)); 630 629 631 630 /* at this point real hardware should be NAKing transfers 632 631 * to that endpoint, until a buffer is queued to it.
+2 -1
drivers/usb/gadget/udc/fsl_udc_core.c
··· 22 22 #include <linux/errno.h> 23 23 #include <linux/err.h> 24 24 #include <linux/slab.h> 25 + #include <linux/string_choices.h> 25 26 #include <linux/init.h> 26 27 #include <linux/list.h> 27 28 #include <linux/interrupt.h> ··· 1182 1181 1183 1182 udc = container_of(gadget, struct fsl_udc, gadget); 1184 1183 spin_lock_irqsave(&udc->lock, flags); 1185 - dev_vdbg(&gadget->dev, "VBUS %s\n", is_active ? "on" : "off"); 1184 + dev_vdbg(&gadget->dev, "VBUS %s\n", str_on_off(is_active)); 1186 1185 udc->vbus_active = (is_active != 0); 1187 1186 if (can_pullup(udc)) 1188 1187 fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+2 -1
drivers/usb/gadget/udc/omap_udc.c
··· 18 18 #include <linux/errno.h> 19 19 #include <linux/delay.h> 20 20 #include <linux/slab.h> 21 + #include <linux/string_choices.h> 21 22 #include <linux/timer.h> 22 23 #include <linux/list.h> 23 24 #include <linux/interrupt.h> ··· 1253 1252 1254 1253 udc = container_of(gadget, struct omap_udc, gadget); 1255 1254 spin_lock_irqsave(&udc->lock, flags); 1256 - VDBG("VBUS %s\n", is_active ? "on" : "off"); 1255 + VDBG("VBUS %s\n", str_on_off(is_active)); 1257 1256 udc->vbus_active = (is_active != 0); 1258 1257 if (cpu_is_omap15xx()) { 1259 1258 /* "software" detect, ignored if !VBUS_MODE_1510 */
+2 -1
drivers/usb/gadget/udc/pxa27x_udc.c
··· 20 20 #include <linux/gpio.h> 21 21 #include <linux/gpio/consumer.h> 22 22 #include <linux/slab.h> 23 + #include <linux/string_choices.h> 23 24 #include <linux/prefetch.h> 24 25 #include <linux/byteorder/generic.h> 25 26 #include <linux/platform_data/pxa2xx_udc.h> ··· 1084 1083 1085 1084 is_first_req = list_empty(&ep->queue); 1086 1085 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n", 1087 - _req, is_first_req ? "yes" : "no", 1086 + _req, str_yes_no(is_first_req), 1088 1087 _req->length, _req->buf); 1089 1088 1090 1089 if (!ep->enabled) {