2023-06-23 15:34:59

by Kyle Tso

[permalink] [raw]
Subject: [PATCH v2 0/3] Some fixes for select_usb_power_delivery

Update v2

- Add "Cc: [email protected]" to each patch

== original cover letter ==

Hi, here are some fixes about the attribute "select_usb_power_delivery"
in typec/class.c

===

usb: typec: Set port->pd before adding device for typec_port

This one is about the visibility of the attribute. port->pd should be
set before device_add otherwise the visibility will be false because
port->pd is NULL.

===

usb: typec: Iterate pds array when showing the pd list

This patch fixes a problem about the incorrect fetching of the pointers
to each usb_power_delivery handle.

===

usb: typec: Use sysfs_emit_at when concatenating the string

This patch changes the use of the API from sysfs_emit to sysfs_emit_at
because the buffer address is not aligned to PAGE_SIZE.

===

Kyle Tso (3):
usb: typec: Set port->pd before adding device for typec_port
usb: typec: Iterate pds array when showing the pd list
usb: typec: Use sysfs_emit_at when concatenating the string

drivers/usb/typec/class.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

--
2.41.0.162.gfafddb0af9-goog



2023-06-23 15:53:35

by Kyle Tso

[permalink] [raw]
Subject: [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port

When calling device_add in the registration of typec_port, it will do
the NULL check on usb_power_delivery handle in typec_port for the
visibility of the device attributes. It is always NULL because port->pd
is set in typec_port_set_usb_power_delivery which is later than the
device_add call.

Set port->pd before device_add and only link the device after that.

Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
Cc: [email protected]
Signed-off-by: Kyle Tso <[email protected]>
---
update v2:
- Add "Cc: [email protected]"

drivers/usb/typec/class.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index faa184ae3dac..3b30948bf4b0 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -2288,6 +2288,8 @@ struct typec_port *typec_register_port(struct device *parent,
return ERR_PTR(ret);
}

+ port->pd = cap->pd;
+
ret = device_add(&port->dev);
if (ret) {
dev_err(parent, "failed to register port (%d)\n", ret);
@@ -2295,7 +2297,7 @@ struct typec_port *typec_register_port(struct device *parent,
return ERR_PTR(ret);
}

- ret = typec_port_set_usb_power_delivery(port, cap->pd);
+ ret = usb_power_delivery_link_device(port->pd, &port->dev);
if (ret) {
dev_err(&port->dev, "failed to link pd\n");
device_unregister(&port->dev);
--
2.41.0.162.gfafddb0af9-goog


2023-06-23 16:33:13

by Kyle Tso

[permalink] [raw]
Subject: [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string

The buffer address used in sysfs_emit should be aligned to PAGE_SIZE.
Use sysfs_emit_at instead to offset the buffer.

Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
Cc: [email protected]
Signed-off-by: Kyle Tso <[email protected]>
---
Update v2:
- Add "Cc: [email protected]"

drivers/usb/typec/class.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index e7312295f8c9..9c1dbf3c00e0 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1288,9 +1288,9 @@ static ssize_t select_usb_power_delivery_show(struct device *dev,

for (i = 0; pds[i]; i++) {
if (pds[i] == port->pd)
- ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pds[i]->dev));
+ ret += sysfs_emit_at(buf, ret, "[%s] ", dev_name(&pds[i]->dev));
else
- ret += sysfs_emit(buf + ret, "%s ", dev_name(&pds[i]->dev));
+ ret += sysfs_emit_at(buf, ret, "%s ", dev_name(&pds[i]->dev));
}

buf[ret - 1] = '\n';
--
2.41.0.162.gfafddb0af9-goog


2023-06-30 13:11:52

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port

On Fri, Jun 23, 2023 at 11:10:34PM +0800, Kyle Tso wrote:
> When calling device_add in the registration of typec_port, it will do
> the NULL check on usb_power_delivery handle in typec_port for the
> visibility of the device attributes. It is always NULL because port->pd
> is set in typec_port_set_usb_power_delivery which is later than the
> device_add call.
>
> Set port->pd before device_add and only link the device after that.
>
> Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
> Cc: [email protected]
> Signed-off-by: Kyle Tso <[email protected]>

Acked-by: Heikki Krogerus <[email protected]>

thanks,

--
heikki

2023-06-30 13:12:03

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string

On Fri, Jun 23, 2023 at 11:10:36PM +0800, Kyle Tso wrote:
> The buffer address used in sysfs_emit should be aligned to PAGE_SIZE.
> Use sysfs_emit_at instead to offset the buffer.
>
> Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
> Cc: [email protected]
> Signed-off-by: Kyle Tso <[email protected]>

Acked-by: Heikki Krogerus <[email protected]>

--
heikki