Skip to content

Commit 8d1b02e

Browse files
nathanchancegregkh
authored andcommitted
usb: atm: cxacru: Merge cxacru_upload_firmware() into cxacru_heavy_init()
After a recent change in clang to expose uninitialized warnings from const variables [1], there is a warning in cxacru_heavy_init(): drivers/usb/atm/cxacru.c:1104:6: error: variable 'bp' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] 1104 | if (instance->modem_type->boot_rom_patch) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/usb/atm/cxacru.c:1113:39: note: uninitialized use occurs here 1113 | cxacru_upload_firmware(instance, fw, bp); | ^~ drivers/usb/atm/cxacru.c:1104:2: note: remove the 'if' if its condition is always true 1104 | if (instance->modem_type->boot_rom_patch) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/usb/atm/cxacru.c:1095:32: note: initialize the variable 'bp' to silence this warning 1095 | const struct firmware *fw, *bp; | ^ | = NULL While the warning is technically correct that bp is conditionally passed uninitialized to cxacru_upload_firmware(), it is ultimately a false positive warning on the uninitialized use of bp because the same condition that initializes bp, instance->modem_type->boot_rom_patch, is the same one that gates the use of bp within cxacru_upload_firmware(). As this warning occurs in clang's frontend before inlining occurs, it cannot know that these conditions are indentical to avoid the warning. Manually inline cxacru_upload_firmware() into cxacru_heavy_init(), as that is its only callsite, so that clang can see that bp is initialized and used under the same condition, clearing up the warning without any functional changes to the code (LLVM was already doing this inlining later). Cc: [email protected] Fixes: 1b0e614 ("[PATCH] USB ATM: driver for the Conexant AccessRunner chipset cxacru") Closes: ClangBuiltLinux/linux#2102 Link: llvm/llvm-project@2464313 [1] Signed-off-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/20250722-usb-cxacru-fix-clang-21-uninit-warning-v2-1-6708a18decd2@kernel.org Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fcb4769 commit 8d1b02e

File tree

1 file changed

+49
-57
lines changed

1 file changed

+49
-57
lines changed

drivers/usb/atm/cxacru.c

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -980,49 +980,84 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
980980
return ret;
981981
}
982982

983-
static void cxacru_upload_firmware(struct cxacru_data *instance,
984-
const struct firmware *fw,
985-
const struct firmware *bp)
983+
984+
static int cxacru_find_firmware(struct cxacru_data *instance,
985+
char *phase, const struct firmware **fw_p)
986986
{
987-
int ret;
987+
struct usbatm_data *usbatm = instance->usbatm;
988+
struct device *dev = &usbatm->usb_intf->dev;
989+
char buf[16];
990+
991+
sprintf(buf, "cxacru-%s.bin", phase);
992+
usb_dbg(usbatm, "cxacru_find_firmware: looking for %s\n", buf);
993+
994+
if (request_firmware(fw_p, buf, dev)) {
995+
usb_dbg(usbatm, "no stage %s firmware found\n", phase);
996+
return -ENOENT;
997+
}
998+
999+
usb_info(usbatm, "found firmware %s\n", buf);
1000+
1001+
return 0;
1002+
}
1003+
1004+
static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
1005+
struct usb_interface *usb_intf)
1006+
{
1007+
const struct firmware *fw, *bp;
1008+
struct cxacru_data *instance = usbatm_instance->driver_data;
9881009
struct usbatm_data *usbatm = instance->usbatm;
9891010
struct usb_device *usb_dev = usbatm->usb_dev;
9901011
__le16 signature[] = { usb_dev->descriptor.idVendor,
9911012
usb_dev->descriptor.idProduct };
9921013
__le32 val;
1014+
int ret;
9931015

994-
usb_dbg(usbatm, "%s\n", __func__);
1016+
ret = cxacru_find_firmware(instance, "fw", &fw);
1017+
if (ret) {
1018+
usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
1019+
return ret;
1020+
}
1021+
1022+
if (instance->modem_type->boot_rom_patch) {
1023+
ret = cxacru_find_firmware(instance, "bp", &bp);
1024+
if (ret) {
1025+
usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
1026+
release_firmware(fw);
1027+
return ret;
1028+
}
1029+
}
9951030

9961031
/* FirmwarePllFClkValue */
9971032
val = cpu_to_le32(instance->modem_type->pll_f_clk);
9981033
ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
9991034
if (ret) {
10001035
usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret);
1001-
return;
1036+
goto done;
10021037
}
10031038

