From: Andrew Goodbody Date: Tue, 30 Sep 2025 15:52:24 +0000 (+0100) Subject: usb: musb-new: Cannot test unsigned member to be negative X-Git-Tag: v2026.01-rc2~58^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41fd18219fb6625171180a21d0e4f17e9b7b5aa2;p=thirdparty%2Fu-boot.git usb: musb-new: Cannot test unsigned member to be negative You cannot test an unsigned member of a struct for being negative, the test will always fail. Instead assign the return value of fdtdec_get_int, which returns an int, to a temporary variable declared as an int, so that it can be tested for being negative before being assigned to the unsigned struct member. This issue was found by Smatch. Signed-off-by: Andrew Goodbody --- diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c index ba600d01102..7fd6639013a 100644 --- a/drivers/usb/musb-new/omap2430.c +++ b/drivers/usb/musb-new/omap2430.c @@ -142,41 +142,49 @@ static int omap2430_musb_of_to_plat(struct udevice *dev) struct omap2430_musb_plat *plat = dev_get_plat(dev); const void *fdt = gd->fdt_blob; int node = dev_of_offset(dev); + int ret; plat->base = (void *)dev_read_addr_ptr(dev); - plat->musb_config.multipoint = fdtdec_get_int(fdt, node, "multipoint", - -1); - if (plat->musb_config.multipoint < 0) { + ret = fdtdec_get_int(fdt, node, "multipoint", -1); + if (ret < 0) { pr_err("MUSB multipoint DT entry missing\n"); return -ENOENT; + } else { + plat->musb_config.multipoint = ret; } plat->musb_config.dyn_fifo = 1; - plat->musb_config.num_eps = fdtdec_get_int(fdt, node, "num-eps", -1); - if (plat->musb_config.num_eps < 0) { + ret = fdtdec_get_int(fdt, node, "num-eps", -1); + if (ret < 0) { pr_err("MUSB num-eps DT entry missing\n"); return -ENOENT; + } else { + plat->musb_config.num_eps = ret; } - plat->musb_config.ram_bits = fdtdec_get_int(fdt, node, "ram-bits", -1); - if (plat->musb_config.ram_bits < 0) { + ret = fdtdec_get_int(fdt, node, "ram-bits", -1); + if (ret < 0) { pr_err("MUSB ram-bits DT entry missing\n"); return -ENOENT; + } else { + plat->musb_config.ram_bits = ret; } - plat->plat.power = fdtdec_get_int(fdt, node, "power", -1); - if (plat->plat.power < 0) { + ret = fdtdec_get_int(fdt, node, "power", -1); + if (ret < 0) { pr_err("MUSB power DT entry missing\n"); return -ENOENT; + } else { + plat->plat.power = ret; } - plat->otg_board_data.interface_type = fdtdec_get_int(fdt, node, - "interface-type", - -1); - if (plat->otg_board_data.interface_type < 0) { + ret = fdtdec_get_int(fdt, node, "interface-type", -1); + if (ret < 0) { pr_err("MUSB interface-type DT entry missing\n"); return -ENOENT; + } else { + plat->otg_board_data.interface_type = ret; } #if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index 967d0953875..bcd31adba52 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -86,6 +86,7 @@ static int ti_musb_of_to_plat(struct udevice *dev) int phys; int ctrl_mod; int usb_index; + int ret; struct musb_hdrc_config *musb_config; plat->base = devfdt_get_addr_index_ptr(dev, 1); @@ -108,35 +109,40 @@ static int ti_musb_of_to_plat(struct udevice *dev) musb_config = malloc(sizeof(struct musb_hdrc_config)); memset(musb_config, 0, sizeof(struct musb_hdrc_config)); - musb_config->multipoint = fdtdec_get_int(fdt, node, - "mentor,multipoint", -1); - if (musb_config->multipoint < 0) { + ret = fdtdec_get_int(fdt, node, "mentor,multipoint", -1); + if (ret < 0) { pr_err("MUSB multipoint DT entry missing\n"); return -ENOENT; + } else { + musb_config->multipoint = ret; } musb_config->dyn_fifo = 1; - musb_config->num_eps = fdtdec_get_int(fdt, node, "mentor,num-eps", - -1); - if (musb_config->num_eps < 0) { + ret = fdtdec_get_int(fdt, node, "mentor,num-eps", -1); + if (ret < 0) { pr_err("MUSB num-eps DT entry missing\n"); return -ENOENT; + } else { + musb_config->num_eps = ret; } - musb_config->ram_bits = fdtdec_get_int(fdt, node, "mentor,ram-bits", - -1); - if (musb_config->ram_bits < 0) { + ret = fdtdec_get_int(fdt, node, "mentor,ram-bits", -1); + if (ret < 0) { pr_err("MUSB ram-bits DT entry missing\n"); return -ENOENT; + } else { + musb_config->ram_bits = ret; } plat->plat.config = musb_config; - plat->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1); - if (plat->plat.power < 0) { + ret = fdtdec_get_int(fdt, node, "mentor,power", -1); + if (ret < 0) { pr_err("MUSB mentor,power DT entry missing\n"); return -ENOENT; + } else { + plat->plat.power = ret; } plat->plat.platform_ops = &musb_dsps_ops;