Skip to content

Commit bd69354

Browse files
krzkgregkh
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 47a836d commit bd69354

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

drivers/usb/core/config.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/usb/quirks.h>
1010
#include <linux/module.h>
1111
#include <linux/slab.h>
12+
#include <linux/string_choices.h>
1213
#include <linux/device.h>
1314
#include <asm/byteorder.h>
1415
#include "usb.h"
@@ -18,12 +19,6 @@
1819

1920
#define USB_MAXCONFIG 8 /* Arbitrary limit */
2021

21-
22-
static inline const char *plural(int n)
23-
{
24-
return (n == 1 ? "" : "s");
25-
}
26-
2722
static int find_next_descriptor(unsigned char *buffer, int size,
2823
int dt1, int dt2, int *num_skipped)
2924
{
@@ -484,7 +479,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
484479
retval = buffer - buffer0 + i;
485480
if (n > 0)
486481
dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
487-
n, plural(n), "endpoint");
482+
n, str_plural(n), "endpoint");
488483
return retval;
489484

490485
skip_to_next_endpoint_or_interface_descriptor:
@@ -563,7 +558,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
563558
alt->extralen = i;
564559
if (n > 0)
565560
dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
566-
n, plural(n), "interface");
561+
n, str_plural(n), "interface");
567562
buffer += i;
568563
size -= i;
569564

@@ -605,7 +600,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
605600
dev_notice(ddev, "config %d interface %d altsetting %d has %d "
606601
"endpoint descriptor%s, different from the interface "
607602
"descriptor's value: %d\n",
608-
cfgno, inum, asnum, n, plural(n), num_ep_orig);
603+
cfgno, inum, asnum, n, str_plural(n), num_ep_orig);
609604
return buffer - buffer0;
610605

611606
skip_to_next_interface_descriptor:
@@ -664,7 +659,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
664659
if (size2 < sizeof(struct usb_descriptor_header)) {
665660
dev_notice(ddev, "config %d descriptor has %d excess "
666661
"byte%s, ignoring\n",
667-
cfgno, size2, plural(size2));
662+
cfgno, size2, str_plural(size2));
668663
break;
669664
}
670665

@@ -754,7 +749,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
754749
if (n != nintf)
755750
dev_notice(ddev, "config %d has %d interface%s, different from "
756751
"the descriptor's value: %d\n",
757-
cfgno, n, plural(n), nintf_orig);
752+
cfgno, n, str_plural(n), nintf_orig);
758753
else if (n == 0)
759754
dev_notice(ddev, "config %d has no interfaces?\n", cfgno);
760755
config->desc.bNumInterfaces = nintf = n;
@@ -798,7 +793,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
798793
config->extralen = i;
799794
if (n > 0)
800795
dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
801-
n, plural(n), "configuration");
796+
n, str_plural(n), "configuration");
802797
buffer += i;
803798
size -= i;
804799

drivers/usb/core/generic.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@
2121

2222
#include <linux/usb.h>
2323
#include <linux/usb/hcd.h>
24+
#include <linux/string_choices.h>
2425
#include <uapi/linux/usb/audio.h>
2526
#include "usb.h"
2627

27-
static inline const char *plural(int n)
28-
{
29-
return (n == 1 ? "" : "s");
30-
}
31-
3228
static int is_rndis(struct usb_interface_descriptor *desc)
3329
{
3430
return desc->bInterfaceClass == USB_CLASS_COMM
@@ -194,18 +190,18 @@ int usb_choose_configuration(struct usb_device *udev)
194190
if (insufficient_power > 0)
195191
dev_info(&udev->dev, "rejected %d configuration%s "
196192
"due to insufficient available bus power\n",
197-
insufficient_power, plural(insufficient_power));
193+
insufficient_power, str_plural(insufficient_power));
198194

199195
if (best) {
200196
i = best->desc.bConfigurationValue;
201197
dev_dbg(&udev->dev,
202198
"configuration #%d chosen from %d choice%s\n",
203-
i, num_configs, plural(num_configs));
199+
i, num_configs, str_plural(num_configs));
204200
} else {
205201
i = -1;
206202
dev_warn(&udev->dev,
207203
"no configuration chosen from %d choice%s\n",
208-
num_configs, plural(num_configs));
204+
num_configs, str_plural(num_configs));
209205
}
210206
return i;
211207
}

0 commit comments

Comments
 (0)