Skip to contentSkip to conversation

usb: typec: cros-ec-ucsi: A couple small cleanups

PATCH In review Stephen Boyd 2 participants 6 messages Jan 9, 2025 – Jan 10, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover usb: typec: cros-ec-ucsi: A couple small cleanups

A couple small cleanups to the cros-ec-ucsi driver that was recently introduced. Patches on top of next-20250109.

Stephen Boyd (2):
usb: typec: cros-ec-ucsi: Add newlines to printk messages
usb: typec: cros-ec-ucsi: Mark cros_ucsi_ops static/const

 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 30 ++++++++++++---------------
 1 file changed, 13 insertions(+), 17 deletions(-)

base-commit: 6ecd20965bdc21b265a0671ccf36d9ad8043f5ab

Signature · 1 line
https://chromeos.dev
#1 lore raw

PATCH 1/2 usb: typec: cros-ec-ucsi: Add newlines to printk messages

These printks need newlines. Add them and convert to dev_err_probe() in cros_ucsi_probe() to simplify code.

Cc Pavan Holla <[email protected]>
Cc Abhishek Pandit-Subedi <[email protected]>
Cc Łukasz Bartosik <[email protected]>
---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 28 ++++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +12 -16
index db8324b71ee9..75646a8d55be 100644
@@ -58,14 +58,14 @@ static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val,
 	int ret;
 
 	if (val_len > MAX_EC_DATA_SIZE) {
-		dev_err(udata->dev, "Can't read %zu bytes. Too big.", val_len);
+		dev_err(udata->dev, "Can't read %zu bytes. Too big.\n", val_len);
 		return -EINVAL;
 	}
 
 	ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET,
 			  &req, sizeof(req), val, val_len);
 	if (ret < 0) {
-		dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d", ret);
+		dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d\n", ret);
 		return ret;
 	}
 	return 0;
@@ -99,7 +99,7 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
 	ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET,
 			  req, sizeof(ec_buf), NULL, 0);
 	if (ret < 0) {
-		dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d", ret);
+		dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d\n", ret);
 		return ret;
 	}
 	return 0;
@@ -161,7 +161,7 @@ static void cros_ucsi_write_timeout(struct work_struct *work)
 
 	if (cros_ucsi_read(udata->ucsi, UCSI_CCI, &cci, sizeof(cci))) {
 		dev_err(udata->dev,
-			"Reading CCI failed; no write timeout recovery possible.");
+			"Reading CCI failed; no write timeout recovery possible.\n");
 		return;
 	}
 
@@ -173,7 +173,7 @@ static void cros_ucsi_write_timeout(struct work_struct *work)
 					      msecs_to_jiffies(WRITE_TMO_MS));
 		else
 			dev_err(udata->dev,
-				"PPM unresponsive - too many write timeouts.");
+				"PPM unresponsive - too many write timeouts.\n");
 
 		return;
 	}
