From nobody Wed Dec 17 06:08:55 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 726CE20CCE9 for ; Tue, 14 Jan 2025 20:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736885156; cv=none; b=sPiQDm0Y3XbbZ3D8r6Yo6iqmurbM2mK1a3yQm7EwJXiatCmxWq5x3ZEQaC89YyHFBQ1Myq8vkCtPKwHZ+ycpZBJX1sjvNHZRfiR+mXgA1HmMo+w0yQAFbMsL6COUUa1hk97LNbJgikPFetVdcgVNQ/2IxyxM9p8zKk3lAc8GrOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736885156; c=relaxed/simple; bh=op/DCt6ROIee0t+eYACLLqRtmspLz0pZPqJlNXnqaN4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sQR2BRxpMzEkawbE64tPUVsNN2jlZ3xpGI+kN+OZG119z4imye5yi3/yNSEaCVJFDccasDTsQ8m+/fM2uYEDNb8D+ShPzYmVqM5sdL1/q9hMjI7w58MvGSQGVOPUNCFo+wxMdSVSb/x+DBhofEvFnJ3DQNSGbLmMh5cQBx0ufkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TziIXzGy; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TziIXzGy" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43620a5f81bso6426815e9.0 for ; Tue, 14 Jan 2025 12:05:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736885152; x=1737489952; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lUd9pE4ibsdIBdg8Wzjk/goShzuEiiFqbneq+H7LmXk=; b=TziIXzGyDyLgfbg4Svhvu3iuh2S6tnplo+/qWmClvhB1x5eKR50HyC3rBr0tdy25m8 3GF5cAuJyoIFL93gyU1+HmyuD9HFUdD68n0b9/gAMnlR5DL2j4Bce0oUXYn8YId33+cU CIf9cp1aHTIedHEq3FGilJPaC8mYjKIXvKQz9rW30h7r+r1a+5z5mF6EN78V2Dto9mgQ HYCtffWtnSMrJlLfXuzCt5FJAI97cVp0l5rN1UxvSJayNRDdbgJoIwToACbYJkm4z4K1 c9UZSA4klp+UqNuHBX/vslSlpjDlj3bKFQsBhfjd7wivDTyTlE90fjUT/fukhuCf/hNG c/6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736885152; x=1737489952; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUd9pE4ibsdIBdg8Wzjk/goShzuEiiFqbneq+H7LmXk=; b=vWpDNfuvspzHqGSV6pCqpAECLTqlyFRn0geJy5wdwkdSH5qSkJ6AhTtQ+YGmvELovX RtPQdg3nUbt8tXNEseG2Hrh1H1BKIeY19/Av95o/53RgOPHGnWxv5QYWQ5WEo+DekJJJ 3g9usxtrP+Y8QXkLfh2Co/H6QKT7O/jbkYfkh3WiXomgTy+qpyOQEElxGjFSU0MD+1V8 uW32xKG6PnFT8EAMU9Be4Hw+XAYbw3tIwcG1l+SqNg3wiMlgBZfkfGLjJ5kG1OUwttNo 2+7+8yHedQpckQkndk0sUvmnq2CqTcztmpdwB+Mx8e4xGdYEk4ArqtX7Imu6Afl81ZM4 JukA== X-Forwarded-Encrypted: i=1; AJvYcCW0j64laGnRBMfzfK/iq/YJZpZdB5GTh0lBYwpYTLj0q2AKA+9jl6AXwwkbfbJ7fMuIxeceB3NJbsXcYUQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyjWucrMQYm3eTPpDTTfjbk5z5nFyRsD9pNa/Jpum3olnzDCaRz UgphY36+tzmUJwn+2IFA6IiEGPJQezREr1b2u+txk+i9zpSgRvvyx7qKgQUwr5I= X-Gm-Gg: ASbGnctv+O7kiEbr7qSV8khmfIqQF68RLsPjv+03Tae/gCfRY2Qg6Ydh7PVQ3yKyR27 LvuVTM/nwtvk85ZMTX+hms2jXAonD0Sw+SRA2C+eBkyXuLzYkT25/TBIrIXEdkvikrc0N5KDnCI uO0Wdsa1BhQJb52LlNnbW27Z4SOkGWACWKG4+/ll1xIZUZrkm/bqj8NOCNgs/mYyFXons5Gzxod ZUwFZPtrbIHjQJ29XCtWsC3Fsaae0xQzVWYHjObki2Y41yydhowujdBuqyKegZq7h4Mo1bt X-Google-Smtp-Source: AGHT+IFMvUJ1WIMM1UnKEmJAeByugzBupQdHG12m5u1eVkgqRkIU1T58DOpbdwucugHJJCsq7sIZfQ== X-Received: by 2002:a05:600c:4e52:b0:434:a339:ec67 with SMTP id 5b1f17b1804b1-436eba35780mr83014555e9.3.1736885151629; Tue, 14 Jan 2025 12:05:51 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e9dc8802sm184622025e9.10.2025.01.14.12.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 12:05:50 -0800 (PST) From: Krzysztof Kozlowski Date: Tue, 14 Jan 2025 21:05:36 +0100 Subject: [PATCH 3/6] USB: typec: Use str_enable_disable-like helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250114-str-enable-disable-usb-v1-3-c8405df47c19@linaro.org> References: <20250114-str-enable-disable-usb-v1-0-c8405df47c19@linaro.org> In-Reply-To: <20250114-str-enable-disable-usb-v1-0-c8405df47c19@linaro.org> To: Greg Kroah-Hartman , Mathias Nyman , Thierry Reding , Jonathan Hunter , Heikki Krogerus , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Peter Chen , Linus Walleij , Alan Stern Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10285; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=op/DCt6ROIee0t+eYACLLqRtmspLz0pZPqJlNXnqaN4=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnhsOT5omtXZe4pNX5FucIXi5M/SLvLnE6Fx0dg 5RFTZwpizSJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ4bDkwAKCRDBN2bmhouD 1wniEACTnxh/J9HADUSXH/B4PxpTjFV+HrzcRy0yJFO5nAqDf8CUvzoxy5LiOSJDsxsv27LeepD N5ehvpyz+w2gWupb8eKYhihGTkZ1w0IyNmJj6Ohn4aBEU9WxRZyebFGmFgq+U+5Yq3MgEfoEDl9 KLU9ATXXCmI42YpRmlk8329azwR3r8wRSmREHw9PbPr1Q997cij4f6FSC5kDaf7XqNFkq3Biy7r sEKxzqtAq+1zMUbuRJqVoc5bDq1zmjPaX5XF9BSD1luW+oTxpU5XewskSF2zy4llNlDkvOBhpUf brYhgStgG0YmQovvVmwGF13nw6GRW3xN/8/O7VG1jmMJMg8U3XDEHcRJFG1uyfxZelW5vyKCFr0 yNMHm1IfLNSSd0BhcGE/R4kUyI6N/XkeZJzVba/Kc5KZA7HVTb+CSpIBtIJuKtpm39WM+W60PHx qSoLgrOPGXZ7fArYjAsMCi2yWV/ZbGsWzpCAblo9RjEYJnvrxUhNTJ181Oy/dCLY58C86yX2j5H noV1BpUMujRYSzzVCK93IgHmRlnfKI9vkAa0hJPXjsbXDcJjMtDlNEFGlcCnRGzSSGK2ASCSXY0 nDWJOYR13ka9BCCBi+4IFPoETK1PdZLOY0+MSfRDgq+ikD5D/uZlMz7v8y0W7VtlqdLvOeEVUr+ DK2pcX225G0ItrA== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B 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 Reviewed-by: Heikki Krogerus --- drivers/usb/typec/class.c | 7 ++++--- drivers/usb/typec/tcpm/fusb302.c | 24 +++++++++++-------= ---- .../usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 3 ++- .../typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c | 3 ++- drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 4 +++- drivers/usb/typec/tcpm/tcpm.c | 7 ++++--- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index d9d019cff01908eaa8dcb484a87147f3d9992bf3..9c76c3d0c6cff9c9b94ef35fb0c= b4be0e395aad6 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -361,7 +362,7 @@ active_show(struct device *dev, struct device_attribute= *attr, char *buf) { struct typec_altmode *alt =3D to_typec_altmode(dev); =20 - return sprintf(buf, "%s\n", alt->active ? "yes" : "no"); + return sprintf(buf, "%s\n", str_yes_no(alt->active)); } =20 static ssize_t active_store(struct device *dev, struct device_attribute *a= ttr, @@ -707,7 +708,7 @@ static ssize_t supports_usb_power_delivery_show(struct = device *dev, { struct typec_partner *p =3D to_typec_partner(dev); =20 - return sprintf(buf, "%s\n", p->usb_pd ? "yes" : "no"); + return sprintf(buf, "%s\n", str_yes_no(p->usb_pd)); } static DEVICE_ATTR_RO(supports_usb_power_delivery); =20 @@ -1855,7 +1856,7 @@ static ssize_t vconn_source_show(struct device *dev, struct typec_port *port =3D to_typec_port(dev); =20 return sprintf(buf, "%s\n", - port->vconn_role =3D=3D TYPEC_SOURCE ? "yes" : "no"); + str_yes_no(port->vconn_role =3D=3D TYPEC_SOURCE)); } static DEVICE_ATTR_RW(vconn_source); =20 diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb= 302.c index e2fe479e16ada018930ea0dbbf58ee37ce9a1990..f15c63d3a8f441569ec98302f5b= 241430d8e4547 100644 --- a/drivers/usb/typec/tcpm/fusb302.c +++ b/drivers/usb/typec/tcpm/fusb302.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -733,7 +734,7 @@ static int tcpm_set_vconn(struct tcpc_dev *dev, bool on) =20 mutex_lock(&chip->lock); if (chip->vconn_on =3D=3D on) { - fusb302_log(chip, "vconn is already %s", on ? "On" : "Off"); + fusb302_log(chip, "vconn is already %s", str_on_off(on)); goto done; } if (on) { @@ -746,7 +747,7 @@ static int tcpm_set_vconn(struct tcpc_dev *dev, bool on) if (ret < 0) goto done; chip->vconn_on =3D on; - fusb302_log(chip, "vconn :=3D %s", on ? "On" : "Off"); + fusb302_log(chip, "vconn :=3D %s", str_on_off(on)); done: mutex_unlock(&chip->lock); =20 @@ -761,7 +762,7 @@ static int tcpm_set_vbus(struct tcpc_dev *dev, bool on,= bool charge) =20 mutex_lock(&chip->lock); if (chip->vbus_on =3D=3D on) { - fusb302_log(chip, "vbus is already %s", on ? "On" : "Off"); + fusb302_log(chip, "vbus is already %s", str_on_off(on)); } else { if (on) ret =3D regulator_enable(chip->vbus); @@ -769,15 +770,14 @@ static int tcpm_set_vbus(struct tcpc_dev *dev, bool o= n, bool charge) ret =3D regulator_disable(chip->vbus); if (ret < 0) { fusb302_log(chip, "cannot %s vbus regulator, ret=3D%d", - on ? "enable" : "disable", ret); + str_enable_disable(on), ret); goto done; } chip->vbus_on =3D on; - fusb302_log(chip, "vbus :=3D %s", on ? "On" : "Off"); + fusb302_log(chip, "vbus :=3D %s", str_on_off(on)); } if (chip->charge_on =3D=3D charge) - fusb302_log(chip, "charge is already %s", - charge ? "On" : "Off"); + fusb302_log(chip, "charge is already %s", str_on_off(charge)); else chip->charge_on =3D charge; =20 @@ -854,16 +854,16 @@ static int tcpm_set_pd_rx(struct tcpc_dev *dev, bool = on) ret =3D fusb302_pd_set_auto_goodcrc(chip, on); if (ret < 0) { fusb302_log(chip, "cannot turn %s auto GCRC, ret=3D%d", - on ? "on" : "off", ret); + str_on_off(on), ret); goto done; } ret =3D fusb302_pd_set_interrupts(chip, on); if (ret < 0) { fusb302_log(chip, "cannot turn %s pd interrupts, ret=3D%d", - on ? "on" : "off", ret); + str_on_off(on), ret); goto done; } - fusb302_log(chip, "pd :=3D %s", on ? "on" : "off"); + fusb302_log(chip, "pd :=3D %s", str_on_off(on)); done: mutex_unlock(&chip->lock); =20 @@ -1531,7 +1531,7 @@ static void fusb302_irq_work(struct work_struct *work) if (interrupt & FUSB_REG_INTERRUPT_VBUSOK) { vbus_present =3D !!(status0 & FUSB_REG_STATUS0_VBUSOK); fusb302_log(chip, "IRQ: VBUS_OK, vbus=3D%s", - vbus_present ? "On" : "Off"); + str_on_off(vbus_present)); if (vbus_present !=3D chip->vbus_present) { chip->vbus_present =3D vbus_present; tcpm_vbus_change(chip->tcpm_port); @@ -1562,7 +1562,7 @@ static void fusb302_irq_work(struct work_struct *work) if ((interrupt & FUSB_REG_INTERRUPT_COMP_CHNG) && intr_comp_chng) { comp_result =3D !!(status0 & FUSB_REG_STATUS0_COMP); fusb302_log(chip, "IRQ: COMP_CHNG, comp=3D%s", - comp_result ? "true" : "false"); + str_true_false(comp_result)); if (comp_result) { /* cc level > Rd_threshold, detach */ chip->cc1 =3D TYPEC_CC_OPEN; diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/= usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c index 726423684bae0a690bd20547313704b7d2f4cfdc..18303b34594bbf6f43d1138177c= 4ab58f0dec395 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "qcom_pmic_typec.h" @@ -418,7 +419,7 @@ static int qcom_pmic_typec_pdphy_set_pd_rx(struct tcpc_= dev *tcpc, bool on) =20 spin_unlock_irqrestore(&pmic_typec_pdphy->lock, flags); =20 - dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", on ? "on" : "off"); + dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", str_on_off(on)); =20 return ret; } diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c b/dri= vers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c index df79059cda6755d4de35b7239fadc2dff2e699b1..8fac171778daf471fe4d03de8cc= 4f9c7ce1f323b 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "qcom_pmic_typec.h" @@ -38,7 +39,7 @@ static int qcom_pmic_typec_pdphy_stub_set_pd_rx(struct tc= pc_dev *tcpc, bool on) struct pmic_typec *tcpm =3D tcpc_to_tcpm(tcpc); struct device *dev =3D tcpm->dev; =20 - dev_dbg(dev, "set_pd_rx: %s\n", on ? "on" : "off"); + dev_dbg(dev, "set_pd_rx: %s\n", str_on_off(on)); =20 return 0; } diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/u= sb/typec/tcpm/qcom/qcom_pmic_typec_port.c index c37dede62e12cd8a105da108838b5ca4f5e632d7..4fc83dcfae643e7a8b8e89ac6e6= f5a9aaba3f65b 100644 --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -562,7 +563,8 @@ static int qcom_pmic_typec_port_set_vconn(struct tcpc_d= ev *tcpc, bool on) spin_unlock_irqrestore(&pmic_typec_port->lock, flags); =20 dev_dbg(dev, "set_vconn: orientation %d control 0x%08x state %s cc %s vco= nn %s\n", - orientation, value, on ? "on" : "off", misc_to_vconn(misc), misc_to_cc(m= isc)); + orientation, value, str_on_off(on), misc_to_vconn(misc), + misc_to_cc(misc)); =20 return ret; } diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index fcf2d7902352c447651f30610d59fef2471f3124..ef2cec386d965512c64e8b7e640= 199e10bb7bc94 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -892,8 +893,8 @@ static int tcpm_enable_auto_vbus_discharge(struct tcpm_= port *port, bool enable) =20 if (port->tcpc->enable_auto_vbus_discharge) { ret =3D port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable); - tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "di= sable", - ret); + tcpm_log_force(port, "%s vbus discharge ret:%d", + str_enable_disable(enable), ret); if (!ret) port->auto_vbus_discharge_enabled =3D enable; } @@ -4439,7 +4440,7 @@ static void tcpm_unregister_altmodes(struct tcpm_port= *port) =20 static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool= capable) { - tcpm_log(port, "Setting usb_comm capable %s", capable ? "true" : "false"); + tcpm_log(port, "Setting usb_comm capable %s", str_true_false(capable)); =20 if (port->tcpc->set_partner_usb_comm_capable) port->tcpc->set_partner_usb_comm_capable(port->tcpc, capable); --=20 2.43.0