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

Configure Feed

Select the types of activity you want to include in your feed.

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 <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20250114-str-enable-disable-usb-v1-3-c8405df47c19@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
13b3af26 789a1714

+27 -21
+4 -3
drivers/usb/typec/class.c
··· 10 10 #include <linux/mutex.h> 11 11 #include <linux/property.h> 12 12 #include <linux/slab.h> 13 + #include <linux/string_choices.h> 13 14 #include <linux/usb/pd_vdo.h> 14 15 #include <linux/usb/typec_mux.h> 15 16 #include <linux/usb/typec_retimer.h> ··· 362 361 { 363 362 struct typec_altmode *alt = to_typec_altmode(dev); 364 363 365 - return sprintf(buf, "%s\n", alt->active ? "yes" : "no"); 364 + return sprintf(buf, "%s\n", str_yes_no(alt->active)); 366 365 } 367 366 368 367 static ssize_t active_store(struct device *dev, struct device_attribute *attr, ··· 708 707 { 709 708 struct typec_partner *p = to_typec_partner(dev); 710 709 711 - return sprintf(buf, "%s\n", p->usb_pd ? "yes" : "no"); 710 + return sprintf(buf, "%s\n", str_yes_no(p->usb_pd)); 712 711 } 713 712 static DEVICE_ATTR_RO(supports_usb_power_delivery); 714 713 ··· 1860 1859 struct typec_port *port = to_typec_port(dev); 1861 1860 1862 1861 return sprintf(buf, "%s\n", 1863 - port->vconn_role == TYPEC_SOURCE ? "yes" : "no"); 1862 + str_yes_no(port->vconn_role == TYPEC_SOURCE)); 1864 1863 } 1865 1864 static DEVICE_ATTR_RW(vconn_source); 1866 1865
+12 -12
drivers/usb/typec/tcpm/fusb302.c
··· 24 24 #include <linux/slab.h> 25 25 #include <linux/spinlock.h> 26 26 #include <linux/string.h> 27 + #include <linux/string_choices.h> 27 28 #include <linux/types.h> 28 29 #include <linux/usb.h> 29 30 #include <linux/usb/typec.h> ··· 734 733 735 734 mutex_lock(&chip->lock); 736 735 if (chip->vconn_on == on) { 737 - fusb302_log(chip, "vconn is already %s", on ? "On" : "Off"); 736 + fusb302_log(chip, "vconn is already %s", str_on_off(on)); 738 737 goto done; 739 738 } 740 739 if (on) { ··· 747 746 if (ret < 0) 748 747 goto done; 749 748 chip->vconn_on = on; 750 - fusb302_log(chip, "vconn := %s", on ? "On" : "Off"); 749 + fusb302_log(chip, "vconn := %s", str_on_off(on)); 751 750 done: 752 751 mutex_unlock(&chip->lock); 753 752 ··· 762 761 763 762 mutex_lock(&chip->lock); 764 763 if (chip->vbus_on == on) { 765 - fusb302_log(chip, "vbus is already %s", on ? "On" : "Off"); 764 + fusb302_log(chip, "vbus is already %s", str_on_off(on)); 766 765 } else { 767 766 if (on) 768 767 ret = regulator_enable(chip->vbus); ··· 770 769 ret = regulator_disable(chip->vbus); 771 770 if (ret < 0) { 772 771 fusb302_log(chip, "cannot %s vbus regulator, ret=%d", 773 - on ? "enable" : "disable", ret); 772 + str_enable_disable(on), ret); 774 773 goto done; 775 774 } 776 775 chip->vbus_on = on; 777 - fusb302_log(chip, "vbus := %s", on ? "On" : "Off"); 776 + fusb302_log(chip, "vbus := %s", str_on_off(on)); 778 777 } 779 778 if (chip->charge_on == charge) 780 - fusb302_log(chip, "charge is already %s", 781 - charge ? "On" : "Off"); 779 + fusb302_log(chip, "charge is already %s", str_on_off(charge)); 782 780 else 783 781 chip->charge_on = charge; 784 782 ··· 854 854 ret = fusb302_pd_set_auto_goodcrc(chip, on); 855 855 if (ret < 0) { 856 856 fusb302_log(chip, "cannot turn %s auto GCRC, ret=%d", 857 - on ? "on" : "off", ret); 857 + str_on_off(on), ret); 858 858 goto done; 859 859 } 860 860 ret = fusb302_pd_set_interrupts(chip, on); 861 861 if (ret < 0) { 862 862 fusb302_log(chip, "cannot turn %s pd interrupts, ret=%d", 863 - on ? "on" : "off", ret); 863 + str_on_off(on), ret); 864 864 goto done; 865 865 } 866 - fusb302_log(chip, "pd := %s", on ? "on" : "off"); 866 + fusb302_log(chip, "pd := %s", str_on_off(on)); 867 867 done: 868 868 mutex_unlock(&chip->lock); 869 869 ··· 1531 1531 if (interrupt & FUSB_REG_INTERRUPT_VBUSOK) { 1532 1532 vbus_present = !!(status0 & FUSB_REG_STATUS0_VBUSOK); 1533 1533 fusb302_log(chip, "IRQ: VBUS_OK, vbus=%s", 1534 - vbus_present ? "On" : "Off"); 1534 + str_on_off(vbus_present)); 1535 1535 if (vbus_present != chip->vbus_present) { 1536 1536 chip->vbus_present = vbus_present; 1537 1537 tcpm_vbus_change(chip->tcpm_port); ··· 1562 1562 if ((interrupt & FUSB_REG_INTERRUPT_COMP_CHNG) && intr_comp_chng) { 1563 1563 comp_result = !!(status0 & FUSB_REG_STATUS0_COMP); 1564 1564 fusb302_log(chip, "IRQ: COMP_CHNG, comp=%s", 1565 - comp_result ? "true" : "false"); 1565 + str_true_false(comp_result)); 1566 1566 if (comp_result) { 1567 1567 /* cc level > Rd_threshold, detach */ 1568 1568 chip->cc1 = TYPEC_CC_OPEN;
+2 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
··· 12 12 #include <linux/regmap.h> 13 13 #include <linux/regulator/consumer.h> 14 14 #include <linux/slab.h> 15 + #include <linux/string_choices.h> 15 16 #include <linux/usb/pd.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include "qcom_pmic_typec.h" ··· 419 418 420 419 spin_unlock_irqrestore(&pmic_typec_pdphy->lock, flags); 421 420 422 - dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", on ? "on" : "off"); 421 + dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", str_on_off(on)); 423 422 424 423 return ret; 425 424 }
+2 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c
··· 12 12 #include <linux/regmap.h> 13 13 #include <linux/regulator/consumer.h> 14 14 #include <linux/slab.h> 15 + #include <linux/string_choices.h> 15 16 #include <linux/usb/pd.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include "qcom_pmic_typec.h" ··· 39 38 struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 40 39 struct device *dev = tcpm->dev; 41 40 42 - dev_dbg(dev, "set_pd_rx: %s\n", on ? "on" : "off"); 41 + dev_dbg(dev, "set_pd_rx: %s\n", str_on_off(on)); 43 42 44 43 return 0; 45 44 }
+3 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
··· 13 13 #include <linux/regmap.h> 14 14 #include <linux/regulator/consumer.h> 15 15 #include <linux/slab.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include <linux/usb/typec_mux.h> 18 19 #include <linux/workqueue.h> ··· 563 562 spin_unlock_irqrestore(&pmic_typec_port->lock, flags); 564 563 565 564 dev_dbg(dev, "set_vconn: orientation %d control 0x%08x state %s cc %s vconn %s\n", 566 - orientation, value, on ? "on" : "off", misc_to_vconn(misc), misc_to_cc(misc)); 565 + orientation, value, str_on_off(on), misc_to_vconn(misc), 566 + misc_to_cc(misc)); 567 567 568 568 return ret; 569 569 }
+4 -3
drivers/usb/typec/tcpm/tcpm.c
··· 21 21 #include <linux/seq_file.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/spinlock.h> 24 + #include <linux/string_choices.h> 24 25 #include <linux/usb.h> 25 26 #include <linux/usb/pd.h> 26 27 #include <linux/usb/pd_ado.h> ··· 893 892 894 893 if (port->tcpc->enable_auto_vbus_discharge) { 895 894 ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable); 896 - tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "disable", 897 - ret); 895 + tcpm_log_force(port, "%s vbus discharge ret:%d", 896 + str_enable_disable(enable), ret); 898 897 if (!ret) 899 898 port->auto_vbus_discharge_enabled = enable; 900 899 } ··· 4440 4439 4441 4440 static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capable) 4442 4441 { 4443 - tcpm_log(port, "Setting usb_comm capable %s", capable ? "true" : "false"); 4442 + tcpm_log(port, "Setting usb_comm capable %s", str_true_false(capable)); 4444 4443 4445 4444 if (port->tcpc->set_partner_usb_comm_capable) 4446 4445 port->tcpc->set_partner_usb_comm_capable(port->tcpc, capable);