Skip to content

Commit befa1c2

Browse files
ADESTMgregkh
authored andcommitted
usb: typec: stusb160x: fix signedness comparison issue with enum variables
chip->port_type and chip->pwr_opmode are enums and when GCC considers them as unsigned, the conditions are never met. This patch takes advantage of the ret variable and fixes the following warnings: drivers/usb/typec/stusb160x.c:548 stusb160x_get_fw_caps() warn: unsigned 'chip->port_type' is never less than zero. drivers/usb/typec/stusb160x.c:570 stusb160x_get_fw_caps() warn: unsigned 'chip->pwr_opmode' is never less than zero. Fixes: da0cb63 ("usb: typec: add support for STUSB160x Type-C controller family") Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com> Link: https://lore.kernel.org/r/20201028163309.12878-1-amelie.delaunay@st.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f27891a commit befa1c2

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

drivers/usb/typec/stusb160x.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,10 @@ static int stusb160x_get_fw_caps(struct stusb160x *chip,
544544
*/
545545
ret = fwnode_property_read_string(fwnode, "power-role", &cap_str);
546546
if (!ret) {
547-
chip->port_type = typec_find_port_power_role(cap_str);
548-
if ((int)chip->port_type < 0) {
549-
ret = chip->port_type;
547+
ret = typec_find_port_power_role(cap_str);
548+
if (ret < 0)
550549
return ret;
551-
}
550+
chip->port_type = ret;
552551
}
553552
chip->capability.type = chip->port_type;
554553

@@ -565,16 +564,13 @@ static int stusb160x_get_fw_caps(struct stusb160x *chip,
565564
*/
566565
ret = fwnode_property_read_string(fwnode, "power-opmode", &cap_str);
567566
if (!ret) {
568-
chip->pwr_opmode = typec_find_pwr_opmode(cap_str);
567+
ret = typec_find_pwr_opmode(cap_str);
569568
/* Power delivery not yet supported */
570-
if ((int)chip->pwr_opmode < 0 ||
571-
chip->pwr_opmode == TYPEC_PWR_MODE_PD) {
572-
ret = (int)chip->pwr_opmode < 0 ? chip->pwr_opmode :
573-
-EINVAL;
574-
dev_err(chip->dev, "bad power operation mode: %d\n",
575-
chip->pwr_opmode);
576-
return ret;
569+
if (ret < 0 || ret == TYPEC_PWR_MODE_PD) {
570+
dev_err(chip->dev, "bad power operation mode: %d\n", ret);
571+
return -EINVAL;
577572
}
573+
chip->pwr_opmode = ret;
578574
}
579575

580576
return 0;

0 commit comments

Comments
 (0)