Skip to content

Commit f386bfa

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

File tree

16 files changed

+41
-27
lines changed

16 files changed

+41
-27
lines changed

drivers/usb/cdns3/cdnsp-gadget.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/delay.h>
1616
#include <linux/log2.h>
1717
#include <linux/slab.h>
18+
#include <linux/string_choices.h>
1819
#include <linux/pci.h>
1920
#include <linux/irq.h>
2021
#include <linux/dmi.h>
@@ -1671,12 +1672,12 @@ static int cdnsp_gadget_init_endpoints(struct cdnsp_device *pdev)
16711672
"CTRL: %s, INT: %s, BULK: %s, ISOC %s, "
16721673
"SupDir IN: %s, OUT: %s\n",
16731674
pep->name, 1024,
1674-
(pep->endpoint.caps.type_control) ? "yes" : "no",
1675-
(pep->endpoint.caps.type_int) ? "yes" : "no",
1676-
(pep->endpoint.caps.type_bulk) ? "yes" : "no",
1677-
(pep->endpoint.caps.type_iso) ? "yes" : "no",
1678-
(pep->endpoint.caps.dir_in) ? "yes" : "no",
1679-
(pep->endpoint.caps.dir_out) ? "yes" : "no");
1675+
str_yes_no(pep->endpoint.caps.type_control),
1676+
str_yes_no(pep->endpoint.caps.type_int),
1677+
str_yes_no(pep->endpoint.caps.type_bulk),
1678+
str_yes_no(pep->endpoint.caps.type_iso),
1679+
str_yes_no(pep->endpoint.caps.dir_in),
1680+
str_yes_no(pep->endpoint.caps.dir_out));
16801681

16811682
INIT_LIST_HEAD(&pep->pending_list);
16821683
}

drivers/usb/chipidea/host.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/usb/hcd.h>
1414
#include <linux/usb/chipidea.h>
1515
#include <linux/regulator/consumer.h>
16+
#include <linux/string_choices.h>
1617
#include <linux/pinctrl/consumer.h>
1718

1819
#include "../host/ehci.h"
@@ -56,7 +57,7 @@ static int ehci_ci_portpower(struct usb_hcd *hcd, int portnum, bool enable)
5657
if (ret) {
5758
dev_err(dev,
5859
"Failed to %s vbus regulator, ret=%d\n",
59-
enable ? "enable" : "disable", ret);
60+
str_enable_disable(enable), ret);
6061
return ret;
6162
}
6263
priv->enabled = enable;

drivers/usb/common/usb-conn-gpio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/platform_device.h>
2020
#include <linux/power_supply.h>
2121
#include <linux/regulator/consumer.h>
22+
#include <linux/string_choices.h>
2223
#include <linux/usb/role.h>
2324

2425
#define USB_GPIO_DEB_MS 20 /* ms */
@@ -111,7 +112,7 @@ static void usb_conn_detect_cable(struct work_struct *work)
111112

112113
if (info->vbus)
113114
dev_dbg(info->dev, "vbus regulator is %s\n",
114-
regulator_is_enabled(info->vbus) ? "enabled" : "disabled");
115+
str_enabled_disabled(regulator_is_enabled(info->vbus)));
115116

116117
power_supply_changed(info->charger);
117118
}

drivers/usb/core/hub.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/sched/mm.h>
1919
#include <linux/list.h>
2020
#include <linux/slab.h>
21+
#include <linux/string_choices.h>
2122
#include <linux/kcov.h>
2223
#include <linux/ioctl.h>
2324
#include <linux/usb.h>
@@ -1496,7 +1497,7 @@ static int hub_configure(struct usb_hub *hub,
14961497

14971498
maxchild = hub->descriptor->bNbrPorts;
14981499
dev_info(hub_dev, "%d port%s detected\n", maxchild,
1499-
(maxchild == 1) ? "" : "s");
1500+
str_plural(maxchild));
15001501

15011502
hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL);
15021503
if (!hub->ports) {
@@ -4139,14 +4140,14 @@ static int usb_set_device_initiated_lpm(struct usb_device *udev,
41394140
break;
41404141
default:
41414142
dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n",
4142-
__func__, enable ? "enable" : "disable");
4143+
__func__, str_enable_disable(enable));
41434144
return -EINVAL;
41444145
}
41454146

41464147
if (udev->state != USB_STATE_CONFIGURED) {
41474148
dev_dbg(&udev->dev, "%s: Can't %s %s state "
41484149
"for unconfigured device.\n",
4149-
__func__, enable ? "enable" : "disable",
4150+
__func__, str_enable_disable(enable),
41504151
usb3_lpm_names[state]);
41514152
return 0;
41524153
}
@@ -4172,8 +4173,7 @@ static int usb_set_device_initiated_lpm(struct usb_device *udev,
41724173
}
41734174
if (ret < 0) {
41744175
dev_warn(&udev->dev, "%s of device-initiated %s failed.\n",
4175-
enable ? "Enable" : "Disable",
4176-
usb3_lpm_names[state]);
4176+
str_enable_disable(enable), usb3_lpm_names[state]);
41774177
return -EBUSY;
41784178
}
41794179
return 0;

