Skip to content

Commit

Permalink
usb: typec: Iterate pds array when showing the pd list
Browse files Browse the repository at this point in the history
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: a7cff92 ("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>
Link: https://lore.kernel.org/r/20230623151036.3955013-3-kyletso@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
kyletsoadl authored and gregkh committed Jul 25, 2023
1 parent b33ebb2 commit 4b642dc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drivers/usb/typec/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down

0 comments on commit 4b642dc

Please sign in to comment.