10041039
/* FirmwarePllBClkValue */
10051040
val = cpu_to_le32(instance->modem_type->pll_b_clk);
10061041
ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
10071042
if (ret) {
10081043
usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret);
1009-
return;
1044+
goto done;
10101045
}
10111046

10121047
/* Enable SDRAM */
10131048
val = cpu_to_le32(SDRAM_ENA);
10141049
ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
10151050
if (ret) {
10161051
usb_err(usbatm, "Enable SDRAM failed: %d\n", ret);
1017-
return;
1052+
goto done;
10181053
}
10191054

10201055
/* Firmware */
10211056
usb_info(usbatm, "loading firmware\n");
10221057
ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
10231058
if (ret) {
10241059
usb_err(usbatm, "Firmware upload failed: %d\n", ret);
1025-
return;
1060+
goto done;
10261061
}
10271062

10281063
/* Boot ROM patch */
@@ -1031,15 +1066,15 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
10311066
ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
10321067
if (ret) {
10331068
usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
1034-
return;
1069+
goto done;
10351070
}
10361071
}
10371072

10381073
/* Signature */
10391074
ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
10401075
if (ret) {
10411076
usb_err(usbatm, "Signature storing failed: %d\n", ret);
1042-
return;
1077+
goto done;
10431078
}
10441079

10451080
usb_info(usbatm, "starting device\n");
@@ -1051,7 +1086,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
10511086
}
10521087
if (ret) {
10531088
usb_err(usbatm, "Passing control to firmware failed: %d\n", ret);
1054-
return;
1089+
goto done;
10551090
}
10561091

10571092
/* Delay to allow firmware to start up. */
@@ -1065,53 +1100,10 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
10651100
ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
10661101
if (ret < 0) {
10671102
usb_err(usbatm, "modem failed to initialize: %d\n", ret);
1068-
return;
1069-
}
1070-
}
1071-
1072-
static int cxacru_find_firmware(struct cxacru_data *instance,
1073-
char *phase, const struct firmware **fw_p)
1074-
{
1075-
struct usbatm_data *usbatm = instance->usbatm;
1076-
struct device *dev = &usbatm->usb_intf->dev;
1077-
char buf[16];
1078-
1079-
sprintf(buf, "cxacru-%s.bin", phase);
1080-
usb_dbg(usbatm, "cxacru_find_firmware: looking for %s\n", buf);
1081-
1082-
if (request_firmware(fw_p, buf, dev)) {
1083-
usb_dbg(usbatm, "no stage %s firmware found\n", phase);
1084-
return -ENOENT;
1085-
}
1086-
1087-
usb_info(usbatm, "found firmware %s\n", buf);
1088-
1089-
return 0;
1090-
}
1091-
1092-
static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
1093-
struct usb_interface *usb_intf)
1094-
{
1095-
const struct firmware *fw, *bp;
1096-
struct cxacru_data *instance = usbatm_instance->driver_data;
1097-
int ret = cxacru_find_firmware(instance, "fw", &fw);
1098-
1099-
if (ret) {
1100-
usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
1101-
return ret;
1103+
goto done;
11021104
}
11031105

1104-
if (instance->modem_type->boot_rom_patch) {
1105-
ret = cxacru_find_firmware(instance, "bp", &bp);
1106-
if (ret) {
1107-
usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
1108-
release_firmware(fw);
1109-
return ret;
1110-
}
1111-
}
1112-
1113-
cxacru_upload_firmware(instance, fw, bp);
1114-
1106+
done:
11151107
if (instance->modem_type->boot_rom_patch)
11161108
release_firmware(bp);
11171109
release_firmware(fw);

0 commit comments

Comments
 (0)