linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Some fixes for select_usb_power_delivery
@ 2023-06-23 15:10 Kyle Tso
  2023-06-23 15:10 ` [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port Kyle Tso
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Kyle Tso @ 2023-06-23 15:10 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: badhri, linux-usb, linux-kernel, Kyle Tso

Update v2

- Add "Cc: stable@vger.kernel.org" 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port
  2023-06-23 15:10 [PATCH v2 0/3] Some fixes for select_usb_power_delivery Kyle Tso
@ 2023-06-23 15:10 ` Kyle Tso
  2023-06-30 12:39   ` Heikki Krogerus
  2023-06-23 15:10 ` [PATCH v2 2/3] usb: typec: Iterate pds array when showing the pd list Kyle Tso
  2023-06-23 15:10 ` [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string Kyle Tso
  2 siblings, 1 reply; 7+ messages in thread
From: Kyle Tso @ 2023-06-23 15:10 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: badhri, linux-usb, linux-kernel, Kyle Tso, stable

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: stable@vger.kernel.org
Signed-off-by: Kyle Tso <kyletso@google.com>
---
update v2:
- Add "Cc: stable@vger.kernel.org"

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] usb: typec: Iterate pds array when showing the pd list
  2023-06-23 15:10 [PATCH v2 0/3] Some fixes for select_usb_power_delivery Kyle Tso
  2023-06-23 15:10 ` [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port Kyle Tso
@ 2023-06-23 15:10 ` Kyle Tso
  2023-06-30 12:41   ` Heikki Krogerus
  2023-06-23 15:10 ` [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string Kyle Tso
  2 siblings, 1 reply; 7+ messages in thread
From: Kyle Tso @ 2023-06-23 15:10 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: badhri, linux-usb, linux-kernel, Kyle Tso, stable

The pointers of each usb_power_delivery handles are stored in "pds"
array returned from the pd_get ops but not in the adjacent memory
calculated from "pd". Get the handles from "pds" array directly instead
of deriving them from "pd".

Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
Cc: stable@vger.kernel.org
Signed-off-by: Kyle Tso <kyletso@google.com>
---
Update v2:
- Add "Cc: stable@vger.kernel.org"

drivers/usb/typec/class.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 3b30948bf4b0..e7312295f8c9 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1277,8 +1277,7 @@ static ssize_t select_usb_power_delivery_show(struct device *dev,
 {
 	struct typec_port *port = to_typec_port(dev);
 	struct usb_power_delivery **pds;
-	struct usb_power_delivery *pd;
-	int ret = 0;
+	int i, ret = 0;
 
 	if (!port->ops || !port->ops->pd_get)
 		return -EOPNOTSUPP;
@@ -1287,11 +1286,11 @@ static ssize_t select_usb_power_delivery_show(struct device *dev,
 	if (!pds)
 		return 0;
 
-	for (pd = pds[0]; pd; pd++) {
-		if (pd == port->pd)
-			ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pd->dev));
+	for (i = 0; pds[i]; i++) {
+		if (pds[i] == port->pd)
+			ret += sysfs_emit(buf + ret, "[%s] ", dev_name(&pds[i]->dev));
 		else
-			ret += sysfs_emit(buf + ret, "%s ", dev_name(&pd->dev));
+			ret += sysfs_emit(buf + ret, "%s ", dev_name(&pds[i]->dev));
 	}
 
 	buf[ret - 1] = '\n';
-- 
2.41.0.162.gfafddb0af9-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string
  2023-06-23 15:10 [PATCH v2 0/3] Some fixes for select_usb_power_delivery Kyle Tso
  2023-06-23 15:10 ` [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port Kyle Tso
  2023-06-23 15:10 ` [PATCH v2 2/3] usb: typec: Iterate pds array when showing the pd list Kyle Tso
@ 2023-06-23 15:10 ` Kyle Tso
  2023-06-30 12:42   ` Heikki Krogerus
  2 siblings, 1 reply; 7+ messages in thread
From: Kyle Tso @ 2023-06-23 15:10 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: badhri, linux-usb, linux-kernel, Kyle Tso, stable

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: stable@vger.kernel.org
Signed-off-by: Kyle Tso <kyletso@google.com>
---
Update v2:
- Add "Cc: stable@vger.kernel.org"

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port
  2023-06-23 15:10 ` [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port Kyle Tso
@ 2023-06-30 12:39   ` Heikki Krogerus
  0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2023-06-30 12:39 UTC (permalink / raw)
  To: Kyle Tso; +Cc: gregkh, badhri, linux-usb, linux-kernel, stable

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: stable@vger.kernel.org
> Signed-off-by: Kyle Tso <kyletso@google.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/3] usb: typec: Iterate pds array when showing the pd list
  2023-06-23 15:10 ` [PATCH v2 2/3] usb: typec: Iterate pds array when showing the pd list Kyle Tso
@ 2023-06-30 12:41   ` Heikki Krogerus
  0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2023-06-30 12:41 UTC (permalink / raw)
  To: Kyle Tso; +Cc: gregkh, badhri, linux-usb, linux-kernel, stable

On Fri, Jun 23, 2023 at 11:10:35PM +0800, Kyle Tso wrote:
> The pointers of each usb_power_delivery handles are stored in "pds"
> array returned from the pd_get ops but not in the adjacent memory
> calculated from "pd". Get the handles from "pds" array directly instead
> of deriving them from "pd".
> 
> Fixes: a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Tso <kyletso@google.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string
  2023-06-23 15:10 ` [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string Kyle Tso
@ 2023-06-30 12:42   ` Heikki Krogerus
  0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2023-06-30 12:42 UTC (permalink / raw)
  To: Kyle Tso; +Cc: gregkh, badhri, linux-usb, linux-kernel, stable

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: stable@vger.kernel.org
> Signed-off-by: Kyle Tso <kyletso@google.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-30 12:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-23 15:10 [PATCH v2 0/3] Some fixes for select_usb_power_delivery Kyle Tso
2023-06-23 15:10 ` [PATCH v2 1/3] usb: typec: Set port->pd before adding device for typec_port Kyle Tso
2023-06-30 12:39   ` Heikki Krogerus
2023-06-23 15:10 ` [PATCH v2 2/3] usb: typec: Iterate pds array when showing the pd list Kyle Tso
2023-06-30 12:41   ` Heikki Krogerus
2023-06-23 15:10 ` [PATCH v2 3/3] usb: typec: Use sysfs_emit_at when concatenating the string Kyle Tso
2023-06-30 12:42   ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).