Skip to content

Commit 13b3af2

Browse files
krzkgregkh
authored andcommitted
USB: typec: 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 789a171 commit 13b3af2

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

drivers/usb/typec/class.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/mutex.h>
1111
#include <linux/property.h>
1212
#include <linux/slab.h>
13+
#include <linux/string_choices.h>
1314
#include <linux/usb/pd_vdo.h>
1415
#include <linux/usb/typec_mux.h>
1516
#include <linux/usb/typec_retimer.h>
@@ -361,7 +362,7 @@ active_show(struct device *dev, struct device_attribute *attr, char *buf)
361362
{
362363
struct typec_altmode *alt = to_typec_altmode(dev);
363364

364-
return sprintf(buf, "%s\n", alt->active ? "yes" : "no");
365+
return sprintf(buf, "%s\n", str_yes_no(alt->active));
365366
}
366367

367368
static ssize_t active_store(struct device *dev, struct device_attribute *attr,
@@ -707,7 +708,7 @@ static ssize_t supports_usb_power_delivery_show(struct device *dev,
707708
{
708709
struct typec_partner *p = to_typec_partner(dev);
709710

710-
return sprintf(buf, "%s\n", p->usb_pd ? "yes" : "no");
711+
return sprintf(buf, "%s\n", str_yes_no(p->usb_pd));
711712
}
712713
static DEVICE_ATTR_RO(supports_usb_power_delivery);
713714

@@ -1859,7 +1860,7 @@ static ssize_t vconn_source_show(struct device *dev,
18591860
struct typec_port *port = to_typec_port(dev);
18601861

18611862
return sprintf(buf, "%s\n",
1862-
port->vconn_role == TYPEC_SOURCE ? "yes" : "no");
1863+
str_yes_no(port->vconn_role == TYPEC_SOURCE));
18631864
}
18641865
static DEVICE_ATTR_RW(vconn_source);
18651866

drivers/usb/typec/tcpm/fusb302.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/slab.h>
2525
#include <linux/spinlock.h>
2626
#include <linux/string.h>
27+
#include <linux/string_choices.h>
2728
#include <linux/types.h>
2829
#include <linux/usb.h>
2930
#include <linux/usb/typec.h>
@@ -733,7 +734,7 @@ static int tcpm_set_vconn(struct tcpc_dev *dev, bool on)
733734

734735
mutex_lock(&chip->lock);
735736
if (chip->vconn_on == on) {
736-
fusb302_log(chip, "vconn is already %s", on ? "On" : "Off");
737+
fusb302_log(chip, "vconn is already %s", str_on_off(on));
737738
goto done;
738739
}
739740
if (on) {
@@ -746,7 +747,7 @@ static int tcpm_set_vconn(struct tcpc_dev *dev, bool on)
746747
if (ret < 0)
747748
goto done;
748749
chip->vconn_on = on;
749-
fusb302_log(chip, "vconn := %s", on ? "On" : "Off");
750+
fusb302_log(chip, "vconn := %s", str_on_off(on));
750751
done:
751752
mutex_unlock(&chip->lock);
752753

@@ -761,23 +762,22 @@ static int tcpm_set_vbus(struct tcpc_dev *dev, bool on, bool charge)
761762

762763
mutex_lock(&chip->lock);
763764
if (chip->vbus_on == on) {
764-
fusb302_log(chip, "vbus is already %s", on ? "On" : "Off");
765+
fusb302_log(chip, "vbus is already %s", str_on_off(on));
765766
} else {
766767
if (on)
767768
ret = regulator_enable(chip->vbus);
768769
else
769770
ret = regulator_disable(chip->vbus);
770771
if (ret < 0) {
771772
fusb302_log(chip, "cannot %s vbus regulator, ret=%d",
772-
on ? "enable" : "disable", ret);
773+
str_enable_disable(on), ret);
773774
goto done;
774775
}
775776
chip->vbus_on = on;
776-
fusb302_log(chip, "vbus := %s", on ? "On" : "Off");
777+
fusb302_log(chip, "vbus := %s", str_on_off(on));
777778
}
778779
if (chip->charge_on == charge)
779-
fusb302_log(chip, "charge is already %s",
780-
charge ? "On" : "Off");
780+
fusb302_log(chip, "charge is already %s", str_on_off(charge));
781781
else
782782
chip->charge_on = charge;
783783

@@ -854,16 +854,16 @@ static int tcpm_set_pd_rx(struct tcpc_dev *dev, bool on)
854854
ret = fusb302_pd_set_auto_goodcrc(chip, on);
855855
if (ret < 0) {
856856
fusb302_log(chip, "cannot turn %s auto GCRC, ret=%d",
857-
on ? "on" : "off", ret);
857+
str_on_off(on), ret);
858858
goto done;
859859
}
860860
ret = fusb302_pd_set_interrupts(chip, on);
861861
if (ret < 0) {
862862
fusb302_log(chip, "cannot turn %s pd interrupts, ret=%d",
863-
on ? "on" : "off", ret);
863+
str_on_off(on), ret);
864864
goto done;
865865
}
866-
fusb302_log(chip, "pd := %s", on ? "on" : "off");
866+
fusb302_log(chip, "pd := %s", str_on_off(on));
867867
done:
868868
mutex_unlock(&chip->lock);
869869

