USB: Replace own str_plural with common one
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tue, 14 Jan 2025 20:05:34 +0000 (21:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Jan 2025 17:28:12 +0000 (18:28 +0100)
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>
drivers/usb/core/config.c
drivers/usb/core/generic.c

index 25a00f974934fb5a562caf3f5f259ba23031e457..f7bf8d1de3adeb16a540ec5236726fc7b03517df 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/usb/quirks.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/string_choices.h>
 #include <linux/device.h>
 #include <asm/byteorder.h>
 #include "usb.h"
 
 #define USB_MAXCONFIG                  8       /* Arbitrary limit */
 
-
-static inline const char *plural(int n)
-{
-       return (n == 1 ? "" : "s");
-}
-
 static int find_next_descriptor(unsigned char *buffer, int size,
     int dt1, int dt2, int *num_skipped)
 {
@@ -484,7 +479,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
        retval = buffer - buffer0 + i;
        if (n > 0)
                dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
-                   n, plural(n), "endpoint");
+                   n, str_plural(n), "endpoint");
        return retval;
 
 skip_to_next_endpoint_or_interface_descriptor:
@@ -563,7 +558,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
        alt->extralen = i;
        if (n > 0)
                dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
-                   n, plural(n), "interface");
+                   n, str_plural(n), "interface");
        buffer += i;
        size -= i;
 
@@ -605,7 +600,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
                dev_notice(ddev, "config %d interface %d altsetting %d has %d "
                    "endpoint descriptor%s, different from the interface "
                    "descriptor's value: %d\n",
-                   cfgno, inum, asnum, n, plural(n), num_ep_orig);
+                   cfgno, inum, asnum, n, str_plural(n), num_ep_orig);
        return buffer - buffer0;
 
 skip_to_next_interface_descriptor:
@@ -664,7 +659,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
                if (size2 < sizeof(struct usb_descriptor_header)) {
                        dev_notice(ddev, "config %d descriptor has %d excess "
                            "byte%s, ignoring\n",
-                           cfgno, size2, plural(size2));
+                           cfgno, size2, str_plural(size2));
                        break;
                }
 
@@ -754,7 +749,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
        if (n != nintf)
                dev_notice(ddev, "config %d has %d interface%s, different from "
                    "the descriptor's value: %d\n",
-                   cfgno, n, plural(n), nintf_orig);
+                   cfgno, n, str_plural(n), nintf_orig);
        else if (n == 0)
                dev_notice(ddev, "config %d has no interfaces?\n", cfgno);
        config->desc.bNumInterfaces = nintf = n;
@@ -798,7 +793,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
        config->extralen = i;
        if (n > 0)
                dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
-                   n, plural(n), "configuration");
+                   n, str_plural(n), "configuration");
        buffer += i;
        size -= i;
 
index b134bff5c3fe3e86215bdcd14a2591a521f5ba3c..9c6ae5e1198bb2043d27e2f309a46f8ce512225f 100644 (file)
 
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/string_choices.h>
 #include <uapi/linux/usb/audio.h>
 #include "usb.h"
 
-static inline const char *plural(int n)
-{
-       return (n == 1 ? "" : "s");
-}
-
 static int is_rndis(struct usb_interface_descriptor *desc)
 {
        return desc->bInterfaceClass == USB_CLASS_COMM
@@ -194,18 +190,18 @@ int usb_choose_configuration(struct usb_device *udev)
        if (insufficient_power > 0)
                dev_info(&udev->dev, "rejected %d configuration%s "
                        "due to insufficient available bus power\n",
-                       insufficient_power, plural(insufficient_power));
+                       insufficient_power, str_plural(insufficient_power));
 
        if (best) {
                i = best->desc.bConfigurationValue;
                dev_dbg(&udev->dev,
                        "configuration #%d chosen from %d choice%s\n",
-                       i, num_configs, plural(num_configs));
+                       i, num_configs, str_plural(num_configs));
        } else {
                i = -1;
                dev_warn(&udev->dev,
                        "no configuration chosen from %d choice%s\n",
-                       num_configs, plural(num_configs));
+                       num_configs, str_plural(num_configs));
        }
        return i;
 }