drivers/usb/core/port.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/kstrtox.h>
1111
#include <linux/slab.h>
12+
#include <linux/string_choices.h>
1213
#include <linux/sysfs.h>
1314
#include <linux/pm_qos.h>
1415
#include <linux/component.h>
@@ -25,7 +26,7 @@ static ssize_t early_stop_show(struct device *dev,
2526
{
2627
struct usb_port *port_dev = to_usb_port(dev);
2728

28-
return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no");
29+
return sysfs_emit(buf, "%s\n", str_yes_no(port_dev->early_stop));
2930
}
3031

3132
static ssize_t early_stop_store(struct device *dev, struct device_attribute *attr,

drivers/usb/fotg210/fotg210-core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/of.h>
1414
#include <linux/platform_device.h>
1515
#include <linux/regmap.h>
16+
#include <linux/string_choices.h>
1617
#include <linux/usb.h>
1718
#include <linux/usb/otg.h>
1819

@@ -119,8 +120,8 @@ void fotg210_vbus(struct fotg210 *fotg, bool enable)
119120
ret = regmap_update_bits(fotg->map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
120121
if (ret)
121122
dev_err(fotg->dev, "failed to %s VBUS\n",
122-
enable ? "enable" : "disable");
123-
dev_info(fotg->dev, "%s: %s VBUS\n", __func__, enable ? "enable" : "disable");
123+
str_enable_disable(enable));
124+
dev_info(fotg->dev, "%s: %s VBUS\n", __func__, str_enable_disable(enable));
124125
}
125126

126127
static int fotg210_probe(struct platform_device *pdev)

drivers/usb/mtu3/mtu3_debugfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Author: Chunfeng Yun <[email protected]>
88
*/
99

10+
#include <linux/string_choices.h>
1011
#include <linux/uaccess.h>
1112

1213
#include "mtu3.h"
@@ -479,7 +480,7 @@ static int ssusb_vbus_show(struct seq_file *sf, void *unused)
479480
struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
480481

481482
seq_printf(sf, "vbus state: %s\n(echo on/off)\n",
482-
regulator_is_enabled(otg_sx->vbus) ? "on" : "off");
483+
str_on_off(regulator_is_enabled(otg_sx->vbus)));
483484

484485
return 0;
485486
}

drivers/usb/mtu3/mtu3_dr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Author: Chunfeng Yun <[email protected]>
88
*/
99

10+
#include <linux/string_choices.h>
1011
#include "mtu3.h"
1112
#include "mtu3_dr.h"
1213
#include "mtu3_debug.h"
@@ -109,7 +110,7 @@ int ssusb_set_vbus(struct otg_switch_mtk *otg_sx, int is_on)
109110
if (!vbus)
110111
return 0;
111112

112-
dev_dbg(ssusb->dev, "%s: turn %s\n", __func__, is_on ? "on" : "off");
113+
dev_dbg(ssusb->dev, "%s: turn %s\n", __func__, str_on_off(is_on));
113114

114115
if (is_on) {
115116
ret = regulator_enable(vbus);

drivers/usb/mtu3/mtu3_gadget.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Author: Chunfeng Yun <[email protected]>
88
*/
99

10+
#include <linux/string_choices.h>
1011
#include "mtu3.h"
1112
#include "mtu3_trace.h"
1213

@@ -490,7 +491,7 @@ static int mtu3_gadget_pullup(struct usb_gadget *gadget, int is_on)
490491
unsigned long flags;
491492

492493
dev_dbg(mtu->dev, "%s (%s) for %sactive device\n", __func__,
493-
is_on ? "on" : "off", mtu->is_active ? "" : "in");
494+
str_on_off(is_on), mtu->is_active ? "" : "in");
494495

495496
pm_runtime_get_sync(mtu->dev);
496497

drivers/usb/musb/da8xx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/of_platform.h>
2222
#include <linux/phy/phy.h>
2323
#include <linux/platform_device.h>
24+
#include <linux/string_choices.h>
2425
#include <linux/dma-mapping.h>
2526
#include <linux/usb/usb_phy_generic.h>
2627

@@ -306,7 +307,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
306307
}
307308

308309
dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
309-
drvvbus ? "on" : "off",
310+
str_on_off(drvvbus),
310311
usb_otg_state_string(musb->xceiv->otg->state),
311312
err ? " ERROR" : "",
312313
devctl);

0 commit comments

Comments
 (0)