From: Kyle Tso <kyletso@google.com>
To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org
Cc: badhri@google.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, Kyle Tso <kyletso@google.com>
Subject: [PATCH 2/3] usb: typec: Iterate pds array when showing the pd list
Date: Thu, 22 Jun 2023 23:04:22 +0800 [thread overview]
Message-ID: <20230622150423.3726894-3-kyletso@google.com> (raw)
In-Reply-To: <20230622150423.3726894-1-kyletso@google.com>
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")
Signed-off-by: Kyle Tso <kyletso@google.com>
---
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
next prev parent reply other threads:[~2023-06-22 15:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 15:04 [PATCH 0/3] Some fixes for select_usb_power_delivery Kyle Tso
2023-06-22 15:04 ` [PATCH 1/3] usb: typec: Set port->pd before adding device for typec_port Kyle Tso
2023-06-23 7:50 ` Greg KH
2023-06-23 10:08 ` Kyle Tso
2023-06-22 15:04 ` Kyle Tso [this message]
2023-06-22 15:04 ` [PATCH 3/3] usb: typec: Use sysfs_emit_at when concatenating the string Kyle Tso
2023-06-23 7:51 ` Greg KH
2023-06-23 10:06 ` Kyle Tso
2023-06-23 10:11 ` Kyle Tso
2023-06-23 11:14 ` Greg KH
2023-06-23 14:23 ` Kyle Tso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230622150423.3726894-3-kyletso@google.com \
--to=kyletso@google.com \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox