Skip to content

Commit

Permalink
usb: typec: thunderbolt: Fix loops that iterate TYPEC_PLUG_SOP_P and …
Browse files Browse the repository at this point in the history
…TYPEC_PLUG_SOP_PP

Fixes these Smatch static checker warnings:
drivers/usb/typec/altmodes/thunderbolt.c:116 tbt_altmode_work() warn: why is zero skipped 'i'
drivers/usb/typec/altmodes/thunderbolt.c:147 tbt_enter_modes_ordered() warn: why is zero skipped 'i'
drivers/usb/typec/altmodes/thunderbolt.c:328 tbt_altmode_remove() warn: why is zero skipped 'i'

Fixes: 100e257 ("usb: typec: Add driver for Thunderbolt 3 Alternate Mode")
Signed-off-by: Benson Leung <bleung@chromium.org>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/Z5Psp615abaaId6J@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Benson Leung authored and Greg Kroah-Hartman committed Feb 3, 2025
1 parent 51333bf commit b51c1e8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/usb/typec/altmodes/thunderbolt.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void tbt_altmode_work(struct work_struct *work)
return;

disable_plugs:
for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) {
for (int i = TYPEC_PLUG_SOP_PP; i >= 0; --i) {
if (tbt->plug[i])
typec_altmode_put_plug(tbt->plug[i]);

Expand Down Expand Up @@ -143,7 +143,7 @@ static int tbt_enter_modes_ordered(struct typec_altmode *alt)
if (tbt->plug[TYPEC_PLUG_SOP_P]) {
ret = typec_cable_altmode_enter(alt, TYPEC_PLUG_SOP_P, NULL);
if (ret < 0) {
for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) {
for (int i = TYPEC_PLUG_SOP_PP; i >= 0; --i) {
if (tbt->plug[i])
typec_altmode_put_plug(tbt->plug[i]);

Expand Down Expand Up @@ -324,7 +324,7 @@ static void tbt_altmode_remove(struct typec_altmode *alt)
{
struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt);

for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) {
for (int i = TYPEC_PLUG_SOP_PP; i >= 0; --i) {
if (tbt->plug[i])
typec_altmode_put_plug(tbt->plug[i]);
}
Expand Down

0 comments on commit b51c1e8

Please sign in to comment.