@@ -208,7 +208,7 @@ static int cros_ucsi_event(struct notifier_block *nb,
 	if (!(host_event & PD_EVENT_PPM))
 		return NOTIFY_OK;
 
-	dev_dbg(udata->dev, "UCSI notification received");
+	dev_dbg(udata->dev, "UCSI notification received\n");
 	flush_work(&udata->work);
 	schedule_work(&udata->work);
 
@@ -237,10 +237,8 @@ static int cros_ucsi_probe(struct platform_device *pdev)
 	udata->dev = dev;
 
 	udata->ec = ec_data->ec_dev;
-	if (!udata->ec) {
-		dev_err(dev, "couldn't find parent EC device");
-		return -ENODEV;
-	}
+	if (!udata->ec)
+		return dev_err_probe(dev, -ENODEV, "couldn't find parent EC device\n");
 
 	platform_set_drvdata(pdev, udata);
 
@@ -249,24 +247,22 @@ static int cros_ucsi_probe(struct platform_device *pdev)
 	init_completion(&udata->complete);
 
 	udata->ucsi = ucsi_create(dev, &cros_ucsi_ops);
-	if (IS_ERR(udata->ucsi)) {
-		dev_err(dev, "failed to allocate UCSI instance");
-		return PTR_ERR(udata->ucsi);
-	}
+	if (IS_ERR(udata->ucsi))
+		return dev_err_probe(dev, PTR_ERR(udata->ucsi), "failed to allocate UCSI instance\n");
 
 	ucsi_set_drvdata(udata->ucsi, udata);
 
 	udata->nb.notifier_call = cros_ucsi_event;
 	ret = cros_usbpd_register_notify(&udata->nb);
 	if (ret) {
-		dev_err(dev, "failed to register notifier: error=%d", ret);
+		dev_err_probe(dev, ret, "failed to register notifier\n");
 		ucsi_destroy(udata->ucsi);
 		return ret;
 	}
 
 	ret = ucsi_register(udata->ucsi);
 	if (ret) {
-		dev_err(dev, "failed to register UCSI: error=%d", ret);
+		dev_err_probe(dev, ret, "failed to register UCSI\n");
 		cros_ucsi_destroy(udata);
 		return ret;
 	}
Signature · 1 line
https://chromeos.dev
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] usb: typec: cros-ec-ucsi: Add newlines to printk messages

Quoted 8 lines · Stephen Boyd

These printks need newlines. Add them and convert to dev_err_probe() in cros_ucsi_probe() to simplify code.

Cc Pavan Holla <[email protected]>
Cc Abhishek Pandit-Subedi <[email protected]>
Cc Łukasz Bartosik <[email protected]>
Quoted 106 lines
---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 28 ++++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +12 -17
index db8324b71ee9..75646a8d55be 100644
@@ -58,14 +58,14 @@ static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val,
        int ret;
 
        if (val_len > MAX_EC_DATA_SIZE) {
-               dev_err(udata->dev, "Can't read %zu bytes. Too big.", val_len);
+               dev_err(udata->dev, "Can't read %zu bytes. Too big.\n", val_len);
                return -EINVAL;
        }
 
        ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET,
                          &req, sizeof(req), val, val_len);
        if (ret < 0) {
-               dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d", ret);
+               dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d\n", ret);
                return ret;
        }
        return 0;
@@ -99,7 +99,7 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
        ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET,
                          req, sizeof(ec_buf), NULL, 0);
        if (ret < 0) {
-               dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d", ret);
+               dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d\n", ret);
                return ret;
        }
        return 0;
@@ -161,7 +161,7 @@ static void cros_ucsi_write_timeout(struct work_struct *work)
 
        if (cros_ucsi_read(udata->ucsi, UCSI_CCI, &cci, sizeof(cci))) {
                dev_err(udata->dev,
-                       "Reading CCI failed; no write timeout recovery possible.");
+                       "Reading CCI failed; no write timeout recovery possible.\n");
                return;
        }
 
@@ -173,7 +173,7 @@ static void cros_ucsi_write_timeout(struct work_struct *work)
                                              msecs_to_jiffies(WRITE_TMO_MS));
                else
                        dev_err(udata->dev,
-                               "PPM unresponsive - too many write timeouts.");
+                               "PPM unresponsive - too many write timeouts.\n");
 
                return;
        }
@@ -208,7 +208,7 @@ static int cros_ucsi_event(struct notifier_block *nb,
        if (!(host_event & PD_EVENT_PPM))
                return NOTIFY_OK;
 
-       dev_dbg(udata->dev, "UCSI notification received");
+       dev_dbg(udata->dev, "UCSI notification received\n");
        flush_work(&udata->work);
        schedule_work(&udata->work);
 
@@ -237,10 +237,8 @@ static int cros_ucsi_probe(struct platform_device *pdev)
        udata->dev = dev;
 
        udata->ec = ec_data->ec_dev;
-       if (!udata->ec) {
-               dev_err(dev, "couldn't find parent EC device");
-               return -ENODEV;
-       }
+       if (!udata->ec)
+               return dev_err_probe(dev, -ENODEV, "couldn't find parent EC device\n");
 
        platform_set_drvdata(pdev, udata);
 
@@ -249,24 +247,22 @@ static int cros_ucsi_probe(struct platform_device *pdev)
        init_completion(&udata->complete);
 
        udata->ucsi = ucsi_create(dev, &cros_ucsi_ops);
-       if (IS_ERR(udata->ucsi)) {
-               dev_err(dev, "failed to allocate UCSI instance");
-               return PTR_ERR(udata->ucsi);
-       }
+       if (IS_ERR(udata->ucsi))
+               return dev_err_probe(dev, PTR_ERR(udata->ucsi), "failed to allocate UCSI instance\n");
 
        ucsi_set_drvdata(udata->ucsi, udata);
 
        udata->nb.notifier_call = cros_ucsi_event;
        ret = cros_usbpd_register_notify(&udata->nb);
        if (ret) {
-               dev_err(dev, "failed to register notifier: error=%d", ret);
+               dev_err_probe(dev, ret, "failed to register notifier\n");
                ucsi_destroy(udata->ucsi);
                return ret;
        }
 
        ret = ucsi_register(udata->ucsi);
        if (ret) {
-               dev_err(dev, "failed to register UCSI: error=%d", ret);
+               dev_err_probe(dev, ret, "failed to register UCSI\n");
                cros_ucsi_destroy(udata);
                return ret;
        }
--

https://chromeos.dev

#3 lore raw

PATCH 2/2 usb: typec: cros-ec-ucsi: Mark cros_ucsi_ops static/const

In reply to Stephen Boyd

This structure isn't used outside this file and can be marked const so that it gets moved to read-only memory.

Cc Pavan Holla <[email protected]>
Cc Abhishek Pandit-Subedi <[email protected]>
Cc Łukasz Bartosik <[email protected]>
---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +1 -1
index 75646a8d55be..c605c8616726 100644
@@ -133,7 +133,7 @@ static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
 	return ret;
 }
 
-struct ucsi_operations cros_ucsi_ops = {
+static const struct ucsi_operations cros_ucsi_ops = {
 	.read_version = cros_ucsi_read_version,
 	.read_cci = cros_ucsi_read_cci,
 	.read_message_in = cros_ucsi_read_message_in,
Signature · 1 line
https://chromeos.dev
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] usb: typec: cros-ec-ucsi: Mark cros_ucsi_ops static/const

Quoted 8 lines · Stephen Boyd

This structure isn't used outside this file and can be marked const so that it gets moved to read-only memory.

Cc Pavan Holla <[email protected]>
Cc Abhishek Pandit-Subedi <[email protected]>
Cc Łukasz Bartosik <[email protected]>
Quoted 20 lines
---
 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +1 -2
index 75646a8d55be..c605c8616726 100644
@@ -133,7 +133,7 @@ static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
        return ret;
 }
 
-struct ucsi_operations cros_ucsi_ops = {
+static const struct ucsi_operations cros_ucsi_ops = {
        .read_version = cros_ucsi_read_version,
        .read_cci = cros_ucsi_read_cci,
        .read_message_in = cros_ucsi_read_message_in,
--

https://chromeos.dev

maintainer
#5 lore raw
In reply to Stephen Boyd
Quoted 11 lines · Stephen Boyd

A couple small cleanups to the cros-ec-ucsi driver that was recently introduced. Patches on top of next-20250109.

Stephen Boyd (2):
usb: typec: cros-ec-ucsi: Add newlines to printk messages
usb: typec: cros-ec-ucsi: Mark cros_ucsi_ops static/const

 drivers/usb/typec/ucsi/cros_ec_ucsi.c | 30 ++++++++++++---------------
 1 file changed, 13 insertions(+), 17 deletions(-)

Thank you Stephen for the updates.

Regards,
Łukasz

Quoted 5 lines

base-commit: 6ecd20965bdc21b265a0671ccf36d9ad8043f5ab --
https://chromeos.dev