@@ -1531,7 +1531,7 @@ static void fusb302_irq_work(struct work_struct *work)
15311531
if (interrupt & FUSB_REG_INTERRUPT_VBUSOK) {
15321532
vbus_present = !!(status0 & FUSB_REG_STATUS0_VBUSOK);
15331533
fusb302_log(chip, "IRQ: VBUS_OK, vbus=%s",
1534-
vbus_present ? "On" : "Off");
1534+
str_on_off(vbus_present));
15351535
if (vbus_present != chip->vbus_present) {
15361536
chip->vbus_present = vbus_present;
15371537
tcpm_vbus_change(chip->tcpm_port);
@@ -1562,7 +1562,7 @@ static void fusb302_irq_work(struct work_struct *work)
15621562
if ((interrupt & FUSB_REG_INTERRUPT_COMP_CHNG) && intr_comp_chng) {
15631563
comp_result = !!(status0 & FUSB_REG_STATUS0_COMP);
15641564
fusb302_log(chip, "IRQ: COMP_CHNG, comp=%s",
1565-
comp_result ? "true" : "false");
1565+
str_true_false(comp_result));
15661566
if (comp_result) {
15671567
/* cc level > Rd_threshold, detach */
15681568
chip->cc1 = TYPEC_CC_OPEN;

drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/regmap.h>
1313
#include <linux/regulator/consumer.h>
1414
#include <linux/slab.h>
15+
#include <linux/string_choices.h>
1516
#include <linux/usb/pd.h>
1617
#include <linux/usb/tcpm.h>
1718
#include "qcom_pmic_typec.h"
@@ -418,7 +419,7 @@ static int qcom_pmic_typec_pdphy_set_pd_rx(struct tcpc_dev *tcpc, bool on)
418419

419420
spin_unlock_irqrestore(&pmic_typec_pdphy->lock, flags);
420421

421-
dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", on ? "on" : "off");
422+
dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", str_on_off(on));
422423

423424
return ret;
424425
}

drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/regmap.h>
1313
#include <linux/regulator/consumer.h>
1414
#include <linux/slab.h>
15+
#include <linux/string_choices.h>
1516
#include <linux/usb/pd.h>
1617
#include <linux/usb/tcpm.h>
1718
#include "qcom_pmic_typec.h"
@@ -38,7 +39,7 @@ static int qcom_pmic_typec_pdphy_stub_set_pd_rx(struct tcpc_dev *tcpc, bool on)
3839
struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc);
3940
struct device *dev = tcpm->dev;
4041

41-
dev_dbg(dev, "set_pd_rx: %s\n", on ? "on" : "off");
42+
dev_dbg(dev, "set_pd_rx: %s\n", str_on_off(on));
4243

4344
return 0;
4445
}

drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/regmap.h>
1414
#include <linux/regulator/consumer.h>
1515
#include <linux/slab.h>
16+
#include <linux/string_choices.h>
1617
#include <linux/usb/tcpm.h>
1718
#include <linux/usb/typec_mux.h>
1819
#include <linux/workqueue.h>
@@ -562,7 +563,8 @@ static int qcom_pmic_typec_port_set_vconn(struct tcpc_dev *tcpc, bool on)
562563
spin_unlock_irqrestore(&pmic_typec_port->lock, flags);
563564

564565
dev_dbg(dev, "set_vconn: orientation %d control 0x%08x state %s cc %s vconn %s\n",
565-
orientation, value, on ? "on" : "off", misc_to_vconn(misc), misc_to_cc(misc));
566+
orientation, value, str_on_off(on), misc_to_vconn(misc),
567+
misc_to_cc(misc));
566568

567569
return ret;
568570
}

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/seq_file.h>
2222
#include <linux/slab.h>
2323
#include <linux/spinlock.h>
24+
#include <linux/string_choices.h>
2425
#include <linux/usb.h>
2526
#include <linux/usb/pd.h>
2627
#include <linux/usb/pd_ado.h>
@@ -892,8 +893,8 @@ static int tcpm_enable_auto_vbus_discharge(struct tcpm_port *port, bool enable)
892893

893894
if (port->tcpc->enable_auto_vbus_discharge) {
894895
ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable);
895-
tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "disable",
896-
ret);
896+
tcpm_log_force(port, "%s vbus discharge ret:%d",
897+
str_enable_disable(enable), ret);
897898
if (!ret)
898899
port->auto_vbus_discharge_enabled = enable;
899900
}
@@ -4439,7 +4440,7 @@ static void tcpm_unregister_altmodes(struct tcpm_port *port)
44394440

44404441
static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capable)
44414442
{
4442-
tcpm_log(port, "Setting usb_comm capable %s", capable ? "true" : "false");
4443+
tcpm_log(port, "Setting usb_comm capable %s", str_true_false(capable));
44434444

44444445
if (port->tcpc->set_partner_usb_comm_capable)
44454446
port->tcpc->set_partner_usb_comm_capable(port->tcpc, capable);

0 commit comments

Comments
 (0)