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

USB: Replace own str_plural with common one

Use existing str_plural() helper from string_choices.h to reduce amount
of duplicated code.

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

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
bd693544 47a836da

+11 -20
+7 -12
drivers/usb/core/config.c
··· 9 9 #include <linux/usb/quirks.h> 10 10 #include <linux/module.h> 11 11 #include <linux/slab.h> 12 + #include <linux/string_choices.h> 12 13 #include <linux/device.h> 13 14 #include <asm/byteorder.h> 14 15 #include "usb.h" ··· 18 17 #define USB_MAXALTSETTING 128 /* Hard limit */ 19 18 20 19 #define USB_MAXCONFIG 8 /* Arbitrary limit */ 21 - 22 - 23 - static inline const char *plural(int n) 24 - { 25 - return (n == 1 ? "" : "s"); 26 - } 27 20 28 21 static int find_next_descriptor(unsigned char *buffer, int size, 29 22 int dt1, int dt2, int *num_skipped) ··· 479 484 retval = buffer - buffer0 + i; 480 485 if (n > 0) 481 486 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 482 - n, plural(n), "endpoint"); 487 + n, str_plural(n), "endpoint"); 483 488 return retval; 484 489 485 490 skip_to_next_endpoint_or_interface_descriptor: ··· 558 563 alt->extralen = i; 559 564 if (n > 0) 560 565 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 561 - n, plural(n), "interface"); 566 + n, str_plural(n), "interface"); 562 567 buffer += i; 563 568 size -= i; 564 569 ··· 600 605 dev_notice(ddev, "config %d interface %d altsetting %d has %d " 601 606 "endpoint descriptor%s, different from the interface " 602 607 "descriptor's value: %d\n", 603 - cfgno, inum, asnum, n, plural(n), num_ep_orig); 608 + cfgno, inum, asnum, n, str_plural(n), num_ep_orig); 604 609 return buffer - buffer0; 605 610 606 611 skip_to_next_interface_descriptor: ··· 659 664 if (size2 < sizeof(struct usb_descriptor_header)) { 660 665 dev_notice(ddev, "config %d descriptor has %d excess " 661 666 "byte%s, ignoring\n", 662 - cfgno, size2, plural(size2)); 667 + cfgno, size2, str_plural(size2)); 663 668 break; 664 669 } 665 670 ··· 749 754 if (n != nintf) 750 755 dev_notice(ddev, "config %d has %d interface%s, different from " 751 756 "the descriptor's value: %d\n", 752 - cfgno, n, plural(n), nintf_orig); 757 + cfgno, n, str_plural(n), nintf_orig); 753 758 else if (n == 0) 754 759 dev_notice(ddev, "config %d has no interfaces?\n", cfgno); 755 760 config->desc.bNumInterfaces = nintf = n; ··· 793 798 config->extralen = i; 794 799 if (n > 0) 795 800 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 796 - n, plural(n), "configuration"); 801 + n, str_plural(n), "configuration"); 797 802 buffer += i; 798 803 size -= i; 799 804
+4 -8
drivers/usb/core/generic.c
··· 21 21 22 22 #include <linux/usb.h> 23 23 #include <linux/usb/hcd.h> 24 + #include <linux/string_choices.h> 24 25 #include <uapi/linux/usb/audio.h> 25 26 #include "usb.h" 26 - 27 - static inline const char *plural(int n) 28 - { 29 - return (n == 1 ? "" : "s"); 30 - } 31 27 32 28 static int is_rndis(struct usb_interface_descriptor *desc) 33 29 { ··· 190 194 if (insufficient_power > 0) 191 195 dev_info(&udev->dev, "rejected %d configuration%s " 192 196 "due to insufficient available bus power\n", 193 - insufficient_power, plural(insufficient_power)); 197 + insufficient_power, str_plural(insufficient_power)); 194 198 195 199 if (best) { 196 200 i = best->desc.bConfigurationValue; 197 201 dev_dbg(&udev->dev, 198 202 "configuration #%d chosen from %d choice%s\n", 199 - i, num_configs, plural(num_configs)); 203 + i, num_configs, str_plural(num_configs)); 200 204 } else { 201 205 i = -1; 202 206 dev_warn(&udev->dev, 203 207 "no configuration chosen from %d choice%s\n", 204 - num_configs, plural(num_configs)); 208 + num_configs, str_plural(num_configs)); 205 209 } 206 210 return i; 207 211 }