]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
usb: musb-new: Cannot test unsigned member to be negative
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Tue, 30 Sep 2025 15:52:24 +0000 (16:52 +0100)
committerMarek Vasut <marek.vasut+usb@mailbox.org>
Tue, 28 Oct 2025 15:35:05 +0000 (16:35 +0100)
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 <andrew.goodbody@linaro.org>
drivers/usb/musb-new/omap2430.c
drivers/usb/musb-new/ti-musb.c

index ba600d0110239164ca7c287ba6347e20d9ae2931..7fd6639013a7fcdaaf9aee38bdaddaa82a66f3a5 100644 (file)
@@ -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 */
index 967d0953875f734ceeb4bd4be610f9cc562ce430..bcd31adba522fc55190fc43fd2dbd2dec93a2731 100644 (file)
@@